Skip to content

Commit c1938f8

Browse files
committed
the show must go on
1 parent 0b4533e commit c1938f8

File tree

1 file changed

+20
-79
lines changed

1 file changed

+20
-79
lines changed

.github/workflows/_image-factory.yml

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
mapchete-hub-ref: ${{ steps.resolve.outputs.hub }}
3232
mapchete-hub-cli-ref: ${{ steps.resolve.outputs.cli }}
3333
calculated-tag: ${{ steps.version.outputs.tag }}
34+
mode: ${{ steps.version.outputs.mode }}
3435
steps:
3536
- uses: actions/checkout@v4
3637

@@ -65,38 +66,28 @@ jobs:
6566
env:
6667
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6768
run: |
68-
# Variables for clarity
6969
EVENT="${{ github.event_name }}"
7070
P_TYPE="${{ github.event.client_payload.type }}"
7171
P_TAG="${{ github.event.client_payload.image_tag }}"
7272
73-
# 1. FINAL RELEASE: Manual Git Tag on container-images repo
7473
if [[ "${{ github.ref_type }}" == "tag" ]]; then
7574
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
7675
echo "mode=release" >> $GITHUB_OUTPUT
77-
78-
# 2. ROLLING: Dispatch requested 'latest' or 'dev' specifically
7976
elif [[ "$EVENT" == "repository_dispatch" && "$P_TAG" =~ ^(latest|dev)$ ]]; then
8077
echo "tag=$P_TAG" >> $GITHUB_OUTPUT
8178
echo "mode=rolling" >> $GITHUB_OUTPUT
82-
83-
# 3. RELEASE CANDIDATE: Version Dispatch or Manual run (no tag provided)
8479
elif [[ "$P_TYPE" == "version" ]] || [[ "$EVENT" == "workflow_dispatch" && -z "${{ inputs.image-tag }}" ]]; then
8580
PREFIX="$(date +'%Y.%-m')."
8681
TAGS=$(gh api /orgs/mapchete/packages/container/${{ inputs.image-name }}/versions --jq '.[].metadata.container.tags[]' 2>/dev/null || echo "")
8782
LATEST_CTR=$(echo "$TAGS" | grep "^$PREFIX" | sed "s/$PREFIX//" | sort -nr | head -n1)
88-
89-
if [[ -z "$LATEST_CTR" ]]; then NEW_TAG="${PREFIX}0"; else NEW_TAG="${PREFIX}$((LATEST_CTR + 1))"; fi
83+
[[ -z "$LATEST_CTR" ]] && NEW_TAG="${PREFIX}0" || NEW_TAG="${PREFIX}$((LATEST_CTR + 1))"
9084
9185
echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
92-
echo "mode=rc" >> $GITHUB_OUTPUT
93-
86+
echo "mode=rc" >> $GITHUB_OUTPUT # This MUST be rc for version dispatches
9487
else
95-
# 4. DEFAULT/FALLBACK
9688
echo "tag=dev" >> $GITHUB_OUTPUT
9789
echo "mode=rolling" >> $GITHUB_OUTPUT
9890
fi
99-
10091
- name: Generate Summary
10192
if: always()
10293
run: |
@@ -168,67 +159,6 @@ jobs:
168159
MAPCHETE_HUB_REF=${{ needs.prepare.outputs.mapchete-hub-ref }}
169160
MAPCHETE_HUB_CLI_REF=${{ needs.prepare.outputs.mapchete-hub-cli-ref }}
170161
171-
- name: Image Fingerprint Check
172-
id: image-fingerprint-check
173-
run: |
174-
LOCAL_FINGERPRINT=$(docker run --rm --entrypoint /bin/sh local-test-image:latest -c "cat /app/uv_fingerprint" | tr -d '\r\n ')
175-
echo "fingerprint=$LOCAL_FINGERPRINT" >> $GITHUB_OUTPUT
176-
177-
# Force build on version dispatches to ensure release tag creation
178-
if [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.client_payload.type }}" == "version" ]]; then
179-
echo "changed=true" >> $GITHUB_OUTPUT
180-
else
181-
REMOTE_TAG="latest"
182-
[[ "${{ github.ref_name }}" != "main" ]] && REMOTE_TAG="dev"
183-
INSPECT_JSON=$(skopeo inspect docker://ghcr.io/mapchete/${{ inputs.image-name }}:$REMOTE_TAG 2>/dev/null || echo '{"Labels":{}}')
184-
REMOTE_FINGERPRINT=$(echo "$INSPECT_JSON" | jq -r '.Labels["org.mapchete.image_fingerprint"] // "none"' | tr -d '\r\n ')
185-
186-
if [[ "$LOCAL_FINGERPRINT" == "$REMOTE_FINGERPRINT" && "$REMOTE_FINGERPRINT" != "none" ]]; then
187-
echo "changed=false" >> $GITHUB_OUTPUT
188-
else
189-
echo "changed=true" >> $GITHUB_OUTPUT
190-
fi
191-
fi
192-
193-
- uses: docker/login-action@v3
194-
if: steps.image-fingerprint-check.outputs.changed == 'true'
195-
with:
196-
registry: ghcr.io
197-
username: ${{ github.actor }}
198-
password: ${{ secrets.GITHUB_TOKEN }}
199-
200-
- id: meta
201-
if: steps.image-fingerprint-check.outputs.changed == 'true'
202-
uses: docker/metadata-action@v5
203-
with:
204-
images: ghcr.io/mapchete/${{ inputs.image-name }}
205-
flavor: |
206-
latest=false
207-
tags: |
208-
# Manual Input override
209-
type=raw,value=${{ inputs.image-tag }},enable=${{ inputs.image-tag != '' }}
210-
211-
# RC Mode: Push only 'rc-' tag
212-
type=raw,value=rc-${{ needs.prepare.outputs.calculated-tag }},enable=${{ needs.prepare.outputs.mode == 'rc' }}
213-
214-
# Release Mode: Final version tag + latest
215-
type=raw,value=${{ needs.prepare.outputs.calculated-tag }},enable=${{ needs.prepare.outputs.mode == 'release' || (github.ref == 'refs/heads/main' && needs.prepare.outputs.mode != 'rolling') }}
216-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || needs.prepare.outputs.tag == 'latest' }}
217-
218-
# Rolling Mode: Specific 'dev' or 'latest' from dispatch
219-
type=raw,value=${{ needs.prepare.outputs.calculated-tag }},enable=${{ needs.prepare.outputs.mode == 'rolling' }}
220-
221-
- id: push
222-
if: steps.image-fingerprint-check.outputs.changed == 'true'
223-
uses: docker/build-push-action@v5
224-
with:
225-
context: ${{ inputs.image-name }}/
226-
push: true
227-
tags: ${{ steps.meta.outputs.tags }}
228-
labels: ${{ steps.meta.outputs.labels }}
229-
build-args: |
230-
IMAGE_FINGERPRINT=${{ steps.image-fingerprint-check.outputs.fingerprint }}
231-
232162
- name: Update Version Tracking Files
233163
if: |
234164
steps.image-fingerprint-check.outputs.changed == 'true' &&
@@ -238,13 +168,24 @@ jobs:
238168
SOURCE_VER="${{ github.event.client_payload.image_tag }}"
239169
FINAL_VER="${{ needs.prepare.outputs.calculated-tag }}"
240170
241-
# Update versions.yml
171+
# 1. Update versions.yml
242172
sed -i "s/^${SOURCE^^}_REF:.*/${SOURCE^^}_REF: $SOURCE_VER/" versions.yml
243173
244-
# Initialize/Update CHANGELOG.md
245-
[[ ! -f CHANGELOG.md ]] && echo -e "# Changelog\n\n" > CHANGELOG.md
246-
ENTRY="## [$FINAL_VER] - RC\n- Proposed alignment: **$SOURCE** to \`$SOURCE_VER\`\n- Test Image: \`ghcr.io/mapchete/${{ inputs.image-name }}:rc-$FINAL_VER\`\n"
247-
sed -i "3i $ENTRY" CHANGELOG.md
174+
# 2. Update CHANGELOG.rst
175+
# Calculate the length of the version string for the RST underline
176+
LEN=${#FINAL_VER}
177+
UNDERLINE=$(printf '%0.s-' $(seq 1 $LEN))
178+
179+
# Prepare the entry
180+
ENTRY="${FINAL_VER}\n${UNDERLINE}\n\n* Aligned with **${SOURCE}** @ \`${SOURCE_VER}\`.\n* Build Fingerprint: \`${{ steps.image-fingerprint-check.outputs.fingerprint }}\` \n"
181+
182+
if [[ ! -f CHANGELOG.rst ]]; then
183+
echo -e "Changelog\n=========\n\n$ENTRY" > CHANGELOG.rst
184+
else
185+
# Prepend after the main title (assuming title is on line 1 and underline on line 2)
186+
# We insert at line 4 to leave a gap after the title
187+
sed -i "4i $ENTRY" CHANGELOG.rst
188+
fi
248189
249190
- name: Automated Version PR
250191
if: |
@@ -264,7 +205,7 @@ jobs:
264205
**Test Image:** `ghcr.io/mapchete/${{ inputs.image-name }}:rc-${{ needs.prepare.outputs.calculated-tag }}`
265206
266207
**Changes:**
267-
- Updates `versions.yml` to pull `${{ github.event.client_payload.source_repo }}` @ `${{ github.event.client_payload.image_tag }}`.
208+
- Updates `versions.yml` to pull `${{ github.event.client_payload.source_repo }}` @ `${{ github.event.client_payload.image_tag || github.event.client_payload.sha }}`.
268209
269210
**To Release:** Review the changes and merge this PR to `main`. The official tag will be applied upon merge.
270211
base: main

0 commit comments

Comments
 (0)