Skip to content

Commit 3ddf137

Browse files
committed
πŸ› fix PR preview workflow
1 parent 864741a commit 3ddf137

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

β€Ž.github/workflows/build_pr_preview.ymlβ€Ž

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
permissions:
9-
contents: write
9+
contents: read
1010
pull-requests: write
1111
pages: write
1212
id-token: write
@@ -27,22 +27,23 @@ jobs:
2727
run: bundle install
2828

2929
- name: Build Jekyll site
30-
run: bundle exec jekyll build
30+
run: bundle exec jekyll build --baseurl "/pull/${{ github.event.number }}" --destination _site
3131

32-
- name: Deploy to Preview Branch
33-
run: |
34-
git config --global user.name "github-actions"
35-
git config --global user.email "[email protected]"
36-
37-
git clone --branch gh-pages https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git preview
38-
mkdir -p preview/pull/${{ github.event.number }}
39-
cp -r _site/* preview/pull/${{ github.event.number }}/
40-
cd preview
41-
git add .
42-
git commit -m "Deploy PR #${{ github.event.number }} preview"
32+
- name: Upload Pages artifact
33+
uses: actions/upload-pages-artifact@v4
34+
with:
35+
path: _site
4336

44-
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
45-
git push origin gh-pages
37+
deploy:
38+
environment:
39+
name: github-pages
40+
url: ${{ steps.deployment.outputs.page_url }}
41+
runs-on: ubuntu-latest
42+
needs: build
43+
steps:
44+
- name: Deploy to GitHub Pages
45+
id: deployment
46+
uses: actions/deploy-pages@v4
4647

4748
- name: Comment PR with Preview URL
4849
uses: actions/github-script@v6
@@ -53,5 +54,5 @@ jobs:
5354
issue_number: context.issue.number,
5455
owner: context.repo.owner,
5556
repo: context.repo.repo,
56-
body: `πŸš€ PR Preview: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pull/${{ github.event.number }}`
57+
body: `πŸš€ PR Preview: ${{ steps.deployment.outputs.page_url }}`
5758
})

0 commit comments

Comments
Β (0)