Move anchore scan #119
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: Delivery | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| packages: write | |
| security-events: write | |
| jobs: | |
| config: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| profile: ${{ steps.resolve.outputs.profile }} | |
| version: ${{ steps.resolve.outputs.version }} | |
| is_release: ${{ steps.resolve.outputs.is_release }} | |
| steps: | |
| - name: Resolve build config | |
| id: resolve | |
| run: | | |
| MSG="${{ github.event.head_commit.message }}" | |
| if [[ "$MSG" =~ ^chore:\ release\ (v[0-9]+\.[0-9]+\.[0-9]+) ]]; then | |
| echo "is_release=true" >> "$GITHUB_OUTPUT" | |
| echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" | |
| echo "profile=release" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_release=false" >> "$GITHUB_OUTPUT" | |
| echo "version=" >> "$GITHUB_OUTPUT" | |
| echo "profile=edge" >> "$GITHUB_OUTPUT" | |
| fi | |
| build-amd64: | |
| runs-on: ubuntu-latest | |
| needs: [config] | |
| outputs: | |
| digest: ${{ steps.build.outputs.digest }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push (linux/amd64) | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/amd64 | |
| push: false | |
| provenance: false | |
| tags: ghcr.io/${{ github.repository }}:build-${{ github.run_id }}-amd64 | |
| build-args: CARGO_PROFILE=${{ needs.config.outputs.profile }} | |
| cache-from: type=gha,scope=build-amd64 | |
| cache-to: type=gha,mode=max,scope=build-amd64 | |
| build-arm64: | |
| runs-on: ubuntu-24.04-arm | |
| needs: [config] | |
| outputs: | |
| digest: ${{ steps.build.outputs.digest }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push (linux/arm64) | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/arm64 | |
| push: false | |
| provenance: false | |
| tags: ghcr.io/${{ github.repository }}:build-${{ github.run_id }}-arm64 | |
| build-args: CARGO_PROFILE=${{ needs.config.outputs.profile }} | |
| cache-from: type=gha,scope=build-arm64 | |
| cache-to: type=gha,mode=max,scope=build-arm64 | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: [config, build-amd64, build-arm64] | |
| steps: | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}},value=${{ needs.config.outputs.version }},enable=${{ needs.config.outputs.is_release == 'true' }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ needs.config.outputs.version }},enable=${{ needs.config.outputs.is_release == 'true' }} | |
| type=edge,branch=main,enable=${{ github.event_name == 'push' && needs.config.outputs.is_release != 'true' }} | |
| type=ref,event=pr | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Combine the two platform-specific images into a single multi-arch manifest. | |
| # DOCKER_METADATA_OUTPUT_JSON is set automatically by docker/metadata-action. | |
| - name: Create and push multi-arch manifest | |
| run: | | |
| docker buildx imagetools create \ | |
| $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| "ghcr.io/${{ github.repository }}@${{ needs.build-amd64.outputs.digest }}" \ | |
| "ghcr.io/${{ github.repository }}@${{ needs.build-arm64.outputs.digest }}" | |
| - name: Scan image | |
| uses: anchore/scan-action@7037fa011853d5a11690026fb85feee79f4c946c # v7.3.2 | |
| id: scan | |
| with: | |
| image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} | |
| only-fixed: true | |
| fail-build: true | |
| severity-cutoff: critical | |
| output-format: sarif | |
| - name: Upload Anchore scan SARIF report | |
| uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4 | |
| if: ${{ !cancelled() }} | |
| with: | |
| sarif_file: ${{ steps.scan.outputs.sarif }} |