Search code examples
github-pagesgithub-actionsgithub-pages-deploy-action

github pages issue when using github actions and github-pages-deploy-action?


I have simple github repo where I host the content of my CV. I use hackmyresume to generate the index.html. I'm using Github Actions to run the npm build and it should publish the generated content to the gh-pages branch.

My workflow file has

on:
push:
    branches:
    - master

jobs:
build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Deploy with github-pages
    uses: JamesIves/github-pages-deploy-action@master
    env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        BASE_BRANCH: master # The branch the action should deploy from.
        BRANCH: gh-pages # The branch the action should deploy to.
        FOLDER: target # The folder the action should deploy.
        BUILD_SCRIPT: npm install && npm run-script build

And the build command is

"build": "hackmyresume BUILD ./src/main/resources/json/fresh/resume.json target/index.html -t compact",

I can see the generated html file getting committed to the github branch

https://github.com/emeraldjava/emeraldjava/blob/gh-pages/index.html

but the gh-page doesn't pick this up? I get a 404 error when i hit

https://emeraldjava.github.io/emeraldjava/

I believe my repo setting and secrets are correct but I must be missing something small. Any help would be appreciated.


Solution

  • This is happening because of your use of the GITHUB_TOKEN variable. There's an open issue with GitHub due to the fact that the built in token doesn't trigger the GitHub Pages deploy job. This means you'll see the files get committed correctly, but they won't be visible.

    To get around this you can use a GitHub access token. You can learn how to generate one here. It needs to be correctly scoped so it has permission to push to a public repository. You'd store this token in your repository's Settings > Secrets menu (Call it something like ACCESS_TOKEN), and then reference it in your configuration like so:

    on:
    push:
        branches:
        - master
    
    jobs:
    build:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v1
        - name: Deploy with github-pages
        uses: JamesIves/github-pages-deploy-action@master
        env:
            ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
            BASE_BRANCH: master # The branch the action should deploy from.
            BRANCH: gh-pages # The branch the action should deploy to.
            FOLDER: target # The folder the action should deploy.
            BUILD_SCRIPT: npm install && npm run-script build
    

    You can find an outline of these variables here. Using an access token will allow the GitHub Pages job to trigger when a new deployment is made. I hope that helps!