|
| 1 | +name: Release Binaries and Images |
| 2 | +run-name: 'Release run by ${{ github.actor }}' |
| 3 | + |
| 4 | +on: |
| 5 | + # Release unstable from HEAD on every merge |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | + # Run manually to release unstable from HEAD |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + protect_ref: |
| 14 | + description: 'Edera Protect commit/branch/tag' |
| 15 | + default: '' |
| 16 | + |
| 17 | + # Nightly build from HEAD |
| 18 | + schedule: |
| 19 | + - cron: "0 9 * * *" |
| 20 | + |
| 21 | + # Official stable versioned release |
| 22 | + release: |
| 23 | + types: |
| 24 | + - published |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | +env: |
| 30 | + GCP_REGION: us-central1 |
| 31 | + GCP_PROJECT: edera-protect |
| 32 | + GCP_WORKLOAD_IDENTITY_PROVIDER: 'projects/914729349132/locations/global/workloadIdentityPools/prod-github-jr1s/providers/prod-github' |
| 33 | + GCP_SERVICE_ACCOUNT: 'edera-dev-preflight-sa@edera-protect.iam.gserviceaccount.com' |
| 34 | + |
| 35 | +jobs: |
| 36 | + # Implementing a gate like this isn't great since the workflow will still |
| 37 | + # run on release events. Github Actions does not have a way to filter on |
| 38 | + # tags for a release event yet so we are stuck with this. The other option |
| 39 | + # was to use the push event and filter on tags but since we're using push |
| 40 | + # events to publish unstable tags on main, it is cleaner to use release |
| 41 | + # events to trigger a true release of stable artifacts. |
| 42 | + release-gate: |
| 43 | + name: 'Check if this is the correct GitHub release event' |
| 44 | + runs-on: ubuntu-latest |
| 45 | + permissions: |
| 46 | + contents: read |
| 47 | + outputs: |
| 48 | + should_run: ${{ steps.check.outputs.should_run }} |
| 49 | + steps: |
| 50 | + - name: Harden the runner (Audit all outbound calls) |
| 51 | + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 |
| 52 | + with: |
| 53 | + egress-policy: audit |
| 54 | + |
| 55 | + - name: 'Check event' |
| 56 | + id: check |
| 57 | + run: | |
| 58 | + echo "Since GitHub doesn't have a way to filter for specific tags in the release event we need to implement this dumb check" |
| 59 | + run=true |
| 60 | + if [[ '${{ github.event_name }}' == 'release' ]] && [[ '${{ github.ref_name }}' =~ 'protect-chart-*' ]]; then |
| 61 | + run=false |
| 62 | + fi |
| 63 | + echo "Workflow should run: ${run}" |
| 64 | + echo "should_run=${run}" >> ${GITHUB_OUTPUT} |
| 65 | +
|
| 66 | + oci: |
| 67 | + name: 'Build and publish protect-${{ matrix.component }} images' |
| 68 | + # Check if this is the proper release event. |
| 69 | + # TODO: remove this when actions has a better answer |
| 70 | + if: ${{ needs.release-gate.outputs.should_run == 'true' }} |
| 71 | + needs: [release-gate] |
| 72 | + runs-on: ubuntu-latest |
| 73 | + strategy: |
| 74 | + fail-fast: false |
| 75 | + matrix: |
| 76 | + component: |
| 77 | + - preflight |
| 78 | + permissions: |
| 79 | + contents: read |
| 80 | + id-token: write |
| 81 | + packages: write |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: 'Harden runner' |
| 85 | + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 |
| 86 | + with: |
| 87 | + egress-policy: audit |
| 88 | + |
| 89 | + - name: 'Checkout repository' |
| 90 | + uses: actions/checkout@6b42224f41ee5dfe5395e27c8b2746f1f9955030 # v4.2.0 |
| 91 | + with: |
| 92 | + submodules: recursive |
| 93 | + persist-credentials: false |
| 94 | + |
| 95 | + - name: 'Build and sign protect-${{ matrix.component }} image' |
| 96 | + uses: edera-dev/actions/build-and-sign-image@v0.0.3 |
| 97 | + with: |
| 98 | + component: '${{ matrix.component }}' |
| 99 | + event: '${{ github.event_name }}' |
| 100 | + repositories: | |
| 101 | + ghcr.io/edera-dev/protect-${{ matrix.component }} |
| 102 | + ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT }}/staging/protect-${{ matrix.component }} |
| 103 | + gcp_region: '${{ env.GCP_REGION }}' |
| 104 | + gcp_workload_identity_provider: '${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}' |
| 105 | + gcp_service_account: '${{ env.GCP_SERVICE_ACCOUNT }}' |
0 commit comments