|
| 1 | +# Node.js with React |
| 2 | +# Build a Node.js project that uses React. |
| 3 | +# Add steps that analyze code, save build artifacts, deploy, and more: |
| 4 | +# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript |
| 5 | + |
| 6 | +pool: |
| 7 | + vmImage: "ubuntu-latest" |
| 8 | + |
| 9 | +steps: |
| 10 | + - task: Bash@3 |
| 11 | + displayName: Generate build number tag if required |
| 12 | + inputs: |
| 13 | + targetType: "inline" |
| 14 | + script: | |
| 15 | + if [ $(Build.SourceBranch) != "refs/heads/master" ] |
| 16 | + then |
| 17 | + # Lowercase |
| 18 | + tag=$(sed 's/.*/\L&/' <<< $(Build.SourceBranchName)) |
| 19 | + # Replace non alpha-numeric to - |
| 20 | + tag=$(sed 's/[^0-9a-z\-]/-/g' <<< $tag) |
| 21 | + # Set the build number in DevOps |
| 22 | + echo "##vso[build.updatebuildnumber]$(Build.BuildNumber).0-$tag" |
| 23 | + else |
| 24 | + echo "##vso[build.updatebuildnumber]$(Build.BuildNumber).0" |
| 25 | + fi |
| 26 | + failOnStderr: true |
| 27 | + - task: Bash@3 |
| 28 | + displayName: Update version number in package.json |
| 29 | + inputs: |
| 30 | + targetType: "inline" |
| 31 | + script: 'sed -i $"s/\"version\": \"[^\"]*\"/\"version\": \"$(Build.BuildNumber)\"/g" .storybook/package.json' |
| 32 | + env: |
| 33 | + GITVERSIONNUMBER: $(Build.BuildNumber) |
| 34 | + |
| 35 | + - task: Bash@3 |
| 36 | + displayName: Update version number in react-spaces-storybook package.json |
| 37 | + inputs: |
| 38 | + targetType: "inline" |
| 39 | + script: sed -i "s/0.2.2/$GITVERSIONNUMBER/g" .storybook/package.json |
| 40 | + env: |
| 41 | + GITVERSIONNUMBER: $(GitVersion.SemVer) |
| 42 | + |
| 43 | + - task: NodeTool@0 |
| 44 | + inputs: |
| 45 | + versionSpec: "20.x" |
| 46 | + checkLatest: true |
| 47 | + displayName: "Install Node.js" |
| 48 | + |
| 49 | + - task: Cache@2 |
| 50 | + displayName: Cache node_modules |
| 51 | + inputs: |
| 52 | + key: 'npm | "$(Agent.OS)" | $(Build.SourcesDirectory)/package-lock.json' |
| 53 | + path: $(Build.SourcesDirectory)/node_modules |
| 54 | + cacheHitVar: CACHE_RESTORED |
| 55 | + |
| 56 | + - task: Npm@1 |
| 57 | + displayName: "Install the dependencies" |
| 58 | + inputs: |
| 59 | + command: custom |
| 60 | + verbose: false |
| 61 | + customCommand: "ci" |
| 62 | + condition: ne(variables.CACHE_RESTORED, 'true') |
| 63 | + |
| 64 | + - script: | |
| 65 | + npm test |
| 66 | + displayName: "Run tests" |
| 67 | +
|
| 68 | + - script: | |
| 69 | + npm run build-storybook |
| 70 | + displayName: "Build storybook" |
| 71 | +
|
| 72 | + - task: CopyFiles@2 |
| 73 | + condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') |
| 74 | + displayName: Move storybook package json |
| 75 | + inputs: |
| 76 | + SourceFolder: ".storybook" |
| 77 | + Contents: "package.json" |
| 78 | + TargetFolder: "./storybook-static" |
| 79 | + OverWrite: true |
| 80 | + |
| 81 | + - task: Npm@1 |
| 82 | + condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') |
| 83 | + displayName: Publish react-spaces-storybook |
| 84 | + inputs: |
| 85 | + command: "publish" |
| 86 | + workingDir: "storybook-static" |
| 87 | + publishEndpoint: "NPM" |
0 commit comments