|
| 1 | +--- |
| 2 | +# yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json |
| 3 | +name: Cluster Release |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + paths: |
| 11 | + - .github/workflows/cluster-release.yaml |
| 12 | + - kubernetes/** |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: cluster-release-${{ github.ref }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +env: |
| 22 | + OCI_REPOSITORY: ghcr.io/${{ github.repository }}/cluster |
| 23 | + |
| 24 | +jobs: |
| 25 | + release: |
| 26 | + name: Build, Sign, and Publish |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + id-token: write |
| 30 | + packages: write |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Require main ref |
| 34 | + if: github.ref != 'refs/heads/main' |
| 35 | + run: | |
| 36 | + echo "Cluster releases must run from refs/heads/main" >&2 |
| 37 | + exit 1 |
| 38 | +
|
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 41 | + with: |
| 42 | + persist-credentials: false |
| 43 | + |
| 44 | + - name: Setup Flux CLI |
| 45 | + uses: fluxcd/flux2/action@889be9d6cc8afa8ed639e1e1ba4ab678e3b38d8c # v2.9.4 |
| 46 | + with: |
| 47 | + token: ${{ github.token }} |
| 48 | + version: 2.9.4 |
| 49 | + |
| 50 | + - name: Setup Cosign |
| 51 | + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 |
| 52 | + with: |
| 53 | + cosign-release: v3.1.3 |
| 54 | + |
| 55 | + - name: Login to GHCR |
| 56 | + uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0 |
| 57 | + with: |
| 58 | + registry: ghcr.io |
| 59 | + username: ${{ github.actor }} |
| 60 | + password: ${{ github.token }} |
| 61 | + |
| 62 | + - name: Publish immutable artifact |
| 63 | + id: publish |
| 64 | + env: |
| 65 | + ARTIFACT_DIR: ${{ runner.temp }}/cluster-artifact |
| 66 | + run: | |
| 67 | + mkdir -p "${ARTIFACT_DIR}/kubernetes" |
| 68 | + cp -a kubernetes/. "${ARTIFACT_DIR}/kubernetes/" |
| 69 | + result="$(flux push artifact "oci://${OCI_REPOSITORY}:${GITHUB_SHA}" \ |
| 70 | + --path "${ARTIFACT_DIR}" \ |
| 71 | + --source "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \ |
| 72 | + --revision "${GITHUB_REF_NAME}@sha1:${GITHUB_SHA}" \ |
| 73 | + --reproducible \ |
| 74 | + --output json)" |
| 75 | + digest="$(jq -er '.digest' <<< "${result}")" |
| 76 | + echo "digest=${digest}" >> "${GITHUB_OUTPUT}" |
| 77 | +
|
| 78 | + - name: Sign and verify artifact |
| 79 | + env: |
| 80 | + DIGEST: ${{ steps.publish.outputs.digest }} |
| 81 | + run: | |
| 82 | + cosign sign --yes --new-bundle-format=true "${OCI_REPOSITORY}@${DIGEST}" |
| 83 | + cosign verify \ |
| 84 | + --new-bundle-format=true \ |
| 85 | + --certificate-identity "${GITHUB_SERVER_URL}/${GITHUB_WORKFLOW_REF}" \ |
| 86 | + --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ |
| 87 | + "${OCI_REPOSITORY}@${DIGEST}" |
| 88 | +
|
| 89 | + - name: Promote artifact |
| 90 | + env: |
| 91 | + DIGEST: ${{ steps.publish.outputs.digest }} |
| 92 | + run: | |
| 93 | + flux tag artifact "oci://${OCI_REPOSITORY}@${DIGEST}" --tag latest |
0 commit comments