Skip to content

Commit

Permalink
better bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwardius committed May 30, 2024
1 parent 1aff9f5 commit a38d188
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/close_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: delete preview on PR close
on:
pull_request:
types: [closed]

jobs:
delete_preview:
runs-on: ubuntu-latest
env:
PR_PATH: pull/${{github.event.number}}
steps:
- name: make empty dir
run: mkdir public

- name: delete folder
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
destination_dir: ${{ env.PR_PATH }}
cname: wiki.watonomous.ca

- name: Comment on PR
uses: hasura/comment-progress@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "🪓 PR closed, deleted preview at https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/"
40 changes: 29 additions & 11 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
jobs:
build-and-deploy:
runs-on: ubuntu-latest

env:
PR_PATH: pull/${{github.event.number}}
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -23,19 +24,36 @@ jobs:
npm install
npm run export
- name: Deploy to GitHub Pages Preview
uses: peaceiris/actions-gh-pages@v4
- name: Comment on PR
uses: hasura/comment-progress@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "Starting deployment of preview ⏳..."

- name: Set base URL for preview if PR
run: echo "BASE_URL=https://wiki.watonomous.ca/${{ github.event.repository.name }}/${{ env.PR_PATH}}/" >> $GITHUB_ENV

- name: Build PR preview website
run: hugo --baseURL "${{ env.BASE_URL }}"
env:
HUGO_ENV: staging

- name: Deploy to PR preview
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
publish_branch: gh-pages-preview-${{ github.event.pull_request.number }}
destination_dir: ${{ env.PR_PATH }}
cname: wiki.watonomous.ca

- name: Comment on the PR with the preview link
uses: peter-evans/commit-comment@v2
- name: Update comment
uses: hasura/comment-progress@v2.2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
🚀 Preview of the changes is available at:
https://${{ github.repository_owner }}.github.io/${{ github.repository }}/gh-pages-preview-${{ github.event.pull_request.number }}
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }} ✨\n\nChanges may take a few minutes to propagate. Since this is a preview of production, content with `draft: true` will not be rendered. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/"

0 comments on commit a38d188

Please sign in to comment.