Skip to content

Commit 7bdbb93

Browse files
author
p1xel
committed
chore(build-dist): Update workflow to work with any source branch
1 parent 38f9730 commit 7bdbb93

1 file changed

Lines changed: 47 additions & 18 deletions

File tree

.github/workflows/build-dist.yml

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,55 +40,84 @@ jobs:
4040
git config user.name "github-actions[bot]"
4141
git config user.email "github-actions[bot]@users.noreply.github.com"
4242
43+
# Get current branch name
44+
SOURCE_BRANCH="${GITHUB_REF_NAME}"
45+
echo "Source branch: $SOURCE_BRANCH"
46+
47+
# Backup dist/ temporarily (it's not in git, created by build)
48+
if [ -d "dist" ]; then
49+
cp -r dist /tmp/dist-backup
50+
echo "✅ Backed up dist/"
51+
else
52+
echo "❌ dist/ not found after build"
53+
exit 1
54+
fi
55+
4356
# Fetch all branches
4457
git fetch origin
4558
4659
# Check if build branch exists
4760
if git show-ref --verify --quiet refs/remotes/origin/build; then
61+
echo "✅ Build branch exists, checking out"
4862
git checkout build
49-
# Reset to master to get latest files (except dist)
50-
git checkout master -- .gitignore
51-
# Remove /dist from gitignore temporarily
63+
64+
# Reset to source branch (except dist/)
65+
git checkout "$SOURCE_BRANCH" -- .gitignore package.json README.md LICENSE
66+
67+
# Remove /dist from gitignore
5268
sed -i '/^\/dist$/d' .gitignore
69+
70+
# Restore dist/ from backup
71+
rm -rf dist
72+
cp -r /tmp/dist-backup dist
5373
else
54-
# Create orphan branch
74+
echo "✅ Creating new orphan build branch"
5575
git checkout --orphan build
76+
5677
# Remove /dist from gitignore
5778
sed -i '/^\/dist$/d' .gitignore
58-
# Remove all files except dist
59-
git rm -rf .
60-
git checkout master -- dist/
61-
git checkout master -- package.json
62-
git checkout master -- README.md
63-
git checkout master -- LICENSE
79+
80+
# Remove all files (clean slate)
81+
git rm -rf . 2>/dev/null || true
82+
83+
# Checkout basic files from source branch
84+
git checkout "$SOURCE_BRANCH" -- package.json README.md LICENSE .gitignore
85+
86+
# Add dist/ from backup
87+
cp -r /tmp/dist-backup dist
6488
fi
6589
66-
- name: 📋 Copy dist to build branch
90+
- name: 📋 Stage files
6791
run: |
68-
# Ensure dist is present
92+
# Verify dist/ exists
6993
if [ ! -d "dist" ]; then
70-
echo "❌ dist/ directory not found after build"
94+
echo "❌ dist/ directory not found"
7195
exit 1
7296
fi
7397
74-
# Add dist files
98+
# Stage files
7599
git add dist/ -f
76100
git add package.json
77101
git add README.md
78102
git add LICENSE
79103
git add .gitignore
80104
105+
echo "✅ Files staged"
106+
81107
- name: 💾 Commit and push
82108
run: |
83-
# Check if there are changes to commit
109+
SOURCE_BRANCH="${GITHUB_REF_NAME}"
110+
111+
# Check for changes
84112
if git diff --staged --quiet; then
85-
echo "✅ No changes in dist/, skipping commit"
113+
echo "✅ No changes to commit"
86114
exit 0
87115
fi
88116
89-
git commit -m "chore(build): update dist/ from master@$(git rev-parse --short master) [skip ci]"
117+
# Commit
118+
git commit -m "chore(build): update dist/ from ${SOURCE_BRANCH}@$(git rev-parse --short HEAD) [skip ci]"
90119
91-
# Force push to build branch (clean history)
120+
# Force push (clean history)
92121
git push origin build --force
93122
94123
echo "✅ Successfully pushed dist/ to build branch"

0 commit comments

Comments
 (0)