Skip to content

Commit 04f1679

Browse files
committed
Cleanup
1 parent 33f8a0e commit 04f1679

File tree

1 file changed

+86
-190
lines changed

1 file changed

+86
-190
lines changed

.github/workflows/build-archives.yml

Lines changed: 86 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -21,226 +21,122 @@ jobs:
2121
- name: ⬇️ Checkout
2222
uses: actions/checkout@v4
2323

24-
- name: 🧩 Create versioned copies
24+
- name: 🛠️ Build version ZIPs
2525
shell: bash
2626
run: |
2727
set -euo pipefail
28-
29-
ensure_version() {
30-
local dir="$1"
31-
local pkg="$2"
32-
local suffix="$3"
33-
34-
local json=""
35-
local json_base=""
36-
if [[ -f "$dir/module.json" ]]; then
37-
json="$dir/module.json"
38-
json_base="module.json"
39-
elif [[ -f "$dir/system.json" ]]; then
40-
json="$dir/system.json"
41-
json_base="system.json"
42-
else
43-
return 0
44-
fi
45-
46-
export PKG_NAME="${pkg}"
47-
export SUFFIX="${suffix}"
48-
export JSON_FILE_BASENAME="${json_base}"
49-
50-
local tmp="${json}.tmp"
51-
jq -S '
52-
.version = env.NEW_VERSION
53-
| .download = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/.versions/" + env.PKG_NAME + "-" + env.SUFFIX + "/" + env.PKG_NAME + ".zip")
54-
| .manifest = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/.versions/" + env.PKG_NAME + "-" + env.SUFFIX + "/" + env.JSON_FILE_BASENAME)
55-
' "$json" > "$tmp"
56-
mv "$tmp" "$json"
57-
}
58-
59-
changed=0
60-
mkdir -p .versions
6128
shopt -s nullglob
6229
63-
for d in */ ; do
64-
case "$d" in
65-
.*/|.git/|.github/|.vscode/|.versions/) continue ;;
66-
esac
67-
68-
d="${d%/}"
69-
name="$(basename "$d")"
30+
MAIN_VERSION="1.0.1"
31+
mkdir -p .versions
7032
71-
for suffix in v0 v2; do
72-
case "$suffix" in
73-
v0) export NEW_VERSION="0.0.1" ;;
74-
v2) export NEW_VERSION="2.0.1" ;;
75-
esac
33+
json_file() {
34+
if [[ -f "$1/module.json" ]]; then echo "$1/module.json"; return; fi
35+
if [[ -f "$1/system.json" ]]; then echo "$1/system.json"; return; fi
36+
echo ""
37+
}
7638
77-
out=".versions/${name}-${suffix}"
78-
tmp_out="${out}.tmp"
39+
patch_main_manifest() {
40+
local dir="$1" pkg="$2"
41+
local jf; jf="$(json_file "$dir")" || true
42+
[[ -n "$jf" ]] || return 0
7943
80-
rm -rf "$tmp_out"
81-
mkdir -p "$tmp_out"
82-
rsync -a --delete \
83-
--exclude '*.zip' \
84-
--exclude '.versions/' \
85-
"${d}/" "$tmp_out/"
44+
local base; base="$(basename "$jf")"
45+
export NEW_MAIN_VERSION="$MAIN_VERSION"
46+
export PKG_NAME="$pkg"
47+
export JSON_FILE_BASENAME="$base"
8648
87-
ensure_version "$tmp_out" "$name" "$suffix"
49+
local tmp="${jf}.tmp"
50+
jq -S '
51+
.version = env.NEW_MAIN_VERSION
52+
| .download = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/" + env.PKG_NAME + "/" + env.PKG_NAME + ".zip")
53+
| .manifest = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/" + env.PKG_NAME + "/" + env.JSON_FILE_BASENAME)
54+
' "$jf" > "$tmp"
55+
if ! cmp -s "$tmp" "$jf"; then mv "$tmp" "$jf"; else rm -f "$tmp"; fi
56+
}
8857
89-
if ! diff -qr "$tmp_out" "$out" > /dev/null 2>&1; then
90-
rm -rf "$out"
91-
mv "$tmp_out" "$out"
92-
echo "Updated: $out"
93-
changed=1
94-
else
95-
rm -rf "$tmp_out"
96-
echo "No changes: $out"
97-
fi
98-
done
99-
done
58+
patch_version_manifest() {
59+
local dir="$1" pkg="$2" suffix="$3" ver="$4"
60+
local jf; jf="$(json_file "$dir")" || true
61+
[[ -n "$jf" ]] || return 0
10062
101-
if [[ "$changed" -eq 1 ]]; then
102-
git config user.name "github-actions[bot]"
103-
git config user.email "github-actions[bot]@users.noreply.github.com"
104-
git add .versions/
105-
if git diff --cached --quiet; then
106-
echo "No versioned changes to commit."
107-
else
108-
git commit -m "chore: Update versioned copies (automated)"
109-
git push
110-
fi
111-
else
112-
echo "No versioned copies changed."
113-
fi
63+
local base; base="$(basename "$jf")"
64+
export NEW_VERSION="$ver"
65+
export PKG_NAME="$pkg"
66+
export SUFFIX="$suffix"
67+
export JSON_FILE_BASENAME="$base"
11468
115-
- name: 📦 Build package ZIPs
116-
shell: bash
117-
run: |
118-
set -euo pipefail
69+
local tmp="${jf}.tmp"
70+
jq -S '
71+
.version = env.NEW_VERSION
72+
| .download = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/.versions/" + env.PKG_NAME + "-" + env.SUFFIX + "/" + env.PKG_NAME + ".zip")
73+
| .manifest = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/.versions/" + env.PKG_NAME + "-" + env.SUFFIX + "/" + env.JSON_FILE_BASENAME)
74+
' "$jf" > "$tmp"
75+
mv "$tmp" "$jf"
76+
}
11977
120-
ensure_main_json() {
121-
local dir="$1"
122-
local pkg="$2"
123-
124-
local json=""
125-
local json_base=""
126-
if [[ -f "$dir/module.json" ]]; then
127-
json="$dir/module.json"
128-
json_base="module.json"
129-
elif [[ -f "$dir/system.json" ]]; then
130-
json="$dir/system.json"
131-
json_base="system.json"
132-
else
78+
build_zip() {
79+
local src="$1" out="$2"
80+
local tmp="${out}.tmp"
81+
local parent; parent="$(dirname "$out")"
82+
mkdir -p "$parent"
83+
(
84+
cd "$src"
85+
zip -rqX "$tmp" . -x "*.zip" -x ".versions/*"
86+
)
87+
if [[ ! -f "$out" ]] || ! cmp -s "$tmp" "$out"; then
88+
mv "$tmp" "$out"
89+
echo "Updated ZIP: $out"
13390
return 0
134-
fi
135-
136-
export NEW_MAIN_VERSION="1.0.1"
137-
export PKG_NAME="${pkg}"
138-
export JSON_FILE_BASENAME="${json_base}"
139-
140-
local tmp="${json}.tmp"
141-
jq -S '
142-
.version = env.NEW_MAIN_VERSION
143-
| .download = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/" + env.PKG_NAME + "/" + env.PKG_NAME + ".zip")
144-
| .manifest = ("https://raw.githubusercontent.com/" + env.GITHUB_REPOSITORY + "/main/" + env.PKG_NAME + "/" + env.JSON_FILE_BASENAME)
145-
' "$json" > "$tmp"
146-
if ! cmp -s "$tmp" "$json"; then
147-
mv "$tmp" "$json"
148-
echo "Patched JSON for $pkg"
14991
else
15092
rm -f "$tmp"
93+
return 1
15194
fi
15295
}
15396
97+
rsync_copy() {
98+
local from="$1" to="$2"
99+
rm -rf "$to"
100+
mkdir -p "$to"
101+
rsync -a --delete --exclude '*.zip' --exclude '.versions/' "$from/" "$to/"
102+
}
103+
154104
changed=0
155-
shopt -s nullglob
156105
157106
for d in */ ; do
158107
case "$d" in
159108
.*/|.git/|.github/|.vscode/|.versions/) continue ;;
160109
esac
161-
162110
d="${d%/}"
163-
pkg="${d}"
164-
165-
ensure_main_json "$d" "$pkg"
166-
167-
zip_path="${d}/${d}.zip"
168-
tmp_zip="${zip_path}.tmp"
169-
170-
(cd "$d" && zip -rqX "../${tmp_zip}" . -x "*.zip" -x ".versions/*")
171-
172-
if [[ ! -f "$zip_path" ]] || ! cmp -s "$tmp_zip" "$zip_path"; then
173-
mv "$tmp_zip" "$zip_path"
174-
echo "Updated ZIP: $zip_path"
175-
changed=1
176-
else
177-
rm -f "$tmp_zip"
178-
echo "No ZIP changes: $zip_path"
179-
fi
180-
done
181-
182-
if [[ "$changed" -eq 1 ]]; then
183-
git config user.name "github-actions[bot]"
184-
git config user.email "github-actions[bot]@users.noreply.github.com"
185-
git add */*.zip */module.json */system.json 2>/dev/null || true
186-
if git diff --cached --quiet; then
187-
echo "No ZIP or JSON changes to commit."
188-
else
189-
git commit -m "chore: Rebuild packages (automated)"
190-
git push
191-
fi
192-
else
193-
git add */module.json */system.json 2>/dev/null || true
194-
if git diff --cached --quiet; then
195-
echo "No changes to commit."
196-
else
197-
git config user.name "github-actions[bot]"
198-
git config user.email "github-actions[bot]@users.noreply.github.com"
199-
git commit -m "chore: Update main manifests (automated)"
200-
git push
201-
fi
202-
fi
203-
204-
- name: 🗂️ Build version ZIPs
205-
shell: bash
206-
run: |
207-
set -euo pipefail
208-
shopt -s nullglob
209-
210-
changed=0
111+
pkg="$d"
211112
212-
for version_dir in .versions/*-v*/ ; do
213-
[[ -d "$version_dir" ]] || continue
214-
version_dir="${version_dir%/}"
113+
patch_main_manifest "$d" "$pkg" || true
215114
216-
version_name="$(basename "$version_dir")"
217-
name="${version_name%-v*}"
115+
if build_zip "$d" "$d/$pkg.zip"; then changed=1; fi
218116
219-
zip_path="${version_dir}/${name}.zip"
220-
tmp_name="${name}.zip.tmp"
221-
222-
(cd "$version_dir" && zip -rqX "$tmp_name" . -x "*.zip" -x ".versions/*")
223-
224-
if [[ ! -f "$zip_path" ]] || ! cmp -s "$version_dir/$tmp_name" "$zip_path"; then
225-
mv "$version_dir/$tmp_name" "$zip_path"
226-
echo "Updated version ZIP: $zip_path"
227-
changed=1
228-
else
229-
rm -f "$version_dir/$tmp_name"
230-
echo "No ZIP changes: $zip_path"
231-
fi
117+
for suffix ver in v0 0.0.1 v2 2.0.1; do
118+
out=".versions/${pkg}-${suffix}"
119+
tmp="${out}.tmp"
120+
rsync_copy "$d" "$tmp"
121+
patch_version_manifest "$tmp" "$pkg" "$suffix" "$ver"
122+
if ! diff -qr "$tmp" "$out" >/dev/null 2>&1; then
123+
rm -rf "$out"
124+
mv "$tmp" "$out"
125+
echo "Updated version dir: $out"
126+
changed=1
127+
else
128+
rm -rf "$tmp"
129+
fi
130+
if build_zip "$out" "$out/$pkg.zip"; then changed=1; fi
131+
done
232132
done
233133
234-
if [[ "$changed" -eq 1 ]]; then
235-
git config user.name "github-actions[bot]"
236-
git config user.email "github-actions[bot]@users.noreply.github.com"
237-
git add .versions/*-v*/*.zip
238-
if git diff --cached --quiet; then
239-
echo "No versioned ZIP changes to commit."
240-
else
241-
git commit -m "chore: Rebuild versioned ZIPs (automated)"
242-
git push
243-
fi
134+
git config user.name "github-actions[bot]"
135+
git config user.email "github-actions[bot]@users.noreply.github.com"
136+
git add */*.zip */module.json */system.json .versions/
137+
if git diff --cached --quiet; then
138+
echo "No changes to commit."
244139
else
245-
echo "No versioned ZIP changes to commit."
140+
git commit -m "chore: Build packages & versioned copies (automated)"
141+
git push
246142
fi

0 commit comments

Comments
 (0)