77
88jobs :
99 goreleaser :
10- name : Release pre-build binary
10+ name : Release pre-build binary and docker images by goreleaser
1111 runs-on : ubuntu-latest
1212 permissions :
1313 contents : write
14+ packages : write
15+ env :
16+ REGISTRY : ghcr.io
1417 steps :
1518 - name : Checkout code
1619 uses : actions/checkout@v4.2.2
@@ -20,39 +23,19 @@ jobs:
2023 uses : actions/setup-go@v5.3.0
2124 with :
2225 go-version-file : ./go.mod
26+ - name : Log in to the Container registry
27+ uses : docker/login-action@v3.4.0
28+ with :
29+ registry : ${{ env.REGISTRY }}
30+ username : ${{ github.actor }}
31+ password : ${{ secrets.GITHUB_TOKEN }}
32+ - name : Set up QEMU
33+ uses : docker/setup-qemu-action@v3.6.0
34+ - name : Set up Docker Buildx
35+ uses : docker/setup-buildx-action@v3.10.0
2336 - name : Run GoReleaser
2437 uses : goreleaser/goreleaser-action@v6.2.1
2538 with :
2639 args : release --clean
2740 env :
2841 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
29-
30- # https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-a-registry-using-a-personal-access-token
31- build-and-push-ghcr :
32- name : Build and Push GHCR
33- runs-on : ubuntu-latest
34- permissions :
35- contents : read
36- packages : write
37- env :
38- IMAGE_NAME : wrench
39- steps :
40- - name : Checkout code
41- uses : actions/checkout@v4.2.2
42- with :
43- fetch-depth : 0
44- - name : Build image
45- run : docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
46- - name : Log in to registry
47- run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
48- - name : Push image
49- run : |
50- IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
51- IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
52- VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
53- [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
54- [ "$VERSION" == "main" ] && VERSION=latest
55- echo IMAGE_ID=$IMAGE_ID
56- echo VERSION=$VERSION
57- docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
58- docker push $IMAGE_ID:$VERSION
0 commit comments