Skip to content

Had to change the build.yml script to work in GitHub #6

@kuhlaid

Description

@kuhlaid

I was not able to get the GitHub website build script https://github.com/lumeland/base-blog/blob/master/.github/workflows/build.yml to push the static files to a gh-pages branch. I had to modify it slightly to the following:

# This script will build static site files and push them to a `gh-pages` branch of your repository.
# If you are able to go into the `gh-pages` branch and see you static content then the build action
# was successful in GitHub and you can continue on with configuring your repository to publish the 
# content of the `gh-pages` branch to your default repository website (which should look like 
# https://[gitUsername].github.io/[repositoryName]/). To publish this website, 
# in your GitHub repository online, go to Settings/Pages/Build and deployment/Source and choose the
# `Deploy from branch`. Then just below that option choose `gh-pages` as the branch. 
name: Build static files to gh-pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Allow one concurrent deployment
concurrency:
  group: "pages"
  cancel-in-progress: true
  
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Clone repository
        uses: actions/checkout@v3

      - name: Setup Deno environment
        uses: denoland/setup-deno@v1
        with:
          deno-version: v1.x

      - name: Build site
        run: |
          deno task build --location=https://lumeland.github.io/base-blog/

      - name: Push static files to gh-pages branch
        uses: crazy-max/ghaction-github-pages@v3
        with:
          target_branch: gh-pages
          build_dir: _site
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I'm guessing the addition of ...

        with:
          target_branch: gh-pages

...helped create the gh-pages branch and maybe using ghaction-github-pages@v3 helped too, but I didn't do much testing between the current version and this version to see what made the difference. If would like for me to send a PR for this I will.

For what it is worth GitHub Pages does a better job at caching resources out of the box. If using Vercel, I would suggest running this build script on GitHub and instead of telling Vercel to build the site on Vercel. If this script is successful in creating a gh-pages branch in your repository, go to the Git settings within your Vercel project and use the gh-pages branch from GitHub (which would have all of the static site files prebuilt for Vercel). You will also need to include a vercel.json (at least at the time of this writing) to set any caching headers, because Vercel will not cache HTTP resources by default when users make requests to the site. Just my 2cents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions