Build and Release #36
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: Build and Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - deploy/helm/Chart.yaml | |
| workflow_dispatch: | |
| inputs: | |
| skip-e2e: | |
| description: Skip e2e tests | |
| type: boolean | |
| default: false | |
| concurrency: | |
| group: ${{ github.workflow }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| packages: read | |
| env: | |
| REGISTRY: ghcr.io | |
| CHART_DIR: deploy/helm | |
| jobs: | |
| detect: | |
| timeout-minutes: 5 | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| skip: ${{ steps.detect.outputs.skip }} | |
| app_version: ${{ steps.detect.outputs.app_version }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Detect appVersion bump | |
| id: detect | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| app_version=$(yq .appVersion "$CHART_DIR/Chart.yaml") | |
| echo "app_version=$app_version" >> "$GITHUB_OUTPUT" | |
| if gh release view "$app_version" > /dev/null 2>&1; then | |
| echo "Release $app_version already exists. Skipping." | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| build-image: | |
| needs: detect | |
| if: ${{ needs.detect.outputs.skip == 'false' }} | |
| uses: ./.github/workflows/_reusable-build.yaml | |
| with: | |
| tags: ${{ github.sha }} | |
| secrets: inherit | |
| permissions: | |
| contents: read | |
| packages: write | |
| e2e: | |
| needs: build-image | |
| if: needs.detect.outputs.skip == 'false' && !inputs['skip-e2e'] | |
| uses: ./.github/workflows/_reusable-e2e.yaml | |
| with: | |
| image_tag: ${{ github.sha }} | |
| secrets: inherit | |
| release: | |
| needs: [detect, build-image, e2e] | |
| if: >- | |
| always() && | |
| needs.detect.outputs.skip == 'false' && | |
| needs.build-image.result == 'success' && | |
| (needs.e2e.result == 'success' || needs.e2e.result == 'skipped') | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: write | |
| packages: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup ORAS | |
| uses: oras-project/setup-oras@1d808f7d7f6995cc68b7bf507bfe5c5446e1dc9d # v2.0.1 | |
| - name: Log in to GHCR | |
| uses: ./.github/actions/ghcr-login | |
| - name: Tag release | |
| run: | | |
| SRC="${{ env.REGISTRY }}/${{ github.repository }}:${{ github.sha }}" | |
| DST="${{ env.REGISTRY }}/${{ github.repository }}:${{ needs.detect.outputs.app_version }}" | |
| LATEST="${{ env.REGISTRY }}/${{ github.repository }}:latest" | |
| oras copy "$SRC" "$DST" | |
| oras copy "$SRC" "$LATEST" | |
| - name: Setup Cosign | |
| uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 | |
| - name: Sign the container image | |
| run: | | |
| IMAGE="${{ env.REGISTRY }}/${{ github.repository }}:${{ needs.detect.outputs.app_version }}" | |
| DIGEST=$(oras resolve "$IMAGE") | |
| cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository }}@${DIGEST}" | |
| - name: Generate SBOM | |
| uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0 | |
| with: | |
| image: ${{ env.REGISTRY }}/${{ github.repository }}:${{ needs.detect.outputs.app_version }} | |
| format: spdx-json | |
| output-file: sbom.spdx.json | |
| upload-artifact: false | |
| upload-release-assets: false | |
| - name: Attest SBOM | |
| run: | | |
| IMAGE="${{ env.REGISTRY }}/${{ github.repository }}:${{ needs.detect.outputs.app_version }}" | |
| DIGEST=$(oras resolve "$IMAGE") | |
| cosign attest --yes --type spdxjson --predicate sbom.spdx.json "${{ env.REGISTRY }}/${{ github.repository }}@${DIGEST}" | |
| - name: Get release notes | |
| run: make release-notes TAG="${{ needs.detect.outputs.app_version }}" > .release_notes | |
| - name: Create release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "${{ needs.detect.outputs.app_version }}" \ | |
| --notes-file .release_notes \ | |
| --title "${{ needs.detect.outputs.app_version }}" \ | |
| --target ${{ github.sha }} \ | |
| --draft |