Skip to content

Commit e09dac1

Browse files
authored
ci: deploy by building on gh-pages branch (#15)
1 parent 94d1771 commit e09dac1

5 files changed

Lines changed: 346 additions & 18 deletions

File tree

.github/workflows/build.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run ts and eslint checks
1+
name: Deploy to gh-pages branch
22

33
on:
44
push:
@@ -8,36 +8,50 @@ on:
88

99
permissions:
1010
contents: write
11-
pages: write
12-
id-token: write
1311

1412
jobs:
15-
deploy:
13+
deploy-on-gh-pages-branch:
1614
runs-on: ubuntu-latest
1715

1816
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v3
17+
- name: Checkout main branch
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
2121

2222
- name: Setup Node.js
23-
uses: actions/setup-node@v3
23+
uses: actions/setup-node@v4
2424
with:
2525
node-version: 22
26-
27-
- name: Install Git
28-
run: sudo apt-get install git -y
26+
cache: npm
2927

3028
- name: Configure git user
3129
run: |
3230
git config user.name "github-actions[bot]"
3331
git config user.email "github-actions[bot]@users.noreply.github.com"
3432
33+
- name: Switch to gh-pages branch and merge main
34+
run: |
35+
git fetch origin gh-pages || true
36+
if git show-ref --verify --quiet refs/remotes/origin/gh-pages; then
37+
git switch -c gh-pages --track origin/gh-pages
38+
else
39+
git switch --create gh-pages
40+
fi
41+
git merge main --allow-unrelated-histories -m "Merge from main branch" || echo "Already up to date"
42+
3543
- name: Install dependencies
36-
run: npm install
44+
run: npm ci
3745

38-
- name: Eslint checks
46+
- name: Run ESLint
3947
run: npm run eslint
4048

41-
- name: Building test
49+
- name: Build project
4250
run: npm run build
4351

52+
- name: Commit and push gh-pages
53+
run: |
54+
git add -A
55+
git commit -m "Deploy from main to gh-pages" || echo "No changes to commit"
56+
git pull --rebase origin gh-pages || echo "Nothing to rebase"
57+
git push origin gh-pages -f

0 commit comments

Comments
 (0)