Skip to content

Commit 64e209f

Browse files
update Pages deploy actions
1 parent 0398d24 commit 64e209f

2 files changed

Lines changed: 96 additions & 22 deletions

File tree

.github/workflows/pages-preview.yml

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@ concurrency:
88
cancel-in-progress: true
99

1010
permissions:
11-
contents: write
11+
contents: read
12+
pages: write
13+
id-token: write
1214

1315
jobs:
1416
deploy-preview:
1517
name: Build & deploy /preview from main
1618
runs-on: ubuntu-latest
19+
environment:
20+
name: github-pages
21+
url: ${{ steps.deployment.outputs.page_url }}
1722

1823
steps:
1924
- name: Checkout main
2025
uses: actions/checkout@v5
2126
with:
2227
ref: main
23-
fetch-depth: 1
28+
fetch-depth: 0
2429

2530
- name: Setup Node
2631
uses: actions/setup-node@v6.4.0
@@ -34,14 +39,50 @@ jobs:
3439
- name: Build
3540
run: npm run build
3641

37-
# Deploy dist/ into gh-pages/preview/
38-
- name: Deploy to gh-pages (preview)
39-
uses: peaceiris/actions-gh-pages@v4
42+
- name: Prepare preview site
43+
run: |
44+
rm -rf pages-site
45+
mkdir -p pages-site/preview
46+
cp -R dist/. pages-site/preview/
47+
48+
- name: Resolve latest stable tag
49+
id: stable
50+
run: |
51+
latest_tag="$(git tag --list 'v*' --sort=-v:refname | head -n 1)"
52+
if [ -z "$latest_tag" ]; then
53+
echo "No stable release tag found." >&2
54+
exit 1
55+
fi
56+
echo "tag=$latest_tag" >> "$GITHUB_OUTPUT"
57+
58+
- name: Checkout latest stable tag
59+
uses: actions/checkout@v5
60+
with:
61+
ref: ${{ steps.stable.outputs.tag }}
62+
path: stable-source
63+
fetch-depth: 1
64+
65+
- name: Install stable dependencies
66+
working-directory: stable-source
67+
run: npm ci
68+
69+
- name: Build stable
70+
working-directory: stable-source
71+
run: npm run build
72+
73+
- name: Add stable site
74+
run: |
75+
cp -R stable-source/dist/. pages-site/
76+
touch pages-site/.nojekyll
77+
78+
- name: Configure Pages
79+
uses: actions/configure-pages@v6
80+
81+
- name: Upload Pages artifact
82+
uses: actions/upload-pages-artifact@v5
4083
with:
41-
github_token: ${{ secrets.GITHUB_TOKEN }}
42-
publish_branch: gh-pages
43-
publish_dir: ./dist
44-
destination_dir: preview
45-
keep_files: true
46-
enable_jekyll: false
47-
commit_message: "Deploy preview (main) ${{ github.sha }}"
84+
path: pages-site
85+
86+
- name: Deploy to GitHub Pages
87+
id: deployment
88+
uses: actions/deploy-pages@v5

.github/workflows/pages-prod.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ concurrency:
1010
cancel-in-progress: false
1111

1212
permissions:
13-
contents: write
13+
contents: read
14+
pages: write
15+
id-token: write
1416

1517
jobs:
1618
deploy-prod:
1719
name: Build & deploy production (tag)
1820
runs-on: ubuntu-latest
21+
environment:
22+
name: github-pages
23+
url: ${{ steps.deployment.outputs.page_url }}
1924

2025
steps:
2126
- name: Checkout tag
@@ -39,13 +44,41 @@ jobs:
3944
- name: Assert build output exists
4045
run: test -f dist/index.html
4146

42-
# Deploy dist/ to gh-pages root
43-
- name: Deploy to gh-pages (production)
44-
uses: peaceiris/actions-gh-pages@v4
47+
- name: Prepare production site
48+
run: |
49+
rm -rf pages-site
50+
mkdir -p pages-site
51+
cp -R dist/. pages-site/
52+
touch pages-site/.nojekyll
53+
54+
- name: Checkout main for preview
55+
uses: actions/checkout@v5
56+
with:
57+
ref: main
58+
path: preview-source
59+
fetch-depth: 1
60+
61+
- name: Install preview dependencies
62+
working-directory: preview-source
63+
run: npm ci
64+
65+
- name: Build preview
66+
working-directory: preview-source
67+
run: npm run build
68+
69+
- name: Add preview site
70+
run: |
71+
mkdir -p pages-site/preview
72+
cp -R preview-source/dist/. pages-site/preview/
73+
74+
- name: Configure Pages
75+
uses: actions/configure-pages@v6
76+
77+
- name: Upload Pages artifact
78+
uses: actions/upload-pages-artifact@v5
4579
with:
46-
github_token: ${{ secrets.GITHUB_TOKEN }}
47-
publish_branch: gh-pages
48-
publish_dir: ./dist
49-
keep_files: true
50-
enable_jekyll: false
51-
commit_message: "Deploy production ${{ github.ref_name }}"
80+
path: pages-site
81+
82+
- name: Deploy to GitHub Pages
83+
id: deployment
84+
uses: actions/deploy-pages@v5

0 commit comments

Comments
 (0)