Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kuhlaid opened this issue Oct 5, 2022 · 1 comment
Open

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

kuhlaid opened this issue Oct 5, 2022 · 1 comment

Comments

@kuhlaid
Copy link

kuhlaid commented Oct 5, 2022

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.

@oscarotero
Copy link
Member

I don't see any significant differency between your configuration and the existing one in this repo. The gh-pages branch name is the default, so I think it's not required. Maybe the upgrade to ghaction-github-pages@v3 would be a nice change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants