Update actions/attest-build-provenance action to v2 #44
This file contains 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 | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
pull_request: | |
branches: | |
- main | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
- name: Set up sqlc | |
uses: sqlc-dev/setup-sqlc@v4 | |
with: | |
sqlc-version: 1.27.0 | |
- name: Generate repository | |
run: sqlc generate | |
- name: Check code format | |
run: test -z "$(gofmt -l .)" | |
- name: Run go vet | |
run: go vet ./... | |
build: | |
runs-on: ubuntu-latest | |
needs: check | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
- name: Set up sqlc | |
uses: sqlc-dev/setup-sqlc@v4 | |
with: | |
sqlc-version: 1.27.0 | |
- name: Generate repository | |
run: sqlc generate | |
- name: Build binary | |
run: go build | |
- name: Upload binary artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: knight | |
path: knight | |
test: | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
- name: Set up sqlc | |
uses: sqlc-dev/setup-sqlc@v4 | |
with: | |
sqlc-version: 1.27.0 | |
- name: Generate repository | |
run: sqlc generate | |
- name: Run tests | |
run: go test -coverprofile cover.out ./... | |
env: | |
DB_NAME: ":memory:" | |
- name: Upload coverage artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: cover.out | |
publish: | |
runs-on: ubuntu-latest | |
needs: test | |
if: startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login to Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Generate artifact attestation | |
uses: actions/attest-build-provenance@v2 | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
subject-digest: ${{ steps.push.outputs.digest }} | |
push-to-registry: true |