@@ -3,68 +3,32 @@ name: Build and Push to Build Branch
33on :
44 push :
55 branches :
6- - development
6+ - development # Triggers when a PR is merged into development
7+
8+ permissions :
9+ contents : write
710
811jobs :
912 build-and-push :
1013 runs-on : ubuntu-latest
11-
1214 steps :
1315 - name : Checkout code
14- uses : actions/checkout@v6 # Upgrade to v6
15- with :
16- fetch-depth : 0
16+ uses : actions/checkout@v6
1717
1818 - name : Setup Node.js
19- uses : actions/setup-node@v6 # Upgrade to v6
19+ uses : actions/setup-node@v6
2020 with :
21- node-version : ' 24' # Upgrade to Node.js 24
22-
23- - name : Install dependencies
24- run : npm ci
25-
26- - name : Build project
27- run : npm run build
28-
29- - name : Configure git
30- run : |
31- git config --local user.email "action@github.com"
32- git config --local user.name "GitHub Action"
21+ node-version : ' lts'
3322
34- - name : Prepare build branch
23+ - name : Install and Build
3524 run : |
36- # Create a temporary directory with only dist contents
37- mkdir -p /tmp/build-contents
38- if [ -d "dist" ]; then
39- cp -r dist/* /tmp/build-contents/
40- fi
41- cp README.md /tmp/build-contents/ 2>/dev/null
25+ npm ci
26+ npm run build
4227
43- # Create or checkout build branch
44- git fetch origin
45- git checkout -B build origin/build 2>/dev/null || git checkout -B build
46-
47- # Clean the current branch (keep only dist content)
48- find . -maxdepth 1 -not -name '.git' -not -name '.gitignore' -exec rm -rf {} + 2>/dev/null || true
49-
50- # Copy dist contents to root of build branch
51- cp -r /tmp/build-contents/* .
52-
53- # Add .gitkeep if dist is empty
54- if [ -z "$(ls -A --ignore=.git)" ]; then
55- touch .gitkeep
56- fi
57-
58- - name : Commit and push build branch
59- run : |
60- # Force add everything to bypass .gitignore rules
61- git add -A --force
62-
63- # Only commit if there are changes
64- if ! git diff-index --quiet HEAD --; then
65- git commit -m "chore: auto build from development branch [skip ci]"
66- # Used --force push to ensure the build branch perfectly matches latest dist
67- git push origin build --force
68- else
69- echo "No changes to commit"
70- fi
28+ - name : Deploy to Build Branch
29+ uses : JamesIves/github-pages-deploy-action@v4
30+ with :
31+ folder : dist # ONLY files in dist move to the build branch
32+ branch : build # The target branch
33+ clean : true # Deletes everything else (README, LICENSE, etc.)
34+ single-commit : true # Keeps git history tiny (ideal for submodules)
0 commit comments