Skip to content

Commit 56353a0

Browse files
authored
chore: update docker publish CI action (#86)
Always run workflow on main and make workflow dispatch simpler.
1 parent f534f4c commit 56353a0

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

.github/workflows/dockerimage.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ name: Docker Image CI
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
ref:
7-
description: 'GitHub ref to checkout'
8-
required: true
9-
default: main
10-
tag:
11-
description: 'Docker tag to push (do NOT use "latest" or version numbers)'
12-
required: true
13-
default: 'HEAD'
145
push:
6+
branches:
7+
- main
158
tags:
169
- v*
1710

1811
env:
12+
DOCKER_BUILDKIT: 1
1913
REGISTRY: ghcr.io
2014
IMAGE_NAME: ${{ github.repository }}
2115

@@ -24,23 +18,20 @@ jobs:
2418
name: Build and push image to registry
2519
runs-on: ubuntu-latest
2620
steps:
27-
- uses: actions/checkout@v2
28-
with:
29-
ref: ${{ github.event.inputs.ref }}
30-
21+
- uses: actions/checkout@v4
3122
- name: Build image
3223
run: docker build . --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
3324

3425
- name: Log in to registry
3526
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
3627

3728
- name: Push image (manual)
38-
if: github.event_name == 'workflow_dispatch'
29+
if: startsWith(github.ref, 'refs/heads/') || github.event_name == 'workflow_dispatch'
3930
run: |
4031
IMAGE_ID="${REGISTRY}/${IMAGE_NAME}"
4132
# Change all uppercase to lowercase
4233
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
43-
TAG=${{ github.event.inputs.tag }}
34+
TAG=${{ github.ref_name }}
4435
4536
echo IMAGE_ID=$IMAGE_ID
4637
echo TAG=$TAG
@@ -49,7 +40,7 @@ jobs:
4940
docker push $IMAGE_ID:$TAG
5041
5142
- name: Push image (release)
52-
if: github.event_name != 'workflow_dispatch'
43+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
5344
run: |
5445
IMAGE_ID="${REGISTRY}/${IMAGE_NAME}"
5546
# Change all uppercase to lowercase
@@ -58,7 +49,7 @@ jobs:
5849
# Strip git ref prefix from version
5950
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
6051
# Strip "v" prefix from tag name
61-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
52+
VERSION=$(echo $VERSION | sed -e 's/^v//')
6253
VERSION_START=${VERSION%%.*}
6354
6455
echo IMAGE_ID=$IMAGE_ID
@@ -67,9 +58,9 @@ jobs:
6758
# Push latest
6859
docker tag $IMAGE_NAME $IMAGE_ID:latest
6960
docker push $IMAGE_ID:latest
70-
# Push full version
61+
# Push full version, (e.g., 5.0.2)
7162
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
7263
docker push $IMAGE_ID:$VERSION
73-
# Push short version
64+
# Push short version (e.g. 5)
7465
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_START
7566
docker push $IMAGE_ID:$VERSION_START

0 commit comments

Comments
 (0)