File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Deploy Vite React App to GitHub Pages (Alternative)
2+
3+ on :
4+ push :
5+ branches :
6+ - master # Change to 'main' if your default branch is 'main'
7+
8+ jobs :
9+ deploy :
10+ runs-on : ubuntu-latest
11+
12+ permissions :
13+ contents : write
14+ pages : write
15+
16+ steps :
17+ - name : Checkout
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0
21+
22+ - name : Set up Node.js
23+ uses : actions/setup-node@v4
24+ with :
25+ node-version : ' 20'
26+ cache : ' npm'
27+
28+ - name : Install Dependencies
29+ run : npm ci
30+
31+ - name : Build
32+ run : npm run deploy
33+
34+ - name : Deploy to gh-pages
35+ run : |
36+ git config user.name "github-actions[bot]"
37+ git config user.email "github-actions[bot]@users.noreply.github.com"
38+
39+ # Remove everything except what we want to deploy
40+ git rm -rf --ignore-unmatch .github node_modules src public build .gitignore package.json package-lock.json tsconfig.json tsconfig.node.json vite.config.ts vite-plugin-save-content.ts README.md deploy.js 2>/dev/null || true
41+
42+ # Add only the files we want to deploy
43+ git add index.html assets/ .nojekyll 2>/dev/null || true
44+
45+ # Commit and push to gh-pages branch
46+ git commit -m "Deploy to GitHub Pages" || exit 0
47+ git push origin HEAD:gh-pages --force
48+
Original file line number Diff line number Diff line change 1919 uses : actions/checkout@v4
2020 with :
2121 fetch-depth : 0 # Fetch all history for git operations
22+ persist-credentials : true # Important for gh-pages action
23+ token : ${{ secrets.GITHUB_TOKEN }}
2224
2325 - name : Set up Node.js
2426 uses : actions/setup-node@v4
@@ -32,12 +34,27 @@ jobs:
3234 - name : Build and Deploy
3335 run : npm run deploy
3436
37+ - name : Verify Git Repository
38+ run : |
39+ pwd
40+ ls -la
41+ git status
42+ git remote -v
43+
44+ - name : Configure Git
45+ run : |
46+ git config --global user.name "github-actions[bot]"
47+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
48+
3549 - name : Deploy to GitHub Pages
3650 uses : peaceiris/actions-gh-pages@v3
51+ if : github.ref == 'refs/heads/master' # Only deploy from master branch
3752 with :
3853 github_token : ${{ secrets.GITHUB_TOKEN }}
3954 publish_dir : ./
55+ destination_dir : ./
4056 cname : false
57+ keep_files : false
4158 exclude_assets : |
4259 .git
4360 .github
You can’t perform that action at this time.
0 commit comments