|
1 |
| -name: Publish Docker image to Docker Hub and GitHub Container Registry |
| 1 | +name: Publish Docker Image to Registries |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | release:
|
5 | 5 | types:
|
6 | 6 | - published # Runs only when a GitHub Release is published
|
7 |
| - workflow_dispatch: # Allows manual execution |
| 7 | + workflow_dispatch: # Allows for manual execution |
8 | 8 |
|
9 | 9 | env:
|
10 | 10 | ALPINE_VERSION: "23-alpine"
|
|
47 | 47 | variant: [alpine, debian]
|
48 | 48 | runs-on: ubuntu-latest
|
49 | 49 | permissions:
|
| 50 | + actions: write |
50 | 51 | contents: write
|
51 | 52 | packages: write
|
52 | 53 | # This is used to complete the identity challenge with sigstore/fulcio when running outside of PRs.
|
@@ -109,35 +110,6 @@ jobs:
|
109 | 110 | type=semver,pattern={{major}},enable=${{ matrix.variant == 'debian' }}
|
110 | 111 | type=raw,value=latest,enable=${{ matrix.variant == 'debian' && github.ref == 'refs/heads/main' }}
|
111 | 112 |
|
112 |
| - - name: Save Version Output |
113 |
| - run: | |
114 |
| - echo "BUILD_FULL_VERSION=${{ steps.meta.outputs.version }}" >> versions.txt |
115 |
| - echo "BUILD_MAJOR_MINOR_VERSION=${{ steps.meta.outputs.major }}.${{ steps.meta.outputs.minor }}" >> versions.txt |
116 |
| - echo "BUILD_MAJOR_VERSION=${{ steps.meta.outputs.major }}" >> versions.txt |
117 |
| -
|
118 |
| - - name: Verify Saved Versions |
119 |
| - run: cat versions.txt |
120 |
| - |
121 |
| - - name: Delete Existing Version Artifact (If Exists) |
122 |
| - run: | |
123 |
| - ARTIFACT_ID=$(gh api repos/${{ github.repository }}/actions/artifacts --jq '.artifacts[] | select(.name=="version-metadata") | .id' || echo "not_found") |
124 |
| - if [[ "$ARTIFACT_ID" != "not_found" ]]; then |
125 |
| - echo "Deleting existing artifact with ID: $ARTIFACT_ID" |
126 |
| - gh api -X DELETE repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID |
127 |
| - else |
128 |
| - echo "No existing artifact found. Skipping deletion." |
129 |
| - fi |
130 |
| - env: |
131 |
| - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
132 |
| - |
133 |
| - - name: Upload Version File |
134 |
| - # Always run this on the first successful job only |
135 |
| - if: github.run_attempt == 1 |
136 |
| - |
137 |
| - with: |
138 |
| - name: version-metadata |
139 |
| - path: versions.txt |
140 |
| - |
141 | 113 | - name: Set up QEMU
|
142 | 114 |
|
143 | 115 |
|
@@ -166,3 +138,20 @@ jobs:
|
166 | 138 | DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
167 | 139 | run: |
|
168 | 140 | echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|
| 141 | +
|
| 142 | + # For use in other workflows (e.g. 'generate-readme', etc.) |
| 143 | + - name: Save Build Version to Repository Variable |
| 144 | + if: matrix.variant == 'debian' && github.run_attempt == 1 |
| 145 | + run: | |
| 146 | + VERSION="${{ steps.meta.outputs.version }}" |
| 147 | +
|
| 148 | + # Check if VERSION is empty and set a fallback value |
| 149 | + if [ -z "$VERSION" ]; then |
| 150 | + # Fetch the latest release using Git |
| 151 | + git tag -l --sort=-v:refname | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 |
| 152 | + fi |
| 153 | +
|
| 154 | + echo "Setting BUILD_VERSION to $VERSION" |
| 155 | + gh variable set BUILD_VERSION --body "$VERSION" |
| 156 | + env: |
| 157 | + GH_TOKEN: ${{ secrets.GH_PAT }} # Needs to be PAT w/ Read access to metadata and secrets & Read and Write access to actions, actions variables, and code |
0 commit comments