Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/build_pr_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
branches:
- main

permissions:
contents: write
pull-requests: write
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -14,7 +20,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.x
ruby-version: '3.2.0'
bundler-cache: true

- name: Install dependencies
Expand All @@ -27,20 +33,23 @@ jobs:
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git clone --branch gh-pages https://github.com/${{ github.repository }} preview

git clone --branch gh-pages https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git preview
mkdir -p preview/pull/${{ github.event.number }}
cp -r _site/* preview/pull/${{ github.event.number }}/
cd preview
git add .
git commit -m "Deploy PR #${{ github.event.number }} preview"

git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push origin gh-pages

- name: Comment PR with Preview URL
uses: actions/github-script@v6
with:
github-token: ${{ secrets.MY_GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/cleanup_pr_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Clean PR Preview

on:
pull_request:
types: [closed]
branches:
- main

permissions:
contents: write

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: gh-pages
token: ${{ secrets.GITHUB_TOKEN }}

- name: Remove PR preview
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
if [ -d "pull/${{ github.event.number }}" ]; then
rm -rf pull/${{ github.event.number }}
git add .
git commit -m "🗑️ Remove PR #${{ github.event.number }} preview"
git push origin gh-pages
fi