Skip to content

Commit 2f7e46c

Browse files
authored
Refactor artifact handling in receive-beta-build workflow
Refactor artifact download and extraction process in CI workflow. Improved error handling and logging for better debugging.
1 parent 4c200d5 commit 2f7e46c

1 file changed

Lines changed: 49 additions & 47 deletions

File tree

.github/workflows/receive-beta-build.yml

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,77 +16,80 @@ jobs:
1616
with:
1717
ref: main
1818

19-
- name: Download artifact
19+
- name: Download and extract build
2020
run: |
2121
set -euo pipefail
22+
2223
ARTIFACT_URL="${{ github.event.client_payload.artifact_url }}"
2324
TOKEN="${{ secrets.BETA_PAT_TOKEN }}"
25+
ZIP_NAME="${{ github.event.client_payload.zip_name }}"
2426
25-
echo "Downloading artifact from: ${ARTIFACT_URL}"
26-
curl -L -H "Authorization: token ${TOKEN}" -o outer-artifact.zip "${ARTIFACT_URL}"
27+
echo "Downloading artifact:"
28+
echo " URL: ${ARTIFACT_URL}"
29+
echo " ZIP_NAME: ${ZIP_NAME}"
2730
28-
- name: Extract artifact(s)
29-
run: |
30-
set -euo pipefail
31+
# Fallback name if for some reason zip_name is empty
32+
OUTER_ZIP="${ZIP_NAME:-build-artifact.zip}"
3133
32-
mkdir -p temp-build
34+
curl -L -H "Authorization: token ${TOKEN}" -o "${OUTER_ZIP}" "${ARTIFACT_URL}"
3335
34-
echo "Unzipping outer artifact to temp-build..."
35-
unzip -q outer-artifact.zip -d temp-build
36+
echo "Unzipping outer artifact into temp-build..."
37+
mkdir -p temp-build
38+
unzip -q "${OUTER_ZIP}" -d temp-build
3639
37-
# Find any zip inside temp-build (inner/packaged zip). Support any name.
38-
INNER_ZIP="$(find temp-build -maxdepth 2 -type f -name '*.zip' -print -quit || true)"
40+
echo "Looking for inner build zip inside temp-build..."
41+
INNER_ZIP="$(find temp-build -maxdepth 2 -type f -name '*.zip' | head -n 1 || true)"
3942
40-
if [ -n "${INNER_ZIP:-}" ]; then
41-
echo "Found inner zip: ${INNER_ZIP}"
42-
unzip -q "${INNER_ZIP}" -d temp-build
43-
rm -f "${INNER_ZIP}"
44-
else
45-
echo "No inner zip found under temp-build; maybe outer zip directly contained files."
43+
if [ -z "${INNER_ZIP}" ]; then
44+
echo "ERROR: No inner zip found under temp-build"
45+
echo "Tree under temp-build:"
46+
find temp-build -maxdepth 5 -print
47+
exit 1
4648
fi
4749
48-
# Clean up the downloaded outer zip
49-
rm -f outer-artifact.zip
50+
echo "Found inner zip: ${INNER_ZIP}"
51+
echo "Unzipping inner build zip..."
52+
unzip -q "${INNER_ZIP}" -d temp-build
53+
54+
# Optional: clean up zips
55+
rm -f "${OUTER_ZIP}"
56+
rm -f "${INNER_ZIP}"
5057
51-
- name: Place Build/dist contents into subfolder
58+
echo "Resulting structure under temp-build:"
59+
find temp-build -maxdepth 4 -type d -print
60+
61+
- name: Replace subfolder with Build/dist contents
5262
run: |
5363
set -euo pipefail
5464
SUBFOLDER="${{ github.event.client_payload.subfolder }}"
65+
5566
echo "Target subfolder: ${SUBFOLDER}"
5667
57-
# Ensure subfolder exists
5868
mkdir -p "${SUBFOLDER}"
5969
60-
# Clear subfolder including hidden files (but keep the dir)
61-
echo "Clearing existing contents of ${SUBFOLDER}"
62-
find "${SUBFOLDER}" -mindepth 1 -maxdepth 1 -print0 | xargs -0 --no-run-if-empty rm -rf --
70+
echo "Before replace, contents of ${SUBFOLDER}:"
71+
ls -la "${SUBFOLDER}" || true
6372
64-
# Determine source dist path
65-
# Look for Build/dist under temp-build
66-
DIST_DIR="$(find temp-build -type d -path '*/Build/dist' -print -quit || true)"
67-
68-
# If not found, also look for any directory named 'dist'
69-
if [ -z "${DIST_DIR:-}" ]; then
70-
DIST_DIR="$(find temp-build -type d -name 'dist' -print -quit || true)"
73+
# Clear subfolder (including hidden files) but keep the dir itself
74+
if [ -d "${SUBFOLDER}" ]; then
75+
echo "Clearing existing contents of ${SUBFOLDER}"
76+
find "${SUBFOLDER}" -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf -- || true
7177
fi
7278
73-
if [ -z "${DIST_DIR:-}" ]; then
74-
echo "ERROR: could not find a 'Build/dist' or 'dist' directory under temp-build:"
75-
find temp-build -maxdepth 4 -print
79+
# Ensure we have Build/dist in temp-build
80+
if [ ! -d "temp-build/Build/dist" ]; then
81+
echo "ERROR: temp-build/Build/dist does not exist"
82+
echo "Actual temp-build structure:"
83+
find temp-build -maxdepth 6 -print
7684
exit 1
7785
fi
7886
79-
echo "Using dist source: ${DIST_DIR}"
80-
81-
# Move contents of dist into subfolder (preserve dotfiles)
87+
echo "Copying Build/dist contents into ${SUBFOLDER}"
8288
shopt -s dotglob nullglob
83-
files=( "${DIST_DIR}"/* )
84-
if [ ${#files[@]} -gt 0 ]; then
85-
echo "Moving ${#files[@]} items from ${DIST_DIR} -> ${SUBFOLDER}"
86-
mv "${files[@]}" "${SUBFOLDER}/"
87-
else
88-
echo "Warning: ${DIST_DIR} is empty; nothing to move."
89-
fi
89+
mv temp-build/Build/dist/* "${SUBFOLDER}/"
90+
91+
echo "After replace, contents of ${SUBFOLDER}:"
92+
ls -la "${SUBFOLDER}"
9093
9194
- name: Commit and push
9295
run: |
@@ -97,14 +100,13 @@ jobs:
97100
git config --global user.name 'github-actions[bot]'
98101
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
99102
100-
# Stage only the subfolder (including deletions)
101-
git add -A "${SUBFOLDER}"
103+
git add "${SUBFOLDER}"
102104
103105
if git diff --staged --quiet; then
104106
echo "No changes to commit"
105107
else
106108
echo "Changes detected; committing..."
107-
git status --porcelain
109+
git status
108110
git commit -m "Deploy ${SOURCE_REPO} build to ${SUBFOLDER}"
109111
git push origin main
110112
fi

0 commit comments

Comments
 (0)