|
6 | 6 | tags: |
7 | 7 | - "v*.*" |
8 | 8 |
|
| 9 | + workflow_dispatch: |
| 10 | + |
9 | 11 | jobs: |
10 | 12 | build-and-push: |
11 | 13 | runs-on: ubuntu-latest |
12 | 14 | permissions: |
13 | 15 | contents: read |
14 | 16 | packages: write |
15 | | - security-events: write |
16 | 17 |
|
17 | 18 | steps: |
18 | 19 | - name: Checkout |
19 | 20 | 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" |
20 | 38 |
|
21 | 39 | - name: Set up QEMU |
22 | 40 | uses: docker/setup-qemu-action@v3 |
|
30 | 48 | with: |
31 | 49 | images: ghcr.io/${{ github.repository }} |
32 | 50 | 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 }} |
36 | 54 | type=raw,value=latest |
37 | 55 |
|
38 | 56 | - name: Login to GHCR |
|
42 | 60 | username: ${{ github.actor }} |
43 | 61 | password: ${{ secrets.GITHUB_TOKEN }} |
44 | 62 |
|
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 | | - |
72 | 63 | - name: Build and push |
73 | 64 | uses: docker/build-push-action@v6 |
74 | 65 | env: |
|
0 commit comments