release #127
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| env: | |
| IMAGE: ghcr.io/sergeii/swat4master | |
| on: | |
| workflow_run: | |
| workflows: [ci] | |
| branches: [main] | |
| types: [completed] | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: release | |
| cancel-in-progress: true | |
| jobs: | |
| plan-release-tag: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| outputs: | |
| tag: ${{ steps.plan.outputs.new_tag }} | |
| changelog: ${{ steps.plan.outputs.changelog }} | |
| date: ${{ steps.build_meta.outputs.date }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: mathieudutour/github-tag-action@v6.2 | |
| id: plan | |
| with: | |
| dry_run: true | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| default_bump: false | |
| - name: Prepare build metadata | |
| id: build_meta | |
| run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | |
| # https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners | |
| build-arch-image: | |
| runs-on: ${{ matrix.platform.runner }} | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| packages: write | |
| needs: plan-release-tag | |
| if: needs.plan-release-tag.outputs.tag != '' | |
| outputs: | |
| digest_amd64: ${{ steps.digest.outputs.amd64 }} | |
| digest_arm64: ${{ steps.digest.outputs.arm64 }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - id: amd64 | |
| name: linux/amd64 | |
| runner: ubuntu-24.04 | |
| - id: arm64 | |
| name: linux/arm64 | |
| runner: ubuntu-24.04-arm | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare image metadata | |
| uses: docker/metadata-action@v6 | |
| id: meta | |
| with: | |
| images: ${{ env.IMAGE }} | |
| - name: Build and push image by digest | |
| uses: docker/build-push-action@v7 | |
| id: build | |
| with: | |
| context: . | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: ${{ matrix.platform.name }} | |
| outputs: type=image,"name=${{ env.IMAGE }}",push-by-digest=true,name-canonical=true,push=true | |
| build-args: | | |
| build_commit_sha=${{ github.sha }} | |
| build_version=${{ needs.plan-release-tag.outputs.tag }} | |
| build_time=${{ needs.plan-release-tag.outputs.date }} | |
| - name: Export image digest | |
| id: digest | |
| run: echo "${{ matrix.platform.id }}=${{ steps.build.outputs.digest }}" >> $GITHUB_OUTPUT | |
| build-binaries: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| needs: plan-release-tag | |
| if: needs.plan-release-tag.outputs.tag != '' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| goos: [darwin, linux] | |
| goarch: [amd64, arm64] | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| - name: Prepare build meta | |
| id: build_meta | |
| run: echo "asset=swat4master-${{ needs.plan-release-tag.outputs.tag }}.${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz" >> $GITHUB_OUTPUT | |
| - name: Generate API docs | |
| run: make generate-api-docs | |
| - name: Build binary | |
| run: >- | |
| make build | |
| GOOS=${{ matrix.goos }} | |
| GOARCH=${{ matrix.goarch }} | |
| BUILD_TIME=${{ needs.plan-release-tag.outputs.date }} | |
| BUILD_COMMIT=${{ github.sha }} | |
| BUILD_VERSION=${{ needs.plan-release-tag.outputs.tag }} | |
| - name: Pack release files | |
| run: tar -czf ${{ steps.build_meta.outputs.asset }} swat4master LICENSE | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ steps.build_meta.outputs.asset }} | |
| path: ${{ steps.build_meta.outputs.asset }} | |
| if-no-files-found: error | |
| push-image-manifest: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| packages: write | |
| contents: read | |
| needs: [plan-release-tag, build-arch-image] | |
| steps: | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create and push multi-arch manifest | |
| run: >- | |
| docker buildx imagetools create | |
| -t ${{ env.IMAGE }}:latest | |
| -t ${{ env.IMAGE }}:${{ needs.plan-release-tag.outputs.tag }} | |
| ${{ env.IMAGE }}@${{ needs.build-arch-image.outputs.digest_amd64 }} | |
| ${{ env.IMAGE }}@${{ needs.build-arch-image.outputs.digest_arm64 }} | |
| - name: Inspect pushed manifest | |
| run: docker buildx imagetools inspect ${{ env.IMAGE }}:latest | |
| create-release-tag: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: write | |
| needs: [plan-release-tag, push-image-manifest, build-binaries] | |
| if: needs.plan-release-tag.outputs.tag != '' | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| pattern: "swat4master-*" | |
| merge-multiple: true | |
| - name: Create git tag | |
| uses: mathieudutour/github-tag-action@v6.2 | |
| with: | |
| commit_sha: ${{ github.sha }} | |
| custom_tag: ${{ needs.plan-release-tag.outputs.tag }} | |
| tag_prefix: "" | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| default_bump: false | |
| - name: Create GitHub release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: ${{ needs.plan-release-tag.outputs.tag }} | |
| name: Release ${{ needs.plan-release-tag.outputs.tag }} | |
| body: ${{ needs.plan-release-tag.outputs.changelog }} | |
| artifacts: "swat4master-*" |