| 1 | trigger: |
| 2 | - master |
| 3 | |
| 4 | stages: |
| 5 | - stage: run_checks |
| 6 | displayName: "Check" |
| 7 | dependsOn: [] |
| 8 | jobs: |
| 9 | - job: fmt |
| 10 | displayName: "fmt" |
| 11 | pool: |
| 12 | vmImage: ubuntu-latest |
| 13 | steps: |
| 14 | - task: GoTool@0 |
| 15 | displayName: "Install Go 1.16" |
| 16 | inputs: |
| 17 | version: "1.16" |
| 18 | - task: Go@0 |
| 19 | displayName: "go fmt ./..." |
| 20 | inputs: |
| 21 | command: 'custom' |
| 22 | customCommand: 'fmt' |
| 23 | arguments: './...' |
| 24 | - job: coverage |
| 25 | displayName: "coverage" |
| 26 | pool: |
| 27 | vmImage: ubuntu-latest |
| 28 | steps: |
| 29 | - task: GoTool@0 |
| 30 | displayName: "Install Go 1.16" |
| 31 | inputs: |
| 32 | version: "1.16" |
| 33 | - task: Go@0 |
| 34 | displayName: "Generate coverage" |
| 35 | inputs: |
| 36 | command: 'test' |
| 37 | arguments: "-race -coverprofile=coverage.txt -covermode=atomic" |
| 38 | - task: Bash@3 |
| 39 | inputs: |
| 40 | targetType: 'inline' |
| 41 | script: 'bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}' |
| 42 | env: |
| 43 | CODECOV_TOKEN: $(CODECOV_TOKEN) |
| 44 | - job: benchmark |
| 45 | displayName: "benchmark" |
| 46 | pool: |
| 47 | vmImage: ubuntu-latest |
| 48 | steps: |
| 49 | - task: GoTool@0 |
| 50 | displayName: "Install Go 1.16" |
| 51 | inputs: |
| 52 | version: "1.16" |
| 53 | - script: echo "##vso[task.setvariable variable=PATH]${PATH}:/home/vsts/go/bin/" |
| 54 | - task: Bash@3 |
| 55 | inputs: |
| 56 | filePath: './benchmark.sh' |
| 57 | arguments: "master $(Build.Repository.Uri)" |
| 58 | |
| 59 | - job: go_unit_tests |
| 60 | displayName: "unit tests" |
| 61 | strategy: |
| 62 | matrix: |
| 63 | linux 1.16: |
| 64 | goVersion: '1.16' |
| 65 | imageName: 'ubuntu-latest' |
| 66 | mac 1.16: |
| 67 | goVersion: '1.16' |
| 68 | imageName: 'macOS-latest' |
| 69 | windows 1.16: |
| 70 | goVersion: '1.16' |
| 71 | imageName: 'windows-latest' |
| 72 | linux 1.15: |
| 73 | goVersion: '1.15' |
| 74 | imageName: 'ubuntu-latest' |
| 75 | mac 1.15: |
| 76 | goVersion: '1.15' |
| 77 | imageName: 'macOS-latest' |
| 78 | windows 1.15: |
| 79 | goVersion: '1.15' |
| 80 | imageName: 'windows-latest' |
| 81 | pool: |
| 82 | vmImage: $(imageName) |
| 83 | steps: |
| 84 | - task: GoTool@0 |
| 85 | displayName: "Install Go $(goVersion)" |
| 86 | inputs: |
| 87 | version: $(goVersion) |
| 88 | - task: Go@0 |
| 89 | displayName: "go test ./..." |
| 90 | inputs: |
| 91 | command: 'test' |
| 92 | arguments: './...' |
| 93 | - stage: build_binaries |
| 94 | displayName: "Build binaries" |
| 95 | dependsOn: run_checks |
| 96 | jobs: |
| 97 | - job: build_binary |
| 98 | displayName: "Build binary" |
| 99 | strategy: |
| 100 | matrix: |
| 101 | linux_amd64: |
| 102 | GOOS: linux |
| 103 | GOARCH: amd64 |
| 104 | darwin_amd64: |
| 105 | GOOS: darwin |
| 106 | GOARCH: amd64 |
| 107 | windows_amd64: |
| 108 | GOOS: windows |
| 109 | GOARCH: amd64 |
| 110 | pool: |
| 111 | vmImage: ubuntu-latest |
| 112 | steps: |
| 113 | - task: GoTool@0 |
| 114 | displayName: "Install Go" |
| 115 | inputs: |
| 116 | version: 1.16 |
| 117 | - task: Bash@3 |
| 118 | inputs: |
| 119 | targetType: inline |
| 120 | script: "make dist" |
| 121 | env: |
| 122 | go.goos: $(GOOS) |
| 123 | go.goarch: $(GOARCH) |
| 124 | - task: CopyFiles@2 |
| 125 | inputs: |
| 126 | sourceFolder: '$(Build.SourcesDirectory)' |
| 127 | contents: '*.tar.xz' |
| 128 | TargetFolder: '$(Build.ArtifactStagingDirectory)' |
| 129 | - task: PublishBuildArtifacts@1 |
| 130 | inputs: |
| 131 | pathtoPublish: '$(Build.ArtifactStagingDirectory)' |
| 132 | artifactName: binaries |
| 133 | - stage: build_binaries_manifest |
| 134 | displayName: "Build binaries manifest" |
| 135 | dependsOn: build_binaries |
| 136 | jobs: |
| 137 | - job: build_manifest |
| 138 | displayName: "Build binaries manifest" |
| 139 | steps: |
| 140 | - task: DownloadBuildArtifacts@0 |
| 141 | inputs: |
| 142 | buildType: 'current' |
| 143 | downloadType: 'single' |
| 144 | artifactName: 'binaries' |
| 145 | downloadPath: '$(Build.SourcesDirectory)' |
| 146 | - task: Bash@3 |
| 147 | inputs: |
| 148 | targetType: inline |
| 149 | script: "cd binaries && sha256sum --binary *.tar.xz | tee $(Build.ArtifactStagingDirectory)/sha256sums.txt" |
| 150 | - task: PublishBuildArtifacts@1 |
| 151 | inputs: |
| 152 | pathtoPublish: '$(Build.ArtifactStagingDirectory)' |
| 153 | artifactName: manifest |
| 154 | |
| 155 | - stage: build_docker_image |
| 156 | displayName: "Build Docker image" |
| 157 | dependsOn: run_checks |
| 158 | jobs: |
| 159 | - job: build |
| 160 | displayName: "Build" |
| 161 | pool: |
| 162 | vmImage: ubuntu-latest |
| 163 | steps: |
| 164 | - task: Docker@2 |
| 165 | inputs: |
| 166 | command: 'build' |
| 167 | Dockerfile: 'Dockerfile' |
| 168 | buildContext: '.' |
| 169 | addPipelineData: false |
| 170 | |
| 171 | - stage: publish_docker_image |
| 172 | displayName: "Publish Docker image" |
| 173 | dependsOn: build_docker_image |
| 174 | condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master')) |
| 175 | jobs: |
| 176 | - job: publish |
| 177 | displayName: "Publish" |
| 178 | pool: |
| 179 | vmImage: ubuntu-latest |
| 180 | steps: |
| 181 | - task: Docker@2 |
| 182 | inputs: |
| 183 | containerRegistry: 'DockerHub' |
| 184 | repository: 'pelletier/go-toml' |
| 185 | command: 'buildAndPush' |
| 186 | Dockerfile: 'Dockerfile' |
| 187 | buildContext: '.' |
| 188 | tags: 'latest' |