Skip to content

Commit fdaf88f

Browse files
committed
Add workflow_dispatch support to docker-publish
1 parent f094c88 commit fdaf88f

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

.github/workflows/docker-publish.yml

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,35 @@ on:
66
tags:
77
- "v*.*"
88

9+
workflow_dispatch:
10+
911
jobs:
1012
build-and-push:
1113
runs-on: ubuntu-latest
1214
permissions:
1315
contents: read
1416
packages: write
15-
security-events: write
1617

1718
steps:
1819
- name: Checkout
1920
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Determine version
25+
id: version
26+
run: |
27+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
28+
TAG=$(git tag --sort=-version:refname --list 'v*.*' | head -1)
29+
if [ -z "$TAG" ]; then
30+
echo "::error::No version tag found"
31+
exit 1
32+
fi
33+
git checkout "$TAG"
34+
else
35+
TAG="${{ github.ref_name }}"
36+
fi
37+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
2038
2139
- name: Set up QEMU
2240
uses: docker/setup-qemu-action@v3
@@ -30,9 +48,9 @@ jobs:
3048
with:
3149
images: ghcr.io/${{ github.repository }}
3250
tags: |
33-
type=semver,pattern={{version}}
34-
type=semver,pattern={{major}}.{{minor}}
35-
type=semver,pattern={{major}}
51+
type=semver,pattern={{version}},value=${{ steps.version.outputs.tag }}
52+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.tag }}
53+
type=semver,pattern={{major}},value=${{ steps.version.outputs.tag }}
3654
type=raw,value=latest
3755
3856
- name: Login to GHCR
@@ -42,33 +60,6 @@ jobs:
4260
username: ${{ github.actor }}
4361
password: ${{ secrets.GITHUB_TOKEN }}
4462

45-
- name: Build image for scanning
46-
uses: docker/build-push-action@v6
47-
env:
48-
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
49-
DOCKER_BUILD_SUMMARY: false
50-
DOCKER_BUILD_RECORD_UPLOAD: false
51-
with:
52-
context: docker
53-
load: true
54-
tags: ghcr.io/${{ github.repository }}:scan
55-
56-
- name: Scan image with Trivy
57-
id: trivy-scan
58-
uses: aquasecurity/trivy-action@0.34.0
59-
with:
60-
image-ref: ghcr.io/${{ github.repository }}:scan
61-
ignore-unfixed: true
62-
scanners: vuln
63-
format: sarif
64-
output: trivy-results.sarif
65-
severity: CRITICAL,HIGH
66-
67-
- name: Upload Trivy scan results to GitHub Security
68-
uses: github/codeql-action/upload-sarif@v4
69-
with:
70-
sarif_file: trivy-results.sarif
71-
7263
- name: Build and push
7364
uses: docker/build-push-action@v6
7465
env:

.github/workflows/image-scan.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run-name: Image Security Scan (${{ github.event_name == 'schedule' && 'latest' |
33

44
on:
55
schedule:
6+
# Monthly on the 1st at 00:00 UTC
67
- cron: '0 0 1 * *'
78
workflow_dispatch:
89

0 commit comments

Comments
 (0)