Skip to content

Cleanup

Cleanup #8

name: Build package versions
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
concurrency:
group: build-zips-${{ github.ref }}
cancel-in-progress: false
jobs:
build:
name: 📦 Build package versions
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout
uses: actions/checkout@v4
- name: 🧩 Create versioned copies
shell: bash
run: |
set -euo pipefail
ensure_version() {
local dir="$1"
local json=""
if [[ -f "$dir/module.json" ]]; then
json="$dir/module.json"
elif [[ -f "$dir/system.json" ]]; then
json="$dir/system.json"
else
return 0
fi
local tmp="${json}.tmp"
jq -S '.version = env.NEW_VERSION' "$json" > "$tmp"
mv "$tmp" "$json"
}
changed=0
mkdir -p .versions
shopt -s nullglob
for d in */ ; do
case "$d" in
.*/|.git/|.github/|.vscode/|.versions/) continue ;;
esac
d="${d%/}"
name="$(basename "$d")"
for suffix in v0 v2; do
case "$suffix" in
v0) export NEW_VERSION="0.0.1" ;;
v2) export NEW_VERSION="2.0.1" ;;
esac
out=".versions/${name}-${suffix}"
tmp_out="${out}.tmp"
rm -rf "$tmp_out"
mkdir -p "$tmp_out"
rsync -a --delete \
--exclude '*.zip' \
--exclude '.versions/' \
"${d}/" "$tmp_out/"
ensure_version "$tmp_out"
if ! diff -qr "$tmp_out" "$out" > /dev/null 2>&1; then
rm -rf "$out"
mv "$tmp_out" "$out"
echo "Updated: $out"
changed=1
else
rm -rf "$tmp_out"
echo "No changes: $out"
fi
done
done
if [[ "$changed" -eq 1 ]]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .versions/
if git diff --cached --quiet; then
echo "No versioned changes to commit."
else
git commit -m "chore: Update versioned copies (automated)"
git push
fi
else
echo "No versioned copies changed."
fi
- name: 📦 Build package ZIPs
shell: bash
run: |
set -euo pipefail
changed=0
shopt -s nullglob
for d in */ ; do
case "$d" in
.*/|.git/|.github/|.vscode/|.versions/) continue ;;
esac
d="${d%/}"
zip_path="${d}/${d}.zip"
tmp_zip="${zip_path}.tmp"
(cd "$d" && zip -rqX "../${tmp_zip}" . -x "*.zip" -x ".versions/*")
if [[ ! -f "$zip_path" ]] || ! cmp -s "$tmp_zip" "$zip_path"; then
mv "$tmp_zip" "$zip_path"
echo "Updated ZIP: $zip_path"
changed=1
else
rm -f "$tmp_zip"
echo "No ZIP changes: $zip_path"
fi
done
if [[ "$changed" -eq 1 ]]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add */*.zip
if git diff --cached --quiet; then
echo "No ZIP changes to commit."
else
git commit -m "chore: Rebuild package ZIPs (automated)"
git push
fi
else
echo "No ZIP changes to commit."
fi
- name: 🗂️ Build version ZIPs
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
changed=0
for version_dir in .versions/*-v*/ ; do
[[ -d "$version_dir" ]] || continue
version_dir="${version_dir%/}"
version_name="$(basename "$version_dir")"
name="${version_name%-v*}"
zip_path="${version_dir}/${name}.zip"
tmp_name="${name}.zip.tmp"
(cd "$version_dir" && zip -rqX "$tmp_name" . -x "*.zip" -x ".versions/*")
if [[ ! -f "$zip_path" ]] || ! cmp -s "$version_dir/$tmp_name" "$zip_path"; then
mv "$version_dir/$tmp_name" "$zip_path"
echo "Updated version ZIP: $zip_path"
changed=1
else
rm -f "$version_dir/$tmp_name"
echo "No ZIP changes: $zip_path"
fi
done
if [[ "$changed" -eq 1 ]]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .versions/*-v*/*.zip
if git diff --cached --quiet; then
echo "No versioned ZIP changes to commit."
else
git commit -m "chore: Rebuild versioned ZIPs (automated)"
git push
fi
else
echo "No versioned ZIP changes to commit."
fi