Configure publishing to github pages #1
Workflow file for this run
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
name: github pages | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
deploy: | |
runs-on: ubuntu-20.04 | |
env: | |
PR_PATH: pull/${{github.event.number}} | |
steps: | |
- name: Comment on PR | |
uses: hasura/[email protected] | |
if: github.ref != 'refs/heads/main' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
repository: ${{ github.repository }} | |
number: ${{ github.event.number }} | |
id: deploy-preview | |
message: "Starting deployment of preview ⏳..." | |
- name: Set domain | |
run: echo "DOMAIN=${{ github.actor }}.github.io" >> $GITHUB_ENV | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
- name: "NPM Install, Build, and Cache" | |
id: npm-install-build-and-cache | |
uses: ./.github/actions/npm-install-build-and-cache | |
- name: "Run Publish Script" | |
run: ./publish/publish.sh | |
- name: Set production base URL | |
run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/" >> $GITHUB_ENV | |
- name: Deploy if this is the `main` branch | |
uses: peaceiris/actions-gh-pages@v3 | |
if: github.ref == 'refs/heads/main' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./publish/build | |
- name: Set base URL for preview if PR | |
if: github.ref != 'refs/heads/main' | |
run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/${{ env.PR_PATH}}/" >> $GITHUB_ENV | |
- name: Deploy to PR preview | |
uses: peaceiris/actions-gh-pages@v3 | |
if: github.ref != 'refs/heads/main' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./publish/build | |
destination_dir: ${{ env.PR_PATH }} | |
- name: Update comment | |
uses: hasura/[email protected] | |
if: github.ref != 'refs/heads/main' | |
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 ✨ ${{ 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 }}/" |