From 17ade87ab94c59e6f69328949528c1642e66901b Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 20 May 2020 15:31:11 -0700 Subject: [PATCH 1/3] WIP: Verify node version --- .../templates/steps/use-node-version.yml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 eng/pipelines/templates/steps/use-node-version.yml diff --git a/eng/pipelines/templates/steps/use-node-version.yml b/eng/pipelines/templates/steps/use-node-version.yml new file mode 100644 index 000000000000..c8dcfd1e44ed --- /dev/null +++ b/eng/pipelines/templates/steps/use-node-version.yml @@ -0,0 +1,22 @@ +parameters: + - name: NodeVersion + type: string + default: $(NodeVersion) + values: + - 8.x + - 10.x + - 12.x + +steps: + - task: NodeTool@0 + inputs: + versionSpec: ${{ parameters.NodeVersion }} + displayName: "Use NodeJS ${{ parameters.NodeVersion }}" + + - script: | + node --version && npm --version + displayName: Node versions + + - pwsh: | + s + displayName: Verify Node Version From 7a1081c7ab30ebad57330fa0e84030bca735a9d7 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 11 Jun 2020 19:20:32 -0700 Subject: [PATCH 2/3] Use template to set and verify node version --- common/smoke-test/smoke-tests.yml | 5 +--- eng/pipelines/templates/steps/common.yml | 9 +----- .../templates/steps/use-node-test-version.yml | 14 ++++----- .../templates/steps/use-node-version.yml | 30 ++++++++++--------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/common/smoke-test/smoke-tests.yml b/common/smoke-test/smoke-tests.yml index 50e42e1de688..7fe63e08e038 100644 --- a/common/smoke-test/smoke-tests.yml +++ b/common/smoke-test/smoke-tests.yml @@ -46,10 +46,7 @@ jobs: value: "@{ storageEndpointSuffix = 'core.chinacloudapi.cn'; azureCloud = 'AzureChinaCloud'; }" steps: - - task: NodeTool@0 - displayName: Use Node $(NodeVersion) - inputs: - versionSpec: $(NodeVersion) + - template: ../../eng/pipelines/templates/steps/common.yml - task: Npm@1 inputs: diff --git a/eng/pipelines/templates/steps/common.yml b/eng/pipelines/templates/steps/common.yml index 585af6538e16..e2026fe3fccb 100644 --- a/eng/pipelines/templates/steps/common.yml +++ b/eng/pipelines/templates/steps/common.yml @@ -8,11 +8,4 @@ steps: - template: /eng/common/pipelines/templates/steps/verify-agent-os.yml - - task: NodeTool@0 - inputs: - versionSpec: "$(NodeVersion)" - displayName: "Use NodeJS $(NodeVersion)" - - - script: | - node --version && npm --version - displayName: Node versions + - template: use-node-version.yml diff --git a/eng/pipelines/templates/steps/use-node-test-version.yml b/eng/pipelines/templates/steps/use-node-test-version.yml index 9ac7d4d19cef..e22a2c92ee6d 100644 --- a/eng/pipelines/templates/steps/use-node-test-version.yml +++ b/eng/pipelines/templates/steps/use-node-test-version.yml @@ -1,12 +1,10 @@ -steps: - - task: NodeTool@0 - inputs: - versionSpec: $(NodeTestVersion) - displayName: "Use NodeJS $(NodeTestVersion)" +parameters: + NodeTestVersion: $(NodeTestVersion) - - script: | - node --version && npm --version - displayName: Node versions +steps: + - template: use-node-version + parameters: + NodeVersion: $(NodeTestVersion) # Packages with native dependencies must be reinstalled after changing Node versions - pwsh: | diff --git a/eng/pipelines/templates/steps/use-node-version.yml b/eng/pipelines/templates/steps/use-node-version.yml index c8dcfd1e44ed..e740b7a62b50 100644 --- a/eng/pipelines/templates/steps/use-node-version.yml +++ b/eng/pipelines/templates/steps/use-node-version.yml @@ -1,22 +1,24 @@ parameters: - - name: NodeVersion - type: string - default: $(NodeVersion) - values: - - 8.x - - 10.x - - 12.x + NodeVersion: $(NodeVersion) steps: - task: NodeTool@0 inputs: versionSpec: ${{ parameters.NodeVersion }} - displayName: "Use NodeJS ${{ parameters.NodeVersion }}" - - - script: | - node --version && npm --version - displayName: Node versions + displayName: "Use Node ${{ parameters.NodeVersion }}" - pwsh: | - s - displayName: Verify Node Version + $expectedVersion = "${{ parameters.NodeVersion }}" + Write-Host "Expected Node Version: $expectedVersion" + + $actualVersion = (node --version).Substring(1) + Write-Host "Actual Node Version: $actualVersion" + Write-Host "Actual NPM Version: $(npm --version)" + + $expectedMajorVersion = $expectedVersion.Split(".")[0] + $actualMajorVersion = $actualVersion.Split(".")[0] + if ($expectedMajorVersion -ne $actualMajorVersion) { + Write-Host "Error: Expected node version does not match actual node version" + exit 1 + } + displayName: "Verify Node Version" From 57a9c49f8c163b4b91847913b059f0aa6da1af02 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 11 Jun 2020 19:21:37 -0700 Subject: [PATCH 3/3] Fix template filename --- eng/pipelines/templates/steps/use-node-test-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/use-node-test-version.yml b/eng/pipelines/templates/steps/use-node-test-version.yml index e22a2c92ee6d..126fffef5f7e 100644 --- a/eng/pipelines/templates/steps/use-node-test-version.yml +++ b/eng/pipelines/templates/steps/use-node-test-version.yml @@ -2,7 +2,7 @@ parameters: NodeTestVersion: $(NodeTestVersion) steps: - - template: use-node-version + - template: use-node-version.yml parameters: NodeVersion: $(NodeTestVersion)