Skip to content

Commit f4cd9d7

Browse files
committed
Redo release workflow
1 parent 4f05b73 commit f4cd9d7

File tree

2 files changed

+120
-77
lines changed

2 files changed

+120
-77
lines changed

.github/workflows/docker.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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`.
4+
on:
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
14+
15+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
16+
jobs:
17+
build-and-push-image:
18+
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
20+
permissions:
21+
id-token: write
22+
contents: read
23+
packages: write
24+
attestations: write
25+
26+
steps:
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+
34+
- # https://github.com/vegardit/docker-gitea-act-runner/issues/23
35+
name: Fix docker sock permissions
36+
run: sudo chmod 666 /var/run/docker.sock
37+
- # https://github.com/docker/setup-qemu-action
38+
name: Set up QEMU
39+
uses: docker/setup-qemu-action@v1
40+
- # https://github.com/docker/setup-buildx-action
41+
name: Set up Docker Buildx
42+
id: buildx
43+
uses: docker/setup-buildx-action@v1
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
48+
with:
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
54+
id: meta
55+
uses: docker/metadata-action@v5
56+
with:
57+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
tags: |
59+
type=ref,event=branch
60+
type=ref,event=pr
61+
type=semver,pattern={{version}}
62+
type=semver,pattern={{major}}.{{minor}}
63+
- # httos://github.com/actions/cache
64+
name: Cache Docker layers
65+
uses: actions/cache@v3
66+
with:
67+
path: |
68+
/go/pkg/mod/
69+
/tmp/.go-build-cache
70+
/tmp/.buildx-cache
71+
key: ${{ runner.os }}-buildx-${{ github.sha }}
72+
restore-keys: |
73+
${{ runner.os }}-buildx-
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
81+
with:
82+
context: .
83+
build-args: |
84+
VERSION=${{ steps.meta.outputs.version }}
85+
platforms: linux/amd64,linux/arm64
86+
push: true
87+
tags: ${{ steps.meta.outputs.tags }}
88+
labels: ${{ steps.meta.outputs.labels }}
89+
cache-from: type=local,src=/tmp/.buildx-cache
90+
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
99+
- # Temp fix
100+
# https://github.com/docker/build-push-action/issues/252
101+
# https://github.com/moby/buildkit/issues/1896
102+
name: Move cache
103+
run: |
104+
rm -rf /tmp/.buildx-cache
105+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.github/workflows/release.yml

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,22 @@
11
name: Release
2-
# Controls when the workflow will run
2+
33
on:
4-
release:
5-
types:
6-
- published
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
type: string
78

89
jobs:
9-
buildpush:
10+
release:
1011
runs-on: ubuntu-latest
11-
permissions:
12-
contents: read
13-
packages: write
1412
steps:
15-
- # Get the repository's code
16-
name: Checkout
17-
uses: actions/checkout@v2
18-
- # https://github.com/vegardit/docker-gitea-act-runner/issues/23
19-
name: Fix docker sock permissions
20-
run: sudo chmod 666 /var/run/docker.sock
21-
- # https://github.com/docker/setup-qemu-action
22-
name: Set up QEMU
23-
uses: docker/setup-qemu-action@v1
24-
- # https://github.com/docker/setup-buildx-action
25-
name: Set up Docker Buildx
26-
id: buildx
27-
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
31-
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
43-
id: meta
44-
uses: docker/metadata-action@v4
45-
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 }}
49-
tags: |
50-
type=ref,event=branch
51-
type=ref,event=pr
52-
type=semver,pattern={{version}}
53-
type=semver,pattern={{major}}.{{minor}}
54-
- # httos://github.com/actions/cache
55-
name: Cache Docker layers
56-
uses: actions/cache@v3
57-
with:
58-
path: |
59-
/go/pkg/mod/
60-
/tmp/.go-build-cache
61-
/tmp/.buildx-cache
62-
key: ${{ runner.os }}-buildx-${{ github.sha }}
63-
restore-keys: |
64-
${{ runner.os }}-buildx-
65-
- # https://github.com/docker/build-push-action
66-
name: Build and push
67-
uses: docker/build-push-action@v2
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Create Release
17+
uses: marvinpinto/action-automatic-releases@latest
6818
with:
69-
context: .
70-
build-args: |
71-
VERSION=${{ steps.meta.outputs.version }}
72-
platforms: linux/amd64,linux/arm64
73-
push: ${{ github.event_name != 'pull_request' }}
74-
tags: ${{ steps.meta.outputs.tags }}
75-
labels: ${{ steps.meta.outputs.labels }}
76-
cache-from: type=local,src=/tmp/.buildx-cache
77-
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
78-
- # Temp fix
79-
# https://github.com/docker/build-push-action/issues/252
80-
# https://github.com/moby/buildkit/issues/1896
81-
name: Move cache
82-
run: |
83-
rm -rf /tmp/.buildx-cache
84-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
19+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
20+
automatic_release_tag: "${{inputs.version}}"
21+
prerelease: false
22+
title: "Release ${{inputs.version}}"

0 commit comments

Comments
 (0)