@@ -3,41 +3,128 @@ name: Release
33on :
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
1013permissions :
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
1322jobs :
14- goreleaser :
15- runs-on : ubuntu-latest
23+ build :
24+ runs-on : amd-runner-2204
25+ strategy :
26+ fail-fast : false
27+ matrix :
28+ platform :
29+ - linux/amd64
30+ - linux/arm64
31+ outputs :
32+ IMAGE_NAME : ${{ steps.image_builder.outputs.IMAGE }}
33+ TAGS : ${{ steps.meta.outputs.tags }}
34+ VERSION : ${{ steps.meta.outputs.version }}
1635 steps :
36+ - name : Prepare
37+ run : |
38+ platform=${{ matrix.platform }}
39+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
40+
1741 - name : Checkout
1842 uses : actions/checkout@v4
19- with :
20- fetch-depth : 0
2143
22- - name : Set up Go
23- uses : actions/setup-go@v5
44+ - name : Docker meta
45+ id : meta
46+ uses : docker/metadata-action@v5
2447 with :
25- go-version : 1.21
48+ images : ${{ env.REGISTRY_IMAGE }}
49+ tags : |
50+ type=ref,event=branch
51+ type=ref,event=pr
52+ type=semver,pattern={{version}}
53+ type=semver,pattern={{major}}.{{minor}}
54+
55+ - name : Image name builder
56+ id : image_builder
57+ run : |
58+ IMAGE=$(jq -ecr '.tags | map(select(match("${{ env.REGEX_IMAGE }}", "i"))) | first| sub(":.*$";"")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
59+ echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
2660
2761 - name : Set up QEMU
2862 uses : docker/setup-qemu-action@v3
2963
30- - name : Login to DockerHub
64+ - name : Set up Docker Buildx
65+ uses : docker/setup-buildx-action@v3
66+
67+ - name : Login to Docker Hub
3168 uses : docker/login-action@v3
3269 with :
33- username : ${{ secrets.DOCKERHUB_USERNAME }}
34- password : ${{ secrets.DOCKERHUB_TOKEN }}
70+ registry : ${{ env.REGISTRY }}
71+ username : ${{ github.actor }}
72+ password : ${{ secrets.GITHUB_TOKEN }}
73+
74+ - name : Build and push by digest
75+ id : build
76+ uses : docker/build-push-action@v6
77+ with :
78+ context : .
79+ push : false
80+ platforms : ${{ matrix.platform }}
81+ labels : ${{ steps.meta.outputs.labels }}
82+ cache-from : type=gha
83+ cache-to : type=gha,mode=max
84+ outputs : type=image,name=${{ steps.image_builder.outputs.IMAGE }},push-by-digest=true,push=true
85+
86+ - name : Export digest
87+ run : |
88+ mkdir -p /tmp/digests
89+ digest="${{ steps.build.outputs.digest }}"
90+ touch "/tmp/digests/${digest#sha256:}"
91+
92+ - name : Upload digest
93+ uses : actions/upload-artifact@v4
94+ with :
95+ name : digests-${{ env.PLATFORM_PAIR }}
96+ path : /tmp/digests/*
97+ if-no-files-found : error
98+ retention-days : 1
3599
36- - name : Run GoReleaser
37- uses : goreleaser/goreleaser-action@v5
100+ merge :
101+ runs-on : arm-runner-2204
102+ needs :
103+ - build
104+ steps :
105+ - name : Download digests
106+ uses : actions/download-artifact@v4
38107 with :
39- distribution : goreleaser
40- version : latest
41- args : release --clean --config=.goreleaser-cdk.yaml
42- env :
43- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
108+ path : /tmp/digests
109+ pattern : digests-*
110+ merge-multiple : true
111+
112+ - name : Set up Docker Buildx
113+ uses : docker/setup-buildx-action@v3
114+
115+ - name : Login to Docker Hub
116+ uses : docker/login-action@v3
117+ with :
118+ registry : ${{ env.REGISTRY }}
119+ username : ${{ github.actor }}
120+ password : ${{ secrets.GITHUB_TOKEN }}
121+
122+ - name : Create manifest list and push
123+ working-directory : /tmp/digests
124+ run : |
125+ docker buildx imagetools create $(jq -cRr 'split("\n") | map(gsub("\\s+";"")) | map("-t "+ .) | join(" ")' <<< '${{ needs.build.outputs.TAGS }}') \
126+ $(printf '${{ needs.build.outputs.IMAGE_NAME }}@sha256:%s ' *)
127+
128+ - name : Inspect image
129+ run : |
130+ docker buildx imagetools inspect ${{ needs.build.outputs.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}
0 commit comments