Skip to content

Commit 28a72a3

Browse files
committed
fix: README generation
Changed from trying to use artifacts and the GHA workflow failing to now using a simple `BUILD_VERSION` repository variable and automatically updating that when the `build-and-push-to-registries` workflow succeeds. Other changes include: * Added `workflow_run` trigger to `generate-readme.yml` so when that workflow recognizes the “Publish Docker Image to Registries” workflow runs and succeeds, it will automatically run the `generate-readme.yml` workflow (since a new Docker release will require Docker image variants table in README.md to have versioning updated) * Generate major and major-minor versions from the `BUILD_VERSION` repository variable (more efficient than storing three separate variables from the `build-and-push-to-registries` workflow job)
1 parent dae3346 commit 28a72a3

File tree

3 files changed

+44
-46
lines changed

3 files changed

+44
-46
lines changed

.github/workflows/generate-readme.yml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ on:
1111
- main
1212
paths:
1313
- 'README.template.md'
14-
workflow_dispatch: # Allows manual execution
14+
workflow_dispatch: # Allows for manual execution
15+
workflow_run: # Triggers this workflow to run when it recognizes 'publish-images' workflow has ran and successfully completed
16+
workflows: ["Publish Docker Image to Registries"]
17+
types:
18+
- completed
1519

1620
permissions:
1721
contents: write # Explicitly allow pushing changes
@@ -41,28 +45,33 @@ jobs:
4145
- name: Install Dependencies
4246
run: npm install mustache dotenv
4347

44-
- name: Download Version File
45-
uses: actions/[email protected]
46-
with:
47-
name: version-metadata
4848

49-
- name: Load Variables from File
49+
- name: Extract Major and Major-Minor Versions
5050
run: |
51-
while IFS='=' read -r key value; do
52-
echo "$key=$value" >> $GITHUB_ENV
53-
done < versions.txt
51+
VERSION="${{ vars.BUILD_VERSION }}"
52+
MAJOR=$(echo "$VERSION" | cut -d. -f1)
53+
MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2)
54+
55+
echo "Full version: $VERSION"
56+
echo "Major version: $MAJOR"
57+
echo "Major-Minor version: $MAJOR_MINOR"
58+
59+
# Export all as environment variables
60+
echo "LATEST_VERSION=$VERSION" >> $GITHUB_ENV
61+
echo "LATEST_MAJOR_VERSION=$MAJOR" >> $GITHUB_ENV
62+
echo "LATEST_MAJOR_MINOR_VERSION=$MAJOR_MINOR" >> $GITHUB_ENV
5463
5564
- name: Generate README.md
5665
env:
57-
BUILD_FULL_VERSION: ${{ env.BUILD_FULL_VERSION }} # e.g., 1.2.3
58-
BUILD_MAJOR_MINOR_VERSION: ${{ env.BUILD_MAJOR_MINOR_VERSION }} # e.g., 1.2
59-
BUILD_MAJOR_VERSION: ${{ env.BUILD_MAJOR_VERSION }} # e.g., 1
66+
BUILD_FULL_VERSION: ${{ env.LATEST_VERSION }} # e.g., 1.2.3
67+
BUILD_MAJOR_VERSION: ${{ env.LATEST_MAJOR_VERSION}} # e.g., 1
68+
BUILD_MAJOR_MINOR_VERSION: ${{ env.LATEST_MAJOR_MINOR_VERSION }} # e.g., 1.2
6069
run: node scripts/generate-readme.js
6170

6271
- name: Commit and Push Changes
6372
env:
64-
KENER_GH_PAT_TOKEN: ${{ secrets.KENER_GH_PAT_TOKEN }}
73+
GH_PAT: ${{ secrets.GH_PAT }}
6574
run: |
6675
git add README.md
6776
git commit -m "Auto-generate README.md with release versions" || echo "No changes to commit"
68-
git push https://x-access-token:${{ secrets.KENER_GH_PAT_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main
77+
git push https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ github.repository }}.git HEAD:main

.github/workflows/publish-images.yml

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Publish Docker image to Docker Hub and GitHub Container Registry
1+
name: Publish Docker Image to Registries
22

33
on:
44
release:
55
types:
66
- published # Runs only when a GitHub Release is published
7-
workflow_dispatch: # Allows manual execution
7+
workflow_dispatch: # Allows for manual execution
88

99
env:
1010
ALPINE_VERSION: "23-alpine"
@@ -47,6 +47,7 @@ jobs:
4747
variant: [alpine, debian]
4848
runs-on: ubuntu-latest
4949
permissions:
50+
actions: write
5051
contents: write
5152
packages: write
5253
# This is used to complete the identity challenge with sigstore/fulcio when running outside of PRs.
@@ -109,35 +110,6 @@ jobs:
109110
type=semver,pattern={{major}},enable=${{ matrix.variant == 'debian' }}
110111
type=raw,value=latest,enable=${{ matrix.variant == 'debian' && github.ref == 'refs/heads/main' }}
111112
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-
uses: actions/[email protected]
137-
with:
138-
name: version-metadata
139-
path: versions.txt
140-
141113
- name: Set up QEMU
142114
uses: docker/[email protected]
143115

@@ -166,3 +138,20 @@ jobs:
166138
DIGEST: ${{ steps.build-and-push.outputs.digest }}
167139
run: |
168140
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

scripts/generate-readme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const template = fs.readFileSync(templatePath, "utf-8");
1818
// Load environment variables and provide default values
1919
const data = {
2020
kener_full_version: process.env.BUILD_FULL_VERSION || "N/A",
21-
kener_major_minor_version: process.env.BUILD_MAJOR_MINOR_VERSION || "N/A",
2221
kener_major_version: process.env.BUILD_MAJOR_VERSION || "N/A",
22+
kener_major_minor_version: process.env.BUILD_MAJOR_MINOR_VERSION || "N/A",
2323
};
2424

2525
// Render README.md

0 commit comments

Comments
 (0)