Skip to content

Commit

Permalink
Add github actions to deploy preview pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-youssef-bitwarden committed Dec 19, 2024
1 parent 2f80c4d commit 42fa9e5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/cleanup-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Cleanup PR Preview
on:
pull_request:
types: [closed]

permissions:
contents: write

jobs:
cleanup:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: gh-pages

- name: Delete PR Preview
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
rm -rf pr-preview/pr-${{ github.event.pull_request.number }}
git add .
git commit -m "Remove PR preview for #${{ github.event.pull_request.number }}"
git push origin gh-pages
59 changes: 59 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy PR Preview
on:
pull_request:
types: [opened, synchronize, reopened]

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

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout your repository using git
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Add PR number to Astro config for base path
- name: Update base path
run: |
echo "export default { base: '/pr-preview/pr-${{ github.event.pull_request.number }}' };" > astro.config.mjs
- name: Install, build, and upload your site output
uses: withastro/action@44cbafd43567733e3b007918c6e0711480560516 # v3.0.0
with:
path: dist/pr-${{ github.event.pull_request.number }}

deploy:
needs: build
runs-on: ubuntu-22.04
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}/pr-preview/pr-${{ github.event.pull_request.number }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

- name: Find Comment
uses: peter-evans/find-comment@a54c31d9fa01c18cba0a010a6a14bfa61fd9c44c # v3.0.0
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Preview deployment is ready!

- name: Create or Update Preview Comment
uses: peter-evans/create-or-update-comment@23ff15bd0ed82dd24f88c2d417cd6e8d5f2c203d # v4.0.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Preview deployment is ready!
🚀 Preview URL: ${{ steps.deployment.outputs.page_url }}/pr-preview/pr-${{ github.event.pull_request.number }}
_Updated at: ${{ github.event.pull_request.updated_at }}_
edit-mode: replace

0 comments on commit 42fa9e5

Please sign in to comment.