(ci/github): Add gh-pages step to build job #22
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: Build | |
on: | |
push: | |
pull_request: | |
jobs: | |
build: | |
name: Test Build | |
runs-on: ubuntu-latest | |
permissions: | |
checks: write # Create checks for commits | |
pull-requests: write # Add comments to PRs | |
contents: write # Push changes (to gh-pages) | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: latest | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
cache: "pnpm" | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build site | |
run: npm run build | |
- name: Send bundle stats to RelativeCI | |
uses: relative-ci/agent-action@v2 | |
with: | |
webpackStatsFile: ./webpack-stats.json | |
key: ${{ secrets.RELATIVE_CI_KEY }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Zip up the public directory | |
run: cd public && zip -r ../site.zip ./ | |
- name: Upload zipped site as an artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: site | |
path: site.zip | |
- name: Determine the size of the zip file | |
id: determineSize | |
# Save to GITHUB_OUTPUT | |
run: echo "SIZE=$(du -sh site.zip | cut -f1)" >> $GITHUB_OUTPUT | |
- name: Create a neutral check with the zipped size | |
uses: LouisBrunner/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
name: "Build Size" | |
conclusion: neutral | |
output: | | |
{"title":"${{ steps.determineSize.outputs.SIZE }} (of 5M)","summary":"${{ steps.determineSize.outputs.SIZE }} (of 5M)"} | |
- name: Upload to netlify (if a PR build) | |
if: github.event_name == 'pull_request' | |
uses: nwtgck/[email protected] | |
with: | |
publish-dir: ./public | |
production-deploy: false | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
deploy-message: ${{ github.event.pull_request.title }}) | |
enable-pull-request-comment: true | |
enable-commit-comment: false | |
enable-commit-status: true | |
overwrites-pull-request-comment: true | |
# replicate deploy preview prefix | |
alias: deploy-preview-${{ github.event.pull_request.number }} | |
enable-github-deployment: false # seems to not be a valid option? (not in schema?) | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
timeout-minutes: 1 | |
- name: Push to "gh-pages" (if push on main) | |
if: github.ref == 'refs/heads/master' && github.event_name == 'push' | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
folder: public |