diff --git a/.github/workflows/build_pr_preview.yml b/.github/workflows/build_pr_preview.yml index d48ed89..5299e18 100644 --- a/.github/workflows/build_pr_preview.yml +++ b/.github/workflows/build_pr_preview.yml @@ -5,6 +5,12 @@ on: branches: - main +permissions: + contents: write + pull-requests: write + pages: write + id-token: write + jobs: build: runs-on: ubuntu-latest @@ -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 @@ -27,20 +33,23 @@ jobs: run: | git config --global user.name "github-actions" git config --global user.email "actions@github.com" - 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, diff --git a/.github/workflows/cleanup_pr_preview.yml b/.github/workflows/cleanup_pr_preview.yml new file mode 100644 index 0000000..bc2de70 --- /dev/null +++ b/.github/workflows/cleanup_pr_preview.yml @@ -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 "actions@github.com" + 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