diff --git a/build/yaml/templates/component-template.yml b/build/yaml/templates/component-template.yml index bd27ea611e..cce084d0c1 100644 --- a/build/yaml/templates/component-template.yml +++ b/build/yaml/templates/component-template.yml @@ -6,22 +6,24 @@ stages: condition: and(or(eq(variables.ComponentType, 'declarativeAsset'), eq(variables.ComponentType, 'generator'), and(eq(variables.ComponentType, 'codeExtension'), eq(variables.Language, 'js'))), not(eq(variables.PublishPackageArtifacts, true))) jobs: - job: job_build_npm - displayName: Build Node project + displayName: Build & Test Node project steps: - - template: npm-build-steps.yml - - template: npm-test-steps.yml + - template: yarn-build-steps.yml + - template: yarn-test-steps.yml + - template: debug-workspace-steps.yml - stage: stage_package_node - displayName: 'Node: Build, Version & Pack' + displayName: 'Node: Build, Test, Version & Pack' condition: and(or(eq(variables.ComponentType, 'declarativeAsset'), eq(variables.ComponentType, 'generator'), and(eq(variables.ComponentType, 'codeExtension'), eq(variables.Language, 'js'))), eq(variables.PublishPackageArtifacts, true)) jobs: - job: pack_npm displayName: 'Build & Pack Node project' steps: - - template: npm-build-steps.yml - - template: npm-test-steps.yml + - template: yarn-build-steps.yml + - template: yarn-test-steps.yml - template: npm-versioning-steps.yml - - template: npm-package-steps.yml + - template: yarn-package-steps.yml + - template: debug-workspace-steps.yml - stage: stage_build_nuget displayName: '.NET: Build & Test' diff --git a/build/yaml/templates/npm-versioning-steps.yml b/build/yaml/templates/npm-versioning-steps.yml index 9cb7e95fb1..a028d41658 100644 --- a/build/yaml/templates/npm-versioning-steps.yml +++ b/build/yaml/templates/npm-versioning-steps.yml @@ -61,5 +61,3 @@ steps: tags: | NpmPackageVersion: $(NpmPackageVersion) continueOnError: true - -- template: debug-workspace-steps.yml \ No newline at end of file diff --git a/build/yaml/templates/npm-build-steps.yml b/build/yaml/templates/yarn-build-steps.yml similarity index 79% rename from build/yaml/templates/npm-build-steps.yml rename to build/yaml/templates/yarn-build-steps.yml index b899f99240..6aa80571f1 100644 --- a/build/yaml/templates/npm-build-steps.yml +++ b/build/yaml/templates/yarn-build-steps.yml @@ -11,7 +11,5 @@ steps: - script: | yarn exec npm run --if-present build - displayName: 'Run build if it exists' + displayName: 'Run `yarn build` if it exists' workingDirectory: '$(WorkingDirectory)' - -- template: debug-workspace-steps.yml diff --git a/build/yaml/templates/npm-package-steps.yml b/build/yaml/templates/yarn-package-steps.yml similarity index 63% rename from build/yaml/templates/npm-package-steps.yml rename to build/yaml/templates/yarn-package-steps.yml index 4a0b9a71b8..4befed4fc2 100644 --- a/build/yaml/templates/npm-package-steps.yml +++ b/build/yaml/templates/yarn-package-steps.yml @@ -1,10 +1,19 @@ steps: - powershell: | if (Test-Path -Path package.json) { - # Get package.json ojbect + # Get package.json object $packageJson = Get-Content package.json; $packageJsonData = $packageJson | ConvertFrom-Json; + # Get name, strip invalid filename characters up to '/' and save as pipeline variable + $packageName = $packageJsonData.name + "Package name = $packageName"; + + $packageName = $packageName -replace ".*\/" + "Package file name = $packageName"; + + Write-Host "##vso[task.setvariable variable=NpmPackageFileName;]$packageName" + # Get variable passed from Setup stage $packageVersion = "$(NpmPackageVersion)"; @@ -21,22 +30,20 @@ steps: workingDirectory: '$(WorkingDirectory)' - script: | - yarn pack - displayName: 'Generate package' + yarn pack --filename $(NpmPackageFileName)-$(NpmPackageVersion).tgz + displayName: 'Run `yarn pack`' workingDirectory: '$(WorkingDirectory)' - task: CopyFiles@2 - displayName: 'Copy packages' + displayName: 'Copy packages to staging directory' inputs: SourceFolder: '$(WorkingDirectory)' Contents: '*.tgz' TargetFolder: '$(Build.ArtifactStagingDirectory)\npm' - task: PublishBuildArtifacts@1 - displayName: 'Publish the npm package' + displayName: 'Publish the npm package to artifacts' inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)\npm' ArtifactName: 'npm' publishLocation: 'Container' - -- template: debug-workspace-steps.yml diff --git a/build/yaml/templates/npm-test-steps.yml b/build/yaml/templates/yarn-test-steps.yml similarity index 84% rename from build/yaml/templates/npm-test-steps.yml rename to build/yaml/templates/yarn-test-steps.yml index 06c8a40a15..477fcbcca6 100644 --- a/build/yaml/templates/npm-test-steps.yml +++ b/build/yaml/templates/yarn-test-steps.yml @@ -9,18 +9,18 @@ steps: if (Test-Path -Path package.json) { $package = Get-Content package.json | ConvertFrom-Json $result = $package.scripts -and $package.scripts.test - Write-Host "##vso[task.setvariable variable=NpmRunTest;]$result" + Write-Host "##vso[task.setvariable variable=YarnRunTest;]$result" } else { Write-Host "Missing package.json" exit 1 } displayName: 'Determine if test script is present' - name: SetNpmRunTest + name: SetYarnRunTest workingDirectory: '$(WorkingDirectory)' - script: | yarn run test - condition: eq(variables.NpmRunTest, true) + condition: eq(variables.YarnRunTest, true) continueOnError: true - displayName: 'Run test if it exists' + displayName: 'Run `yarn test` if it exists' workingDirectory: '$(WorkingDirectory)'