github.com/go-swagger/go-swagger@v0.31.0/.github/workflows/test.yaml (about) 1 name: Run CI 2 3 env: 4 GOCOVMODE: atomic 5 6 on: 7 push: 8 tags: 9 - v* 10 branches: 11 - master 12 paths-ignore: 13 - docs/* 14 - hack/hugo/* 15 - .github/workflows/update-doc.yaml 16 17 pull_request_target: 18 19 # pull_request: 20 # paths-ignore: 21 # - docs/* 22 # - hack/hugo/* 23 # - .github/workflows/update-doc.yaml 24 25 permissions: 26 contents: write 27 pull-requests: read 28 29 jobs: 30 lint: 31 name: lint 32 runs-on: ubuntu-latest 33 steps: 34 - uses: actions/checkout@v4 35 - uses: actions/setup-go@v5 36 with: 37 go-version: stable 38 check-latest: true 39 cache: true 40 - name: golangci-lint 41 uses: golangci/golangci-lint-action@v3 42 with: 43 args: --verbose 44 only-new-issues: true 45 skip-cache: true 46 version: latest 47 48 build: 49 # description: | 50 # Make sure we build and run elementary operations. 51 # And that, at this moment, it still runs with go 1.20. 52 # The full test suite warrants support for the 2 latest go minor releases. 53 needs: [lint] 54 strategy: 55 matrix: 56 go: ['1.20','oldstable','stable'] 57 os: [ubuntu-latest, macos-latest, windows-latest, macos-13] 58 runs-on: ${{ matrix.os }} 59 steps: 60 - uses: actions/checkout@v4 61 - uses: actions/setup-go@v5 62 with: 63 go-version: ${{ matrix.go }} 64 check-latest: true 65 cache: true 66 67 - name: Build binary 68 run: | 69 go install ./cmd/swagger 70 71 - name: Verify that examples build 72 run: | 73 cd examples 74 go build ./... 75 go test ./... 76 77 - name: Run validation tests 78 run: | 79 swagger validate fixtures/bugs/2493/fixture-2492.json 80 swagger validate fixtures/bugs/2493/fixture-2493.json 81 swagger validate fixtures/bugs/2493/fixture-2492.yaml 82 swagger validate fixtures/bugs/2493/fixture-2493.yaml 83 swagger validate fixtures/bugs/2866/2866.yaml 84 85 test: 86 # description: | 87 # Run unit tests on the 2 most recent go releases and 3 popular platforms. 88 needs: [lint] 89 strategy: 90 matrix: 91 go: ['oldstable','stable'] 92 os: [ubuntu-latest, macos-latest, windows-latest] 93 exclude: # <- temporarily exclude go1.22.0 on windows. We hit this bug:https://github.com/golang/go/issues/65653 94 - go: stable 95 os: windows-latest 96 runs-on: ${{ matrix.os }} 97 steps: 98 - uses: actions/checkout@v4 99 - uses: actions/setup-go@v5 100 with: 101 go-version: ${{ matrix.go }} 102 check-latest: true 103 cache: true 104 105 - name: Install Tools 106 run: | 107 go install gotest.tools/gotestsum@latest 108 109 - name: Run unit tests with code coverage 110 run: > 111 gotestsum -- 112 -p 1 113 -timeout=20m 114 -coverprofile='coverage-${{ matrix.os }}-${{ matrix.go }}.txt' 115 -covermode=atomic 116 -coverpkg=$(go list)/... 117 ./... 118 119 - name: Publish To Codecov 120 # retry after 30s whenever codecov servers experience delays. 121 # inspired by https://github.com/Kong/kubernetes-testing-framework/blob/230e26621db6af0d8543e784afb208e8c2a6b710/.github/workflows/tests.yaml#L57 122 # until retries are eventually natively supported by the codecov CLI: https://github.com/codecov/codecov-action/issues/926 123 uses: Wandalen/wretry.action@v3 124 with: 125 action: codecov/codecov-action@v4 126 attempt_limit: 10 127 attempt_delay: 30000 128 with: | 129 files: 'coverage-${{ matrix.os }}-${{ matrix.go }}.txt' 130 flags: 'unit-${{ matrix.go }}' 131 os: '${{ matrix.os }}' 132 fail_ci_if_error: true 133 verbose: true 134 # This secret is not passed on when triggered by PR from a fork: in this case, 135 # tokenless upload is used by the codecov CLI. 136 # It is used when running the workflow from pushed commits or tags on master. 137 token: ${{ secrets.CODECOV_TOKEN }} 138 139 codegen_test: 140 # description: | 141 # Exercise go-swagger from the command line, with a bunch of specs 142 # and several options (flatten/expand spec). 143 # 144 # The test matrix applies to linux only. OS-specific quirks should 145 # be covered by unit tests. 146 needs: [lint] 147 strategy: 148 matrix: 149 go: ['oldstable','stable'] 150 os: [ubuntu-latest] 151 include: 152 - fixture: codegen-fixtures # <- complex API specs to torture the code generator 153 args: "-skip-models -skip-full-flatten" 154 - fixture: canary-fixtures # <- popular real-life API specs 155 args: "-skip-models -skip-full-flatten -skip-expand" 156 runs-on: ${{ matrix.os }} 157 env: 158 GOCOVERDIR: /tmp/cov 159 steps: 160 - uses: actions/checkout@v4 161 - uses: actions/setup-go@v5 162 with: 163 go-version: ${{ matrix.go }} 164 check-latest: true 165 cache: true 166 167 - name: Install Tools 168 run: | 169 go get gotest.tools/icmd@latest 170 mkdir /tmp/cov 171 172 - name: Build binary with test coverage instrumentation 173 run: > 174 ./hack/build-docker.sh --github-action 175 -cover 176 -covermode=atomic 177 -coverpkg=$(go list)/... 178 179 - name: Run codegen tests 180 run: > 181 go test -v -timeout 30m -parallel 3 182 hack/codegen_nonreg_test.go 183 -args -fixture-file "${{ matrix.fixture }}.yaml" $${{ matrix.args }} 184 - name: Construct coverage reports from integration tests 185 run: > 186 go tool covdata textfmt 187 -i "${GOCOVERDIR}" 188 -o "codegen-coverage-${{ matrix.os }}-${{ matrix.go }}-${{ matrix.fixture }}.txt" 189 190 - name: Publish To Codecov 191 uses: codecov/codecov-action@v4 192 with: 193 files: 'codegen-coverage-${{ matrix.os }}-${{ matrix.go }}-${{ matrix.fixture }}.txt' 194 flags: 'codegen-${{ matrix.go }}-${{ matrix.fixture }}' 195 os: '${{ matrix.os }}' 196 fail_ci_if_error: true 197 verbose: true 198 token: ${{ secrets.CODECOV_TOKEN }} # <- this secret is not passed on when triggered by PR from a fork 199 200 docker_dev: 201 needs: [lint, build, test, codegen_test] 202 if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v') 203 runs-on: ubuntu-latest 204 steps: 205 - name: Checkout 206 uses: actions/checkout@v4 207 208 - name: Docker meta 209 id: meta 210 uses: docker/metadata-action@v5 211 with: 212 images: | 213 quay.io/goswagger/swagger 214 ghcr.io/go-swagger/go-swagger 215 tags: | 216 type=ref,event=branch 217 type=sha 218 219 - name: Set up QEMU 220 uses: docker/setup-qemu-action@v3 221 222 - name: Set up Docker Buildx 223 uses: docker/setup-buildx-action@v3 224 225 - name: Login to Quay Registry 226 uses: docker/login-action@v2 227 with: 228 registry: quay.io 229 username: ${{ secrets.QUAY_USERNAME }} 230 password: ${{ secrets.QUAY_PASS }} 231 232 - name: Login to GitHub Container Registry 233 if: github.event_name != 'pull_request' 234 uses: docker/login-action@v2 235 with: 236 registry: ghcr.io 237 username: ${{ github.repository_owner }} 238 password: ${{ secrets.CR_PAT }} 239 240 - name: Build and push 241 uses: docker/build-push-action@v3 242 with: 243 context: . 244 build-args: | 245 commit_hash=${{ github.sha }} 246 tag_name=dev 247 platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x 248 push: ${{ github.event_name != 'pull_request' }} 249 tags: ${{ steps.meta.outputs.tags }} 250 251 publish_release: 252 needs: [lint, build, test, codegen_test] 253 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') 254 runs-on: ubuntu-latest 255 steps: 256 - uses: actions/checkout@v4 257 - uses: actions/setup-go@v5 258 with: 259 go-version: 'stable' 260 check-latest: true 261 cache: true 262 263 - name: Install Tools 264 run: | 265 go install github.com/aktau/github-release@latest 266 go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest 267 268 - name: Build release 269 run: | 270 set -x 271 rm -rf dist 272 mkdir -p dist/bin 273 mkdir -p dist/build 274 275 build_binary() { 276 LDFLAGS="-s -w -X github.com/$GITHUB_REPOSITORY/cmd/swagger/commands.Commit=${GITHUB_SHA}" 277 LDFLAGS="$LDFLAGS -X github.com/$GITHUB_REPOSITORY/cmd/swagger/commands.Version=${GITHUB_REF_NAME-dev}" 278 out="swagger_$1_$2" 279 if [[ $1 == "windows" ]]; then 280 out="${out}.exe" 281 fi 282 GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "./dist/bin/$out" ./cmd/swagger 283 } 284 285 go mod download 286 287 build_binary linux amd64 288 build_binary linux arm64 289 build_binary linux arm 290 build_binary linux ppc64le 291 build_binary linux s390x 292 build_binary darwin amd64 293 build_binary darwin arm64 294 build_binary windows amd64 295 build_binary windows arm64 296 297 nfpm p -p deb -t dist/build 298 nfpm p -p rpm -t dist/build 299 300 pushd dist/bin || exit 1 301 sha1sum * > sha1sum.txt 302 sha256sum * > sha256sum.txt 303 popd || exit 1 304 305 - name: Push RPM 306 id: push_rpm 307 uses: cloudsmith-io/action@master 308 with: 309 api-key: ${{ secrets.CLOUDSMITH_API_KEY }} 310 command: "push" 311 format: "rpm" 312 owner: "go-swagger" 313 repo: "go-swagger" 314 distro: "fedora" 315 release: "any-version" 316 file: "dist/build/swagger-*.x86_64.rpm" 317 318 - name: Push Deb 319 id: push 320 uses: cloudsmith-io/action@master 321 with: 322 api-key: ${{ secrets.CLOUDSMITH_API_KEY }} 323 command: "push" 324 format: "deb" 325 owner: "go-swagger" 326 repo: "go-swagger" 327 distro: "debian" 328 release: "any-version" 329 file: "dist/build/swagger_*_amd64.deb" 330 331 - name: Publish Binaries 332 uses: fnkr/github-action-ghr@v1 333 env: 334 GHR_PATH: dist/bin/ 335 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 336 337 docker: 338 needs: [lint, build, test, codegen_test] 339 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') 340 runs-on: ubuntu-latest 341 steps: 342 - name: Checkout 343 uses: actions/checkout@v4 344 345 - name: Docker meta 346 id: meta 347 uses: docker/metadata-action@v4 348 with: 349 # list of Docker images to use as base name for tags 350 images: | 351 quay.io/goswagger/swagger 352 ghcr.io/go-swagger/go-swagger 353 # generate Docker tags based on the following events/attributes 354 tags: | 355 type=ref,event=tag 356 type=semver,pattern={{version}} 357 type=semver,pattern={{major}}.{{minor}} 358 type=semver,pattern={{major}} 359 type=sha 360 361 - name: Set up QEMU 362 uses: docker/setup-qemu-action@v3 363 364 - name: Set up Docker Buildx 365 uses: docker/setup-buildx-action@v3 366 367 - name: Login to Quay Registry 368 uses: docker/login-action@v2 369 with: 370 registry: quay.io 371 username: ${{ secrets.QUAY_USERNAME }} 372 password: ${{ secrets.QUAY_PASS }} 373 374 - name: Login to GitHub Container Registry 375 if: github.event_name != 'pull_request' 376 uses: docker/login-action@v2 377 with: 378 registry: ghcr.io 379 username: ${{ github.repository_owner }} 380 password: ${{ secrets.CR_PAT }} 381 382 - name: Build and push 383 uses: docker/build-push-action@v3 384 with: 385 context: . 386 build-args: | 387 commit_hash=${{ github.sha }} 388 tag_name=${{ github.ref_name }} 389 platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x 390 push: ${{ github.event_name != 'pull_request' }} 391 tags: ${{ steps.meta.outputs.tags }}