Skip to content

Commit 9163374

Browse files
authored
add ghcr publish job in release workflow (#111)
1 parent 340a6f8 commit 9163374

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

.github/workflows/goreleaser.yaml

-30
This file was deleted.

.github/workflows/release.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
env:
9+
GO_VERSION: "~1.21"
10+
11+
jobs:
12+
goreleaser:
13+
name: Release pre-build binary
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Set up Go
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: ${{ env.GO_VERSION }}
24+
- name: Run GoReleaser
25+
uses: goreleaser/goreleaser-action@v4
26+
with:
27+
version: latest
28+
args: release --clean
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
32+
# 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
33+
build-and-push-ghcr:
34+
name: Build and Push GHCR
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: read
38+
packages: write
39+
env:
40+
IMAGE_NAME: wrench
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
- name: Build image
47+
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
48+
- name: Log in to registry
49+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
50+
- name: Push image
51+
run: |
52+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
53+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
54+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
55+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
56+
[ "$VERSION" == "main" ] && VERSION=latest
57+
echo IMAGE_ID=$IMAGE_ID
58+
echo VERSION=$VERSION
59+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
60+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)