Skip to content

Commit dd175fc

Browse files
Merge pull request #170 from 0xPolygon/arpit/releaser
feat: modify releaser
2 parents 4c93103 + 68359e9 commit dd175fc

3 files changed

Lines changed: 107 additions & 125 deletions

File tree

.github/workflows/release.yml

Lines changed: 107 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,129 @@ name: Release
33
on:
44
push:
55
tags:
6-
# run only against tags that follow semver (https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string)
7-
- 'v[0-9]+.[0-9]+.[0-9]+*'
8-
- 'v[0-9]+.[0-9]+.[0-9]+*.[0-9]+'
6+
- 'v*.*.*'
7+
- 'v*.*.*-*'
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
912

1013
permissions:
1114
contents: write
15+
packages: write
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
20+
REGEX_IMAGE: ${{ github.repository }}:\\d+.\\d+.\\d+
1221

1322
jobs:
14-
goreleaser:
23+
build:
1524
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
platform:
29+
- linux/amd64
30+
- linux/arm64
31+
32+
outputs:
33+
IMAGE_NAME: ${{ steps.image_builder.outputs.IMAGE }}
34+
TAGS: ${{ steps.meta.outputs.tags }}
35+
VERSION: ${{ steps.meta.outputs.version }}
1636
steps:
37+
- name: Prepare
38+
run: |
39+
platform=${{ matrix.platform }}
40+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
41+
1742
- name: Checkout
1843
uses: actions/checkout@v4
19-
with:
20-
fetch-depth: 0
2144

22-
- name: Set up Go
23-
uses: actions/setup-go@v5
45+
- name: Docker meta
46+
id: meta
47+
uses: docker/metadata-action@v5
2448
with:
25-
go-version: 1.23.7
49+
images: ${{ env.REGISTRY_IMAGE }}
50+
tags: |
51+
type=ref,event=branch
52+
type=ref,event=pr
53+
type=semver,pattern={{version}}
54+
type=semver,pattern={{major}}.{{minor}}
55+
56+
- name: Image name builder
57+
id: image_builder
58+
run: |
59+
IMAGE=$(jq -ecr '.tags | map(select(match("${{ env.REGEX_IMAGE }}", "i"))) | first| sub(":.*$";"")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
60+
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
2661
2762
- name: Set up QEMU
2863
uses: docker/setup-qemu-action@v3
2964

30-
- name: Login to DockerHub
65+
- name: Set up Docker Buildx
66+
uses: docker/setup-buildx-action@v3
67+
68+
- name: Login to Docker Hub
3169
uses: docker/login-action@v3
3270
with:
33-
username: ${{ secrets.DOCKERHUB_USERNAME }}
34-
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
registry: ${{ env.REGISTRY }}
72+
username: ${{ github.actor }}
73+
password: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Build and push by digest
76+
id: build
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: .
80+
push: false
81+
platforms: ${{ matrix.platform }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max
85+
outputs: type=image,name=${{ steps.image_builder.outputs.IMAGE }},push-by-digest=true,push=true
86+
87+
- name: Export digest
88+
run: |
89+
mkdir -p /tmp/digests
90+
digest="${{ steps.build.outputs.digest }}"
91+
touch "/tmp/digests/${digest#sha256:}"
92+
93+
- name: Upload digest
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: digests-${{ env.PLATFORM_PAIR }}
97+
path: /tmp/digests/*
98+
if-no-files-found: error
99+
retention-days: 1
100+
101+
merge:
102+
runs-on: ubuntu-latest
103+
needs:
104+
- build
105+
steps:
106+
- name: Download digests
107+
uses: actions/download-artifact@v4
108+
with:
109+
path: /tmp/digests
110+
pattern: digests-*
111+
merge-multiple: true
112+
113+
- name: Set up Docker Buildx
114+
uses: docker/setup-buildx-action@v3
35115

36-
- name: Run GoReleaser
37-
uses: goreleaser/goreleaser-action@v5
116+
- name: Login to Docker Hub
117+
uses: docker/login-action@v3
38118
with:
39-
distribution: goreleaser
40-
version: latest
41-
args: release --clean --config=.goreleaser-cdk.yaml
42-
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
registry: ${{ env.REGISTRY }}
120+
username: ${{ github.actor }}
121+
password: ${{ secrets.GITHUB_TOKEN }}
122+
123+
- name: Create manifest list and push
124+
working-directory: /tmp/digests
125+
run: |
126+
docker buildx imagetools create $(jq -cRr 'split("\n") | map(gsub("\\s+";"")) | map("-t "+ .) | join(" ")' <<< '${{ needs.build.outputs.TAGS }}') \
127+
$(printf '${{ needs.build.outputs.IMAGE_NAME }}@sha256:%s ' *)
128+
129+
- name: Inspect image
130+
run: |
131+
docker buildx imagetools inspect ${{ needs.build.outputs.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}

.goreleaser-cdk.yaml

Lines changed: 0 additions & 84 deletions
This file was deleted.

.goreleaser.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)