From b8030f1de474bd3f80edb0c4733564874baacf1e Mon Sep 17 00:00:00 2001 From: Allan Eagle Date: Mon, 22 Apr 2024 00:26:01 +0100 Subject: [PATCH 1/4] Split sb npm package build --- azure-pipelines-sb.yml | 88 ++++++++++++++++++++++++++++++++++++++++++ azure-pipelines.yml | 16 -------- 2 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 azure-pipelines-sb.yml diff --git a/azure-pipelines-sb.yml b/azure-pipelines-sb.yml new file mode 100644 index 0000000..9784459 --- /dev/null +++ b/azure-pipelines-sb.yml @@ -0,0 +1,88 @@ +# Node.js with React +# Build a Node.js project that uses React. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript + +pool: + vmImage: "ubuntu-latest" + +steps: + - task: Bash@3 + displayName: Generate build number tag if required + condition: eq(variables.IsPullRequestTrigger, false) + inputs: + targetType: "inline" + script: | + if [ $(Build.SourceBranch) != "refs/heads/main" ] + then + # Lowercase + tag=$(sed 's/.*/\L&/' <<< $(Build.SourceBranchName)) + # Replace non alpha-numeric to - + tag=$(sed 's/[^0-9a-z\-]/-/g' <<< $tag) + # Set the build number in DevOps + echo "##vso[build.updatebuildnumber]v-sb-$(Build.BuildNumber).0-$tag" + else + echo "##vso[build.updatebuildnumber]v-sb-$(Build.BuildNumber).0" + fi + failOnStderr: true + - task: Bash@3 + displayName: Update version number in package.json + inputs: + targetType: "inline" + script: 'sed -i $"s/\"version\": \"[^\"]*\"/\"version\": \"$(Build.BuildNumber)\"/g" .storybook/package.json' + env: + GITVERSIONNUMBER: $(Build.BuildNumber) + + - task: Bash@3 + displayName: Update version number in react-spaces-storybook package.json + inputs: + targetType: "inline" + script: sed -i "s/0.2.2/$GITVERSIONNUMBER/g" .storybook/package.json + env: + GITVERSIONNUMBER: $(GitVersion.SemVer) + + - task: NodeTool@0 + inputs: + versionSpec: "20.x" + checkLatest: true + displayName: "Install Node.js" + + - task: Cache@2 + displayName: Cache node_modules + inputs: + key: 'npm | "$(Agent.OS)" | $(Build.SourcesDirectory)/package-lock.json' + path: $(Build.SourcesDirectory)/node_modules + cacheHitVar: CACHE_RESTORED + + - task: Npm@1 + displayName: "Install the dependencies" + inputs: + command: custom + verbose: false + customCommand: "ci" + condition: ne(variables.CACHE_RESTORED, 'true') + + - script: | + npm test + displayName: "Run tests" + + - script: | + npm run build-storybook + displayName: "Build storybook" + + - task: CopyFiles@2 + condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') + displayName: Move storybook package json + inputs: + SourceFolder: ".storybook" + Contents: "package.json" + TargetFolder: "./storybook-static" + OverWrite: true + + - task: Npm@1 + condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') + displayName: Publish react-spaces-storybook + inputs: + command: "publish" + workingDir: "storybook-static" + publishEndpoint: "NPM" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4d63930..43d71c3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,14 +23,6 @@ steps: env: GITVERSIONNUMBER: $(GitVersion.SemVer) - - task: Bash@3 - displayName: Update version number in react-spaces-storybook package.json - inputs: - targetType: "inline" - script: sed -i "s/0.2.2/$GITVERSIONNUMBER/g" .storybook/package.json - env: - GITVERSIONNUMBER: $(GitVersion.SemVer) - - task: NodeTool@0 inputs: versionSpec: "20.x" @@ -73,14 +65,6 @@ steps: TargetFolder: "./storybook-static" OverWrite: true - - task: Npm@1 - condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') - displayName: Publish react-spaces-storybook - inputs: - command: "publish" - workingDir: "storybook-static" - publishEndpoint: "NPM" - - task: Npm@1 condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') displayName: Publish react-spaces From 8f59a9c94604c0661ea87e1e00d29b59208eb211 Mon Sep 17 00:00:00 2001 From: Allan Eagle Date: Mon, 22 Apr 2024 00:27:09 +0100 Subject: [PATCH 2/4] Fix branch --- azure-pipelines-sb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines-sb.yml b/azure-pipelines-sb.yml index 9784459..f8e24c5 100644 --- a/azure-pipelines-sb.yml +++ b/azure-pipelines-sb.yml @@ -13,7 +13,7 @@ steps: inputs: targetType: "inline" script: | - if [ $(Build.SourceBranch) != "refs/heads/main" ] + if [ $(Build.SourceBranch) != "refs/heads/master" ] then # Lowercase tag=$(sed 's/.*/\L&/' <<< $(Build.SourceBranchName)) From b65f15be9361dae1379f9c4d9c115a69c68f4e5b Mon Sep 17 00:00:00 2001 From: Allan Eagle Date: Mon, 22 Apr 2024 00:29:20 +0100 Subject: [PATCH 3/4] Remove condition --- azure-pipelines-sb.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-pipelines-sb.yml b/azure-pipelines-sb.yml index f8e24c5..307840c 100644 --- a/azure-pipelines-sb.yml +++ b/azure-pipelines-sb.yml @@ -9,7 +9,6 @@ pool: steps: - task: Bash@3 displayName: Generate build number tag if required - condition: eq(variables.IsPullRequestTrigger, false) inputs: targetType: "inline" script: | From 0b8d1aef9b486ce9c4c3ce1d6c8cb0d56afec068 Mon Sep 17 00:00:00 2001 From: Allan Eagle Date: Mon, 22 Apr 2024 00:32:59 +0100 Subject: [PATCH 4/4] Revise version generation --- azure-pipelines-sb.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines-sb.yml b/azure-pipelines-sb.yml index 307840c..90fbc0f 100644 --- a/azure-pipelines-sb.yml +++ b/azure-pipelines-sb.yml @@ -19,9 +19,9 @@ steps: # Replace non alpha-numeric to - tag=$(sed 's/[^0-9a-z\-]/-/g' <<< $tag) # Set the build number in DevOps - echo "##vso[build.updatebuildnumber]v-sb-$(Build.BuildNumber).0-$tag" + echo "##vso[build.updatebuildnumber]$(Build.BuildNumber).0-$tag" else - echo "##vso[build.updatebuildnumber]v-sb-$(Build.BuildNumber).0" + echo "##vso[build.updatebuildnumber]$(Build.BuildNumber).0" fi failOnStderr: true - task: Bash@3