Skip to content

Commit 00ce700

Browse files
committed
Redo release workflow
1 parent 4f05b73 commit 00ce700

File tree

1 file changed

+52
-31
lines changed

1 file changed

+52
-31
lines changed

.github/workflows/release.yml

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
name: Release
2-
# Controls when the workflow will run
1+
name: Create and publish a Docker image
2+
3+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
34
on:
4-
release:
5-
types:
6-
- published
5+
pull_request:
6+
branches: main
7+
push:
8+
branches: main
9+
tags: v.*
10+
11+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
12+
env:
13+
REGISTRY: ghcr.io
714

15+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
816
jobs:
9-
buildpush:
17+
build-and-push-image:
1018
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
1120
permissions:
21+
id-token: write
1222
contents: read
1323
packages: write
24+
attestations: write
25+
1426
steps:
15-
- # Get the repository's code
16-
name: Checkout
17-
uses: actions/checkout@v2
27+
- name: Set image name
28+
run: |
29+
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}"
30+
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
1834
- # https://github.com/vegardit/docker-gitea-act-runner/issues/23
1935
name: Fix docker sock permissions
2036
run: sudo chmod 666 /var/run/docker.sock
@@ -25,27 +41,20 @@ jobs:
2541
name: Set up Docker Buildx
2642
id: buildx
2743
uses: docker/setup-buildx-action@v1
28-
- # https://github.com/docker/login-action
29-
name: Log in to the Container registry
30-
uses: docker/login-action@v2
44+
45+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
46+
- name: Log in to the Container registry
47+
uses: docker/login-action@v3
3148
with:
32-
# Maybe there is a default env var for this?
33-
registry: git.maronato.dev
34-
username: ${{ github.repository_owner }}}
35-
# Ideally, we should only need to set "permissions: package: write", but
36-
# Gitea is having issues with that. For now, this is a manually created
37-
# token available user-wise, with the "package:write" permission.
38-
password: ${{ secrets.PACKAGE_WRITE_TOKEN }}
39-
- # https://github.com/docker/metadata-action
40-
# Generate tags and labels for the image
41-
# according to the commit and the branch
42-
name: Docker meta
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
53+
- name: Extract metadata (tags, labels) for Docker
4354
id: meta
44-
uses: docker/metadata-action@v4
55+
uses: docker/metadata-action@v5
4556
with:
46-
# The container image name needs the custom registry in it.
47-
# Maybe there is a default env var for this?
48-
images: git.maronato.dev/${{ github.repository }}
57+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4958
tags: |
5059
type=ref,event=branch
5160
type=ref,event=pr
@@ -62,19 +71,31 @@ jobs:
6271
key: ${{ runner.os }}-buildx-${{ github.sha }}
6372
restore-keys: |
6473
${{ runner.os }}-buildx-
65-
- # https://github.com/docker/build-push-action
66-
name: Build and push
67-
uses: docker/build-push-action@v2
74+
75+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
76+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
77+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
78+
- name: Build and push Docker image
79+
id: push
80+
uses: docker/build-push-action@v6
6881
with:
6982
context: .
7083
build-args: |
7184
VERSION=${{ steps.meta.outputs.version }}
7285
platforms: linux/amd64,linux/arm64
73-
push: ${{ github.event_name != 'pull_request' }}
86+
push: true
7487
tags: ${{ steps.meta.outputs.tags }}
7588
labels: ${{ steps.meta.outputs.labels }}
7689
cache-from: type=local,src=/tmp/.buildx-cache
7790
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
91+
92+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
93+
- name: Generate artifact attestation
94+
uses: actions/attest-build-provenance@v1
95+
with:
96+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
97+
subject-digest: ${{ steps.push.outputs.digest }}
98+
push-to-registry: true
7899
- # Temp fix
79100
# https://github.com/docker/build-push-action/issues/252
80101
# https://github.com/moby/buildkit/issues/1896

0 commit comments

Comments
 (0)