|
| 1 | +trigger: |
| 2 | + tags: |
| 3 | + include: |
| 4 | + - v.* |
| 5 | + branches: |
| 6 | + include: |
| 7 | + - develop |
| 8 | + - release* |
| 9 | + paths: |
| 10 | + exclude: |
| 11 | + - README.md |
| 12 | + |
| 13 | +pr: |
| 14 | + - master |
| 15 | + - develop |
| 16 | + |
| 17 | +variables: |
| 18 | + group: 'pipelines' |
| 19 | + repository: 'focal-freedom-236620/controller' |
| 20 | + primaryTag: $(Build.SourceBranchName) |
| 21 | + releaseCandidate: 'rc1' |
| 22 | + |
| 23 | +jobs: |
| 24 | + - job: Controller |
| 25 | + pool: |
| 26 | + vmImage: 'Ubuntu-16.04' |
| 27 | + |
| 28 | + steps: |
| 29 | + - task: NodeTool@0 |
| 30 | + inputs: |
| 31 | + versionSpec: '8.x' |
| 32 | + displayName: 'Install Node.js' |
| 33 | + |
| 34 | + - script: | |
| 35 | + npm install |
| 36 | + displayName: 'npm install and build' |
| 37 | +
|
| 38 | + # When we are ready to enforce standardjs, remove redirection and remove '|| true' from the standard script in package.json |
| 39 | + - script: | |
| 40 | + npm run standard 2>&1 | tee standardjs.out |
| 41 | + displayName: 'Standardjs report' |
| 42 | +
|
| 43 | + - script: | |
| 44 | + npm run snyk -- --project-name=ControllerCI |
| 45 | + displayName: 'Snyk monitor' |
| 46 | + env: |
| 47 | + SNYK_TOKEN: $(snykToken) |
| 48 | +
|
| 49 | + - script: | |
| 50 | + npm test |
| 51 | + displayName: 'unit tests' |
| 52 | +
|
| 53 | + - script: | |
| 54 | + echo "npm test" |
| 55 | + displayName: 'integration tests' |
| 56 | +
|
| 57 | + - script: | |
| 58 | + echo "##vso[task.setvariable variable=agent.jobstatus;]canceled" |
| 59 | + echo "##vso[task.complete result=Canceled;]DONE" |
| 60 | + condition: eq(variables['Build.Reason'], 'PullRequest') |
| 61 | +
|
| 62 | + - script: | |
| 63 | + npm pack |
| 64 | + ls iofogcontroller-*.tgz |
| 65 | + displayName: 'npm pack for release artefact' |
| 66 | +
|
| 67 | + - task: CopyFiles@2 |
| 68 | + inputs: |
| 69 | + SourceFolder: $(System.DefaultWorkingDirectory) |
| 70 | + TargetFolder: $(Build.ArtifactStagingDirectory) |
| 71 | + Contents: | |
| 72 | + standardjs.out |
| 73 | + *.tgz |
| 74 | + Dockerfile.dev |
| 75 | + OverWrite: true |
| 76 | + displayName: 'artefacts to publish' |
| 77 | + |
| 78 | + - script: | |
| 79 | + rm -fr iofogcontroller-*.tgz |
| 80 | + git checkout package-lock.json |
| 81 | + git config --global user.email "[email protected]" |
| 82 | + git config --global user.name "Azure DevOps" |
| 83 | +
|
| 84 | + PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') |
| 85 | + if [[ $(Build.SourceBranch) == refs/heads/release* ]]; then |
| 86 | + npm --no-git-tag-version version $PACKAGE_VERSION-$(releaseCandidate)-b$(Build.BuildId) |
| 87 | + else |
| 88 | + npm --no-git-tag-version version $PACKAGE_VERSION-b$(Build.BuildId) |
| 89 | + fi |
| 90 | + displayName: 'npm version' |
| 91 | +
|
| 92 | + - script: | |
| 93 | + npm pack |
| 94 | + displayName: 'npm pack with version containing build number' |
| 95 | +
|
| 96 | + - bash: | |
| 97 | + echo 'checking pack file exists..' |
| 98 | + tar=$(ls iofogcontroller-*.tgz) |
| 99 | + echo $tar |
| 100 | + echo "##vso[task.setvariable variable=controller_tar]$tar" |
| 101 | +
|
| 102 | + echo 'setting secondary tag' |
| 103 | + echo "##vso[task.setvariable variable=secondaryTag]b-$(Build.BuildId)" |
| 104 | +
|
| 105 | + if [[ $(Build.SourceBranch) == refs/heads/release* ]]; then |
| 106 | + echo "##vso[task.setvariable variable=primaryTag]rc-$(Build.SourceBranchName)" |
| 107 | + #If branch starts with ref/tags, apply latest and version tag |
| 108 | + elif [[ $(Build.SourceBranch) == refs/tags* ]]; then |
| 109 | + primaryTag= echo $(primaryTag) | awk '{print substr($1,2);}' |
| 110 | + echo $primaryTag |
| 111 | + echo "##vso[task.setvariable variable=primaryTag]$primaryTag" |
| 112 | + echo "##vso[task.setvariable variable=secondaryTag]latest" |
| 113 | + fi |
| 114 | + displayName: 'setting vars' |
| 115 | + name: setvarStep |
| 116 | +
|
| 117 | + - task: Docker@2 |
| 118 | + displayName: 'build docker' |
| 119 | + inputs: |
| 120 | + containerRegistry: 'Edgeworx GCP' |
| 121 | + repository: $(repository) |
| 122 | + command: 'build' |
| 123 | + Dockerfile: "Dockerfile.dev" |
| 124 | + arguments: --build-arg FILENAME=$(controller_tar) |
| 125 | + tags: | |
| 126 | + $(secondaryTag) |
| 127 | + $(primaryTag) |
| 128 | +
|
| 129 | + - task: Docker@2 |
| 130 | + displayName: 'push docker' |
| 131 | + inputs: |
| 132 | + containerRegistry: 'Edgeworx GCP' |
| 133 | + repository: $(repository) |
| 134 | + command: 'push' |
| 135 | + Dockerfile: "Dockerfile.dev" |
| 136 | + tags: | |
| 137 | + $(secondaryTag) |
| 138 | + $(primaryTag) |
| 139 | +
|
| 140 | + - script: | |
| 141 | + echo "npm test" |
| 142 | + displayName: 'api tests' |
| 143 | +
|
| 144 | + - task: PublishBuildArtifacts@1 |
| 145 | + inputs: |
| 146 | + PathtoPublish: '$(Build.ArtifactStagingDirectory)' |
| 147 | + ArtifactName: 'controller' |
| 148 | + |
| 149 | + - task: DownloadSecureFile@1 |
| 150 | + inputs: |
| 151 | + secureFile: 'package_cloud' |
| 152 | + displayName: 'download package cloud token file' |
| 153 | + |
| 154 | + - task: UseRubyVersion@0 |
| 155 | + inputs: |
| 156 | + versionSpec: '>= 2.5' |
| 157 | + addToPath: true |
| 158 | + displayName: 'install rubygem to be used to install package_cloud cli' |
| 159 | + |
| 160 | + - script: | |
| 161 | + gem install package_cloud |
| 162 | + package_cloud -h |
| 163 | + echo "config file..." |
| 164 | + echo $DOWNLOADSECUREFILE_SECUREFILEPATH |
| 165 | + displayName: 'install package_cloud cli' |
| 166 | +
|
| 167 | + - script: | |
| 168 | + echo $(controller_tar) |
| 169 | + package_cloud push iofog/iofog-controller-snapshots/node/1 $(controller_tar) --config=$DOWNLOADSECUREFILE_SECUREFILEPATH |
| 170 | + displayName: 'push to package cloud' |
0 commit comments