@@ -3,7 +3,7 @@ name: Deploy Built Project to Master Branch
33on :
44 push :
55 branches : [ next ]
6- workflow_dispatch : # Allow manual trigger
6+ workflow_dispatch :
77
88jobs :
99 build-and-deploy-to-master :
1313 - name : Checkout
1414 uses : actions/checkout@v4
1515 with :
16- fetch-depth : 0 # Fetch all history for proper git operations
16+ fetch-depth : 0
1717
1818 - name : Setup Node.js
1919 uses : actions/setup-node@v4
@@ -51,51 +51,50 @@ jobs:
5151
5252 - name : Build project
5353 run : npm run build:prod
54-
55- - name : Configure Git
56- run : |
57- git config --local user.email "action@github.com"
58- git config --local user.name "GitHub Action"
5954
60- - name : Discard local changes
61- run : git reset --hard
55+ - name : Upload dist as artifact
56+ uses : actions/upload-artifact@v4
57+ with :
58+ name : dist
59+ path : dist
6260
6361 - name : Switch to master branch
6462 run : |
6563 git checkout master
6664 git pull origin master
67-
68- - name : Clean master branch (keep only built files )
65+
66+ - name : Clean master branch (keep only .git )
6967 run : |
70- # Remove all files except .git
7168 find . -maxdepth 1 -not -name '.git' -not -name '.' -exec rm -rf {} +
72-
73- - name : Copy built files to master
74- run : |
75- # Copy built files from next branch
76- git checkout next -- dist/
77- git checkout next -- .env.production
78- git checkout next -- .env.example
79- git checkout next -- README.md
80- git checkout next -- package.json
81-
82- - name : Create index.html for GitHub Pages
69+
70+ - name : Download built artifact
71+ uses : actions/download-artifact@v4
72+ with :
73+ name : dist
74+ path : dist
75+
76+ - name : Copy important files to master
8377 run : |
84- # Move dist contents to root for GitHub Pages
85- cp -r dist/* .
86- # Keep important files
78+ cp .env.production .
8779 cp .env.example .
8880 cp README.md .
8981 cp package.json .
90-
82+ # Move built files to root
83+ cp -r dist/* .
84+
85+ - name : Configure Git
86+ run : |
87+ git config --local user.email "action@github.com"
88+ git config --local user.name "GitHub Action"
89+
9190 - name : Commit and push to master
9291 run : |
9392 git add .
94- git commit -m "Deploy built project from next branch - $(date)"
93+ git commit -m "Deploy built project from next branch - $(date)" || echo "No changes to commit"
9594 git push origin master
9695
9796 - name : Deploy to GitHub Pages
9897 uses : peaceiris/actions-gh-pages@v3
9998 with :
10099 github_token : ${{ secrets.GITHUB_TOKEN }}
101- publish_dir : ./
100+ publish_dir : ./
0 commit comments