Skip to content

Commit 0c0dba3

Browse files
committed
Add publish workflow that publishes a new release to ghcr.io
1 parent 0497016 commit 0c0dba3

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/publish.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish to ghcr.io
2+
3+
env:
4+
IMAGE_NAME: Dockge
5+
6+
on:
7+
release:
8+
types: [released]
9+
10+
jobs:
11+
build-and-publish-image:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: 22
21+
22+
- uses: pnpm/action-setup@v2
23+
name: Install pnpm
24+
with:
25+
version: 8
26+
run_install: false
27+
28+
- name: Get pnpm store directory
29+
shell: bash
30+
run: |
31+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
32+
33+
- uses: actions/cache@v3
34+
name: Setup pnpm cache
35+
with:
36+
path: ${{ env.STORE_PATH }}
37+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38+
restore-keys: |
39+
${{ runner.os }}-pnpm-store-
40+
41+
- name: Install dependencies
42+
run: pnpm install
43+
44+
- name: Lint
45+
run: pnpm run lint
46+
47+
- name: Check Typescript
48+
run: pnpm run check-ts
49+
50+
- name: Build Docker image
51+
run: docker build . --file docker/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
52+
53+
- name: Log in to registry
54+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
55+
56+
- name: Push image
57+
run: |
58+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
59+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
60+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
61+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
62+
[ "$VERSION" == "main" ] && VERSION=latest
63+
echo IMAGE_ID=$IMAGE_ID
64+
echo VERSION=$VERSION
65+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
66+
docker push $IMAGE_ID:$VERSION
67+

0 commit comments

Comments
 (0)