|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # create GitHub releases & upload assets |
| 10 | + packages: write # push to GHCR |
| 11 | + id-token: write # keyless cosign signing via OIDC |
| 12 | + |
| 13 | +env: |
| 14 | + IMAGE: ghcr.io/${{ github.repository }} |
| 15 | + GO_VERSION: "1.24" |
| 16 | + |
| 17 | +jobs: |
| 18 | + # ── 1. Build binaries for all platforms (parallelised) ─────────────────────── |
| 19 | + build: |
| 20 | + name: Build (${{ matrix.os }}-${{ matrix.arch }}${{ matrix.variant && format('v{0}', matrix.variant) || '' }}) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - { os: linux, arch: amd64 } |
| 26 | + - { os: linux, arch: arm64 } |
| 27 | + - { os: linux, arch: arm, variant: "7" } |
| 28 | + - { os: linux, arch: "386" } |
| 29 | + - { os: darwin, arch: amd64 } |
| 30 | + - { os: darwin, arch: arm64 } |
| 31 | + - { os: windows, arch: amd64 } |
| 32 | + - { os: windows, arch: "386" } |
| 33 | + |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - uses: actions/setup-go@v5 |
| 38 | + with: |
| 39 | + go-version: ${{ env.GO_VERSION }} |
| 40 | + cache: true |
| 41 | + |
| 42 | + - name: Build |
| 43 | + env: |
| 44 | + GOOS: ${{ matrix.os }} |
| 45 | + GOARCH: ${{ matrix.arch }} |
| 46 | + GOARM: ${{ matrix.variant }} |
| 47 | + CGO_ENABLED: "0" |
| 48 | + run: | |
| 49 | + VERSION="${{ github.ref_name }}" |
| 50 | + REVISION="$(git rev-parse --short=8 HEAD)" |
| 51 | + REFERENCE="${{ github.ref_name }}" |
| 52 | + BUILT="$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 53 | + PKG="github.com/codecentric/fleeting-plugin-scaleway" |
| 54 | +
|
| 55 | + ARCH_DIR="${{ matrix.arch }}${{ matrix.variant && format('v{0}', matrix.variant) || '' }}" |
| 56 | + EXT="${{ matrix.os == 'windows' && '.exe' || '' }}" |
| 57 | + OUTDIR="dist/${{ matrix.os }}/${ARCH_DIR}" |
| 58 | + mkdir -p "${OUTDIR}" |
| 59 | +
|
| 60 | + go build -a \ |
| 61 | + -ldflags "-w -s \ |
| 62 | + -X ${PKG}.VERSION=${VERSION} \ |
| 63 | + -X ${PKG}.REVISION=${REVISION} \ |
| 64 | + -X ${PKG}.REFERENCE=${REFERENCE} \ |
| 65 | + -X ${PKG}.BUILT=${BUILT}" \ |
| 66 | + -o "${OUTDIR}/plugin${EXT}" \ |
| 67 | + ./cmd/fleeting-plugin-scaleway/... |
| 68 | +
|
| 69 | + echo "Built ${OUTDIR}/plugin${EXT}" |
| 70 | +
|
| 71 | + - name: Upload dist artifact |
| 72 | + uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: dist-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.variant && format('v{0}', matrix.variant) || '' }} |
| 75 | + path: dist/ |
| 76 | + retention-days: 1 |
| 77 | + |
| 78 | + # ── 2. Publish OCI artifact to GHCR & create GitHub release ───────────────── |
| 79 | + release: |
| 80 | + name: Publish OCI & GitHub Release |
| 81 | + runs-on: ubuntu-latest |
| 82 | + needs: build |
| 83 | + |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - uses: actions/setup-go@v5 |
| 88 | + with: |
| 89 | + go-version: ${{ env.GO_VERSION }} |
| 90 | + cache: true |
| 91 | + |
| 92 | + # Merge all per-platform dist/ directories into one |
| 93 | + - name: Download all dist artifacts |
| 94 | + uses: actions/download-artifact@v4 |
| 95 | + with: |
| 96 | + pattern: dist-* |
| 97 | + path: dist/ |
| 98 | + merge-multiple: true |
| 99 | + |
| 100 | + - name: Display dist layout |
| 101 | + run: find dist -type f | sort |
| 102 | + |
| 103 | + # Install fleeting-artifact |
| 104 | + - name: Install fleeting-artifact |
| 105 | + run: go install gitlab.com/gitlab-org/fleeting/fleeting-artifact/cmd/fleeting-artifact@latest |
| 106 | + |
| 107 | + # Install cosign for keyless signing |
| 108 | + - name: Install cosign |
| 109 | + uses: sigstore/cosign-installer@v3 |
| 110 | + |
| 111 | + # Log in to GHCR |
| 112 | + - name: Log in to GHCR |
| 113 | + uses: docker/login-action@v3 |
| 114 | + with: |
| 115 | + registry: ghcr.io |
| 116 | + username: ${{ github.actor }} |
| 117 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + |
| 119 | + # Push the multi-platform OCI artifact and capture the digest |
| 120 | + - name: Release OCI artifact |
| 121 | + id: oci |
| 122 | + env: |
| 123 | + VERSION: ${{ github.ref_name }} |
| 124 | + run: | |
| 125 | + # Strip leading 'v' for the OCI tag (fleeting-artifact expects semver without 'v') |
| 126 | + SEMVER="${VERSION#v}" |
| 127 | + DIGEST="$(fleeting-artifact release -dir dist "${{ env.IMAGE }}:${SEMVER}")" |
| 128 | + echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT" |
| 129 | + echo "semver=${SEMVER}" >> "$GITHUB_OUTPUT" |
| 130 | +
|
| 131 | + # Keyless sign the OCI artifact with cosign + OIDC |
| 132 | + - name: Sign OCI artifact |
| 133 | + env: |
| 134 | + COSIGN_YES: "true" |
| 135 | + run: cosign sign "${{ steps.oci.outputs.digest }}" |
| 136 | + |
| 137 | + # Build checksums of all binaries for the GitHub release assets |
| 138 | + - name: Generate checksums |
| 139 | + run: | |
| 140 | + find dist -type f -name 'plugin*' | sort | xargs sha256sum > checksums.txt |
| 141 | + cat checksums.txt |
| 142 | +
|
| 143 | + # Create a GitHub release with the binary archives and checksums |
| 144 | + - name: Create GitHub Release |
| 145 | + uses: softprops/action-gh-release@v2 |
| 146 | + with: |
| 147 | + name: Release ${{ github.ref_name }} |
| 148 | + generate_release_notes: true |
| 149 | + files: | |
| 150 | + checksums.txt |
0 commit comments