Skip to content

Commit 45f6a93

Browse files
committed
try to figure out a PR creation with sensible version(s) tracking
1 parent e513079 commit 45f6a93

File tree

1 file changed

+78
-12
lines changed

1 file changed

+78
-12
lines changed

.github/workflows/_image-factory.yml

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
default: ''
2323

2424
jobs:
25-
prepare:
25+
prepare:
2626
runs-on: ubuntu-latest
2727
outputs:
2828
run-build: ${{ steps.check.outputs.run }}
@@ -32,6 +32,7 @@ jobs:
3232
mapchete-hub-cli-ref: ${{ steps.resolve.outputs.cli }}
3333
steps:
3434
- uses: actions/checkout@v4
35+
3536
- id: check
3637
run: |
3738
if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then
@@ -52,12 +53,9 @@ jobs:
5253
5354
# 2. Extract values from the repository_dispatch payload if they exist
5455
DISPATCH_REPO="${{ github.event.client_payload.source_repo }}"
55-
# Prioritize image_tag (versioning) over sha (development commits)
5656
DISPATCH_REF="${{ github.event.client_payload.image_tag || github.event.client_payload.sha }}"
5757
58-
# 3. Resolve final references using a strict priority order:
59-
# Manual Input > Matching Repository Dispatch > versions.yml Default
60-
58+
# 3. Resolve final references
6159
if [[ -n "${{ inputs.mapchete-ref }}" ]]; then M_REF="${{ inputs.mapchete-ref }}"
6260
elif [[ "$DISPATCH_REPO" == "mapchete" ]]; then M_REF="$DISPATCH_REF"
6361
else M_REF="$MAPCHETE_DEFAULT_VAL"; fi
@@ -79,6 +77,20 @@ jobs:
7977
echo "hub=$HUB_REF" >> $GITHUB_OUTPUT
8078
echo "cli=$CLI_REF" >> $GITHUB_OUTPUT
8179
80+
- name: Generate Summary
81+
run: |
82+
echo "### 🛠️ Build Preparation Summary" >> $GITHUB_STEP_SUMMARY
83+
echo "**Trigger Event:** \`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY
84+
echo "**Target Image:** \`${{ inputs.image-name }}\`" >> $GITHUB_STEP_SUMMARY
85+
echo "**Run Build:** \`${{ steps.check.outputs.run }}\`" >> $GITHUB_STEP_SUMMARY
86+
echo "" >> $GITHUB_STEP_SUMMARY
87+
echo "| Component | Resolved Reference |" >> $GITHUB_STEP_SUMMARY
88+
echo "| :--- | :--- |" >> $GITHUB_STEP_SUMMARY
89+
echo "| mapchete | \`${{ steps.resolve.outputs.mapchete }}\` |" >> $GITHUB_STEP_SUMMARY
90+
echo "| mapchete-eo | \`${{ steps.resolve.outputs.eo }}\` |" >> $GITHUB_STEP_SUMMARY
91+
echo "| mapchete-hub | \`${{ steps.resolve.outputs.hub }}\` |" >> $GITHUB_STEP_SUMMARY
92+
echo "| mapchete-hub-cli | \`${{ steps.resolve.outputs.cli }}\` |" >> $GITHUB_STEP_SUMMARY
93+
8294
build:
8395
needs: prepare
8496
if: needs.prepare.outputs.run-build == 'true'
@@ -194,23 +206,77 @@ jobs:
194206
subject-digest: ${{ steps.push.outputs.digest }}
195207
push-to-registry: true
196208

209+
- name: Update Version Tracking Files
210+
if: github.event_name == 'repository_dispatch'
211+
run: |
212+
NEW_REF="${{ github.event.client_payload.image_tag }}"
213+
SOURCE="${{ github.event.client_payload.source_repo }}"
214+
TYPE="${{ github.event.client_payload.type }}"
215+
DATE=$(date +'%Y-%m-%d')
216+
217+
# 1. Determine the target reference for versions.yml
218+
# If it's a version release, use the tag. Otherwise, use 'main'.
219+
if [[ "$TYPE" == "version" ]]; then
220+
TARGET_REF="$NEW_REF"
221+
else
222+
TARGET_REF="main"
223+
fi
224+
225+
echo "Updating $SOURCE to $TARGET_REF in versions.yml"
226+
227+
# 2. Update versions.yml (assuming keys exist in the file)
228+
case "$SOURCE" in
229+
"mapchete")
230+
sed -i "s/^MAPCHETE_REF:.*/MAPCHETE_REF: $TARGET_REF/" versions.yml
231+
;;
232+
"mapchete-eo")
233+
sed -i "s/^MAPCHETE_EO_REF:.*/MAPCHETE_EO_REF: $TARGET_REF/" versions.yml
234+
;;
235+
"mapchete-hub")
236+
sed -i "s/^MAPCHETE_HUB_REF:.*/MAPCHETE_HUB_REF: $TARGET_REF/" versions.yml
237+
;;
238+
"mapchete-hub-cli")
239+
sed -i "s/^MAPCHETE_HUB_CLI_REF:.*/MAPCHETE_HUB_CLI_REF: $TARGET_REF/" versions.yml
240+
;;
241+
esac
242+
243+
# 3. Handle CHANGELOG.md (Only for Version Releases)
244+
if [[ "$TYPE" == "version" ]]; then
245+
# Create file if it doesn't exist
246+
if [[ ! -f CHANGELOG.md ]]; then
247+
echo "# Changelog" > CHANGELOG.md
248+
echo "All notable changes to the Mapchete Container Images will be documented in this file." >> CHANGELOG.md
249+
fi
250+
251+
# Create the new entry
252+
NEW_ENTRY="## [$NEW_REF] - $DATE\n- Automated release alignment: **$SOURCE** updated to \`$NEW_REF\`\n- Image: \`ghcr.io/mapchete/${{ inputs.image-name }}:$NEW_REF\`\n- Fingerprint: \`${{ steps.image-fingerprint-check.outputs.fingerprint }}\` \n"
253+
254+
# Prepend the entry below the header (line 3)
255+
sed -i "3i $NEW_ENTRY" CHANGELOG.md
256+
fi
257+
197258
- name: Automated Version PR
198259
if: github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'version'
199260
uses: peter-evans/create-pull-request@v6
200261
with:
201262
token: ${{ secrets.MAPCHETE_PAT || secrets.GITHUB_TOKEN }}
202-
commit-message: "chore: update ${{ inputs.image-name }} to ${{ github.event.client_payload.image_tag }}"
203-
branch: "bump/${{ inputs.image-name }}"
204-
title: "🚀 Bump ${{ inputs.image-name }} version"
263+
commit-message: "chore(release): align ${{ inputs.image-name }} with ${{ github.event.client_payload.image_tag }}"
264+
branch: "release/${{ inputs.image-name }}-${{ github.event.client_payload.image_tag }}"
265+
title: "🚀 Release Align: ${{ inputs.image-name }} @ ${{ github.event.client_payload.image_tag }}"
205266
body: |
206-
Automated update from `${{ github.event.client_payload.source_repo }}`.
207-
- **New Version:** `${{ github.event.client_payload.image_tag }}`
208-
- **Fingerprint:** `${{ steps.image-fingerprint-check.outputs.fingerprint }}`
267+
### 📦 Automated Release Alignment
268+
A new tagged version was detected in the source repository.
269+
270+
**Changes:**
271+
1. **versions.yml**: Updated `${{ github.event.client_payload.source_repo }}` reference to `${{ github.event.client_payload.image_tag }}`.
272+
2. **CHANGELOG.md**: Added release entry.
273+
274+
Verification Fingerprint: `${{ steps.image-fingerprint-check.outputs.fingerprint }}`
209275
base: main
210276
delete-branch: true
277+
labels: "automated-pr, release-alignment"
211278
assignees: "scartography"
212279
reviewers: "ungarj"
213-
labels: "automated-pr"
214280

215281
cleanup-registry:
216282
needs: [prepare, build]

0 commit comments

Comments
 (0)