-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Build and deploy new PR site preview | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened] | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
pull-requests: write # GitHub Actions bot permissions | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Comment on PR | ||
uses: hasura/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
repository: ${{ github.repository }} | ||
number: ${{ github.event.number }} | ||
id: deploy-preview | ||
message: "Starting deployment of preview ⏳..." | ||
- name: Checkout and setup node | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: npm | ||
cache-dependency-path: "./package-lock.json" | ||
|
||
- name: Create dotenv | ||
run: | | ||
echo "SITE_URL=https://dallyh.github.io/" >> .env | ||
echo "SITE_BASE=/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/" >> .env | ||
- name: Install Node dependencies | ||
run: npm install | ||
|
||
- name: Build the site | ||
run: npm run build | ||
|
||
- name: Upload site artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: site | ||
path: ./dist/ | ||
|
||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: pull-request-preview | ||
url: https://dallyh.github.io/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/ | ||
|
||
steps: | ||
- name: Download the artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: site | ||
path: ./dist/ | ||
|
||
- name: Upload files to GitHub Pages | ||
uses: cpina/[email protected] | ||
env: | ||
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} | ||
with: | ||
source-directory: "./dist/" | ||
destination-github-username: ${{ github.actor }} | ||
destination-repository-name: "deploy-previews" | ||
target-branch: main | ||
target-directory: "${{ github.event.repository.name }}/${{ github.event.pull_request.number }}" | ||
|
||
- name: Output the URL | ||
run: echo "https://dallyh.github.io/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/" | ||
|
||
- name: Update comment | ||
uses: hasura/[email protected] | ||
with: | ||
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 ✨ https://dallyh.github.io/deploy-previews/${{ github.event.repository.name }}/${{ github.event.pull_request.number }}/ ✨\n\nPlease note that it may take a few seconds for GitHub Pages to build and deploy." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters