1+ name : Update Catalog.json w New App Version PR
2+
3+ on :
4+ push :
5+ branches : [main]
6+
7+ permissions :
8+ contents : write
9+ pull-requests : write
10+
11+ jobs :
12+ update-catalog-pr :
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - name : Checkout main
17+ uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0
20+
21+ - name : Detect changed ZIPs, create tags, update catalog.json (in working tree)
22+ shell : bash
23+ env :
24+ BEFORE_SHA : ${{ github.event.before }}
25+ AFTER_SHA : ${{ github.sha }}
26+ run : |
27+ set -euo pipefail
28+
29+ # 1) Find ZIP files changed in this push to main (merge commit)
30+ mapfile -t changed_zips < <(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" | grep -E '\.zip$' || true)
31+
32+ if [[ ${#changed_zips[@]} -eq 0 ]]; then
33+ echo "No .zip files changed. Exiting."
34+ exit 0
35+ fi
36+
37+ echo "Changed ZIPs:"
38+ printf ' - %s\n' "${changed_zips[@]}"
39+
40+ git config user.name "github-actions[bot]"
41+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
42+
43+ updated_any=false
44+
45+ for zip_path in "${changed_zips[@]}"; do
46+ # Only act on ZIPs that exist after the merge (skip deletions)
47+ [[ -f "$zip_path" ]] || continue
48+
49+ zip_dir="$(dirname "$zip_path")"
50+ catalog_path="$zip_dir/catalog.json"
51+ manifest_path="$zip_dir/manifest.json"
52+
53+ # 2) If no catalog.json next to this zip, exit (no-op)
54+ if [[ ! -f "$catalog_path" ]]; then
55+ echo "No catalog.json at $catalog_path. Exiting."
56+ exit 0
57+ fi
58+
59+ if [[ ! -f "$manifest_path" ]]; then
60+ echo "::error file=$manifest_path::manifest.json not found next to ZIP ($zip_path)"
61+ exit 1
62+ fi
63+
64+ # Version from manifest.json (expects .version)
65+ version="$(jq -r '.version // empty' "$manifest_path")"
66+ if [[ -z "$version" || "$version" == "null" ]]; then
67+ echo "::error file=$manifest_path::Missing .version in manifest.json"
68+ exit 1
69+ fi
70+
71+ # 3) Tag name = zip filename without .zip
72+ zip_file="$(basename "$zip_path")"
73+ tag_name="${zip_file%.zip}"
74+
75+ # Create + push tag (skip if already exists)
76+ if ! git rev-parse -q --verify "refs/tags/$tag_name" >/dev/null; then
77+ git tag -a "$tag_name" -m "Release $tag_name"
78+ fi
79+ if ! git ls-remote --exit-code --tags origin "refs/tags/$tag_name" >/dev/null 2>&1; then
80+ git push origin "refs/tags/$tag_name"
81+ fi
82+
83+ # 4) Update latest and 5) Append a new versions entry
84+ tmp="$(mktemp)"
85+ jq --arg v "$version" --arg t "$tag_name" '
86+ .versions = (.versions // []) |
87+ .latest = {"version": $v, "tag": $t} |
88+ .versions = (.versions + [{"version": $v, "tag": $t}])
89+ ' "$catalog_path" > "$tmp"
90+
91+ mv "$tmp" "$catalog_path"
92+ git add "$catalog_path"
93+ updated_any=true
94+ done
95+
96+ if [[ "$updated_any" != "true" ]]; then
97+ echo "No catalog updates to propose. Exiting."
98+ exit 0
99+ fi
100+
101+ if git diff --cached --quiet; then
102+ echo "No effective catalog changes staged. Exiting."
103+ exit 0
104+ fi
105+
106+ - name : Create PR with catalog.json update
107+ if : ${{ !cancelled() }}
108+ uses : peter-evans/create-pull-request@v6
109+ with :
110+ token : ${{ secrets.GITHUB_TOKEN }}
111+ branch : chore/update-catalog-${{ github.run_id }}
112+ delete-branch : true
113+ commit-message : " chore: update catalog.json after ZIP merge"
114+ title : " chore: update catalog.json after ZIP merge"
115+ body : |
116+ This PR was auto-generated after a ZIP file was merged into `main`.
117+
118+ - Creates a tag matching the ZIP filename (without `.zip`)
119+ - Updates `catalog.json` `latest`
120+ - Appends a new entry to `catalog.json` `versions`
121+ labels : |
122+ automation
0 commit comments