github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/devops/azure-pipeline.yml (about) 1 name: $(date:yyyyMMdd)$(rev:.r) 2 pool: 3 name: Default 4 demands: 5 - agent.OS -equals Linux 6 variables: 7 BuildConfiguration: 'release' 8 BuildPlatform: 'any cpu' 9 LintExecute: 'true' 10 ContractTestExecute: 'true' 11 RunscopeExecute: 'false' 12 Organization: mundipagg 13 SonarcloudAccount: Sonarqube 14 ProjectKey: mundipagg_boleto-api 15 ProjectName: boleto-api 16 ImageVersion: $(Build.BuildNumber) 17 CGO_ENABLED: 0 18 19 trigger: 20 batch: true 21 branches: 22 include: 23 - '*' 24 tags: 25 include: 26 - '*' 27 pr: 28 branches: 29 include: 30 - 'master' 31 resources: 32 repositories: 33 - repository: self 34 type: git 35 ref: master 36 stages: 37 - stage: QA 38 jobs: 39 - job: Linter 40 displayName: Linter 41 workspace: 42 clean: all 43 steps: 44 - task: GoTool@0 45 displayName: Use Go 1.13.14 46 inputs: 47 version: 1.13.14 48 - task: Go@0 49 displayName: go mod download 50 inputs: 51 command: custom 52 customCommand: mod 53 arguments: download 54 workingDirectory: $(System.DefaultWorkingDirectory) 55 - task: Bash@3 56 displayName: Install Go lint 57 inputs: 58 targetType: inline 59 script: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(System.DefaultWorkingDirectory) v1.42.1 60 - task: Bash@3 61 condition: eq(variables['LintExecute'], 'true') 62 displayName: Run linter 63 inputs: 64 targetType: inline 65 script: $(System.DefaultWorkingDirectory)/golangci-lint run --new-from-rev=origin/master --timeout 2m0s --allow-parallel-runners 66 - job: QualityAnalysis 67 displayName: Quality Analysis 68 workspace: 69 clean: all 70 steps: 71 - task: GoTool@0 72 displayName: Use Go 1.13.14 73 inputs: 74 version: 1.13.14 75 - task: Bash@3 76 displayName: Install ubuntu requerements 77 inputs: 78 targetType: inline 79 script: | 80 apt-get update && apt-get install -y ca-certificates openssl curl default-jre 81 export cert_location=/usr/local/share/ca-certificates 82 - task: Go@0 83 displayName: go mod download 84 inputs: 85 command: custom 86 customCommand: mod 87 arguments: download 88 workingDirectory: $(System.DefaultWorkingDirectory) 89 - task: Go@0 90 displayName: go test 91 inputs: 92 command: test 93 arguments: ./... -short -coverprofile=coverage.file -tags=unit 94 workingDirectory: $(System.DefaultWorkingDirectory) 95 - task: SonarCloudPrepare@1 96 displayName: Prepare analysis on SonarCloud 97 inputs: 98 SonarCloud: $(SonarcloudAccount) 99 organization: $(Organization) 100 projectKey: $(ProjectKey) 101 projectName: $(ProjectName) 102 scannerMode: CLI 103 configFile: $(System.DefaultWorkingDirectory)/sonar-project.properties 104 - task: SonarCloudAnalyze@1 105 displayName: Run Code Analysis 106 - task: SonarCloudPublish@1 107 displayName: Publish Quality Gate Result 108 - job: ContractTest 109 displayName: Contract Test 110 dependsOn: QualityAnalysis 111 condition: | 112 and 113 ( 114 eq(variables['ContractTestExecute'], 'true'), 115 eq(dependencies.QualityAnalysis.result, 'Succeeded') 116 ) 117 steps: 118 - task: Bash@3 119 displayName: docker-compose build contract-test 120 inputs: 121 targetType: inline 122 script: > 123 cd devops 124 125 docker-compose build contract-test 126 - task: Bash@3 127 displayName: Run contract test 128 inputs: 129 targetType: inline 130 script: >- 131 cd devops 132 133 docker-compose run --rm \ 134 -e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \ 135 -e PACT_URL=$(PACT_URL) \ 136 -e GITHUB_COMMIT=$(Build.SourceVersion) \ 137 -e GITHUB_BRANCH=$(Build.SourceBranchName) \ 138 -e PACT_BROKER_URL=https://pagarme.pactflow.io/ \ 139 contract-test 140 - task: Bash@3 141 displayName: Can I deploy 142 inputs: 143 targetType: inline 144 script: > 145 docker run --rm \ 146 -e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \ 147 pactfoundation/pact-cli:0.47.1.0 \ 148 broker can-i-deploy \ 149 --broker-base-url 'https://pagarme.pactflow.io' \ 150 --pacticipant 'boleto-api' \ 151 --version $(Build.SourceVersion) 152 - job: RunscopeTests 153 displayName: Runscope tests 154 dependsOn: ContractTest 155 condition: | 156 and 157 ( 158 eq(variables['RunscopeExecute'], 'true'), 159 eq(dependencies.QualityAnalysis.result, 'Succeeded'), 160 in(dependencies.ContractTest.result, 'Succeeded', 'Skipped') 161 ) 162 continueOnError: 'true' 163 steps: 164 - task: ThiagoBarradas.runscopetest.runscopetest-task.runscopetest@1 165 displayName: 'Runscope Integration Test' 166 inputs: 167 triggerUrl: '$(RunscopeUrl)' 168 accessToken: '$(RunscopeToken)' 169 - stage: Build 170 dependsOn: 171 - QA 172 condition: succeeded() 173 jobs: 174 - job: Build 175 cancelTimeoutInMinutes: 1 176 workspace: 177 clean: all 178 steps: 179 - task: Bash@3 180 displayName: Moves files to src/github.com/mundipagg/boleto-api 181 inputs: 182 targetType: inline 183 script: >- 184 mkdir -p src/github.com/mundipagg/boleto-api; 185 186 mv $(ls | grep -vwE "(src)") src/github.com/mundipagg/boleto-api/; 187 - task: GoTool@0 188 displayName: Use Go 1.13.14 189 inputs: 190 version: 1.13.14 191 goPath: $(System.DefaultWorkingDirectory) 192 - task: Go@0 193 displayName: go mod download 194 inputs: 195 command: custom 196 customCommand: mod 197 arguments: download 198 workingDirectory: $(System.DefaultWorkingDirectory)/src/github.com/mundipagg/boleto-api 199 - task: Go@0 200 displayName: go build - com GoMod 201 inputs: 202 command: build 203 arguments: -o "$(Build.Repository.LocalPath)/build-output/api/boleto-api" 204 workingDirectory: $(System.DefaultWorkingDirectory)/src/github.com/mundipagg/boleto-api 205 - task: Bash@3 206 displayName: go build - sem GoMod 207 enabled: False 208 inputs: 209 targetType: inline 210 script: GO111MODULE=off go build -o "$(Build.Repository.LocalPath)/build-output/api/boleto-api" . 211 workingDirectory: $(System.DefaultWorkingDirectory)/src/github.com/mundipagg/boleto-api 212 - task: CopyFiles@2 213 displayName: Copy Files "Time" 214 inputs: 215 SourceFolder: ./src/github.com/mundipagg/boleto-api/devops/time 216 TargetFolder: $(Build.Repository.LocalPath)/build-output/api/lib/time 217 CleanTargetFolder: true 218 - task: CopyFiles@2 219 displayName: Copy Files "Boleto" 220 inputs: 221 SourceFolder: ./src/github.com/mundipagg/boleto-api/boleto 222 Contents: >- 223 Arial.ttf 224 225 favicon.ico 226 TargetFolder: $(Build.Repository.LocalPath)/build-output/api/boleto 227 CleanTargetFolder: true 228 - task: ArchiveFiles@2 229 displayName: Archive Files 230 inputs: 231 rootFolderOrFile: '$(Build.Repository.LocalPath)/build-output' 232 includeRootFolder: false 233 archiveType: 'tar' 234 tarCompression: 'none' 235 archiveFile: '$(Build.ArtifactStagingDirectory)/boleto-api-$(Build.BuildId).tar' 236 replaceExistingArchive: true 237 - task: PublishBuildArtifacts@1 238 displayName: Publish Artifact 239 inputs: 240 PathtoPublish: '$(Build.ArtifactStagingDirectory)' 241 ArtifactName: 'drop' 242 publishLocation: 'Container'