|
| 1 | +# This workflow uses actions that are not certified by GitHub. |
| 2 | +# They are provided by a third-party and are governed by |
| 3 | +# separate terms of service, privacy policy, and support |
| 4 | +# documentation. |
| 5 | + |
| 6 | +# This workflow lets you compile your Go project using a SLSA3 compliant builder. |
| 7 | +# This workflow will generate a so-called "provenance" file describing the steps |
| 8 | +# that were performed to generate the final binary. |
| 9 | +# The project is an initiative of the OpenSSF (openssf.org) and is developed at |
| 10 | +# https://github.com/slsa-framework/slsa-github-generator. |
| 11 | +# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier. |
| 12 | +# For more information about SLSA and how it improves the supply-chain, visit slsa.dev. |
| 13 | + |
| 14 | +name: SLSA releaser |
| 15 | +on: |
| 16 | + workflow_dispatch: |
| 17 | + push: |
| 18 | + tags: |
| 19 | + - "v*" |
| 20 | + |
| 21 | +permissions: read-all |
| 22 | +env: |
| 23 | + IMAGE_REGISTRY: ghcr.io |
| 24 | + IMAGE_NAME: ${{ github.repository }} |
| 25 | +jobs: |
| 26 | + # Generate ldflags dynamically. |
| 27 | + # Optional: only needed for ldflags. |
| 28 | + args: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + commit-date: ${{ steps.ldflags.outputs.commit-date }} |
| 32 | + commit: ${{ steps.ldflags.outputs.commit }} |
| 33 | + version: ${{ steps.ldflags.outputs.version }} |
| 34 | + tree-state: ${{ steps.ldflags.outputs.tree-state }} |
| 35 | + steps: |
| 36 | + - id: checkout |
| 37 | + uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # tag=v2.3.4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + - id: ldflags |
| 41 | + run: | |
| 42 | + echo "commit-date=$(git log --date=iso8601-strict -1 --pretty=%ct)" >> "$GITHUB_OUTPUT" |
| 43 | + echo "commit=$GITHUB_SHA" >> "$GITHUB_OUTPUT" |
| 44 | + echo "version=$(git describe --tags --always --dirty | cut -c2-)" >> "$GITHUB_OUTPUT" |
| 45 | + echo "tree-state=$(if git diff --quiet; then echo "clean"; else echo "dirty"; fi)" >> "$GITHUB_OUTPUT" |
| 46 | + build: |
| 47 | + permissions: |
| 48 | + id-token: write # To sign. |
| 49 | + contents: write # To upload release assets. |
| 50 | + actions: read # To read workflow path. |
| 51 | + strategy: |
| 52 | + matrix: |
| 53 | + os: |
| 54 | + - linux |
| 55 | + - windows |
| 56 | + - darwin |
| 57 | + arch: |
| 58 | + - amd64 |
| 59 | + - arm64 |
| 60 | + needs: args |
| 61 | + uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] |
| 62 | + with: |
| 63 | + go-version: 1.23 |
| 64 | + private-repository: true |
| 65 | + config-file: .slsa-goreleaser/${{matrix.os}}-${{matrix.arch}}.yml |
| 66 | + evaluated-envs: "COMMIT_DATE:${{needs.args.outputs.commit-date}}, COMMIT:${{needs.args.outputs.commit}}, VERSION:${{needs.args.outputs.version}}, TREE_STATE:${{needs.args.outputs.tree-state}}" |
| 67 | + # ============================================================================================================= |
| 68 | + # Optional: For more options, see https://github.com/slsa-framework/slsa-github-generator#golang-projects |
| 69 | + # ============================================================================================================= |
| 70 | + |
| 71 | + build-image: |
| 72 | + permissions: |
| 73 | + contents: read |
| 74 | + packages: write |
| 75 | + needs: args |
| 76 | + outputs: |
| 77 | + image: ${{ steps.image.outputs.image }} |
| 78 | + digest: ${{ steps.build.outputs.digest }} |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: Checkout the repository |
| 82 | + uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # v2.3.4 |
| 83 | + |
| 84 | + - name: Set up Docker Buildx |
| 85 | + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 |
| 86 | + |
| 87 | + - name: Authenticate Docker |
| 88 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 89 | + with: |
| 90 | + registry: ${{ env.IMAGE_REGISTRY }} |
| 91 | + username: ${{ github.actor }} |
| 92 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: Extract metadata (tags, labels) for Docker |
| 95 | + id: meta |
| 96 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 97 | + with: |
| 98 | + images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} |
| 99 | + |
| 100 | + - name: Build and push Docker image |
| 101 | + uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0 |
| 102 | + id: build |
| 103 | + with: |
| 104 | + push: true |
| 105 | + tags: ${{ steps.meta.outputs.tags }} |
| 106 | + labels: ${{ steps.meta.outputs.labels }} |
| 107 | + build-args: | |
| 108 | + VERSION=${{ needs.args.outputs.version }} |
| 109 | + GIT_COMMIT=${{ needs.args.outputs.commit }} |
| 110 | + BUILD_DATE=${{ needs.args.outputs.commit-date }} |
| 111 | + GIT_TREE_STATE=${{ needs.args.outputs.tree-state }} |
| 112 | + - name: Output image |
| 113 | + id: image |
| 114 | + run: | |
| 115 | + # NOTE: Set the image as an output because the `env` context is not |
| 116 | + # available to the inputs of a reusable workflow call. |
| 117 | + image_name=$(echo "${IMAGE_REGISTRY}/${IMAGE_NAME}"| tr '[:upper:]' '[:lower:]') |
| 118 | + echo "image=$image_name" >> "$GITHUB_OUTPUT" |
| 119 | + # This step calls the container workflow to generate provenance and push it to |
| 120 | + # the container registry. |
| 121 | + provenance: |
| 122 | + needs: build-image |
| 123 | + permissions: |
| 124 | + actions: read # for detecting the Github Actions environment. |
| 125 | + id-token: write # for creating OIDC tokens for signing. |
| 126 | + packages: write # for uploading attestations. |
| 127 | + uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] |
| 128 | + with: |
| 129 | + image: ${{ needs.build-image.outputs.image }} |
| 130 | + digest: ${{ needs.build-image.outputs.digest }} |
| 131 | + registry-username: ${{ github.actor }} |
| 132 | + private-repository: true |
| 133 | + secrets: |
| 134 | + registry-password: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments