Github action not triggering gh-pages upon push

For some reason when pushing towards gh-pages branch from within a github action the commit appears to be correctly pushed towards the branch but does not trigger github pages deployments (within environment tabs).

Do you have any advice on what i could have a look at?

Project https://github.com/ivoputzer/github-page

Workflow https://github.com/ivoputzer/github-page/blob/master/.github/main.workflow

28 Likes

The GITHUB_TOKEN that is provided as a part of GitHub Actions doesn’t have authorization to create any successive events, such as GitHub Pages builds. So while you can push to the gh-pages branch using the GITHUB_TOKEN, it won’t spawn a GitHub Pages build. You’ll need to create a personal access token and supply it to your GitHub Action as a secret. 

I used https://github.com/peaceiris/actions-gh-pages for a recent project because it already has a workaround for exactly this problem and seems to be actively maintained.

I hope that helps!

9 Likes

Thanks, now we have a pretty straightforward answer about that issue :slight_smile: . Basically it’s not a bug but a design decision.

On the other hand it is kind of a usability issue. This behavior makes it impossible to have a “copy and paste” workflow configuration or a “fork and publish” repository that will just build a repository and publish it to Github’s web hosting without complex additional configuration. (Like it’s possible to do so with both Gitlab and Bitbucket as example.)

Is there any chance this usability problem could be considered by the dev team to create some kind of specific exception for static web content publishing?

5 Likes

It’s something that we should give some more thought to, but we need to weigh that with the more common usability concern of push triggers within push triggers.  Given this common workflow trigger:

on: [push, pull_request]
jobs:
publish:
steps:
run: build_site && git push origin gh-pages

If you were to update a gh-pages branch in this workflow, you’d get into an infinite loop - your first workflow would push the gh-pages branch, which would trigger this workflow, ad infinitum.

Obviously you could construct a less naive workflow that filters based on branches, or only pushes when changes are detected, etc.  (Perhaps this will coincidentally no-op because there’s no changes in the source branch.)  But it’s a concern and that’s why we’re limitation workflow execution in this way from the token.

I’ve logged an issue to give this particular workflow consideration some more thought.  We should improve the guidance, at least, even if we don’t relax the token restrictions.

3 Likes

Mea culpa - I was wrong about the reason that this wasn’t working.  In fact, there was an issue occurring between GitHub Actions and GitHub Pages.  We made some changes to GitHub Pages that we think should have mitigated this isssue.

Here’s an example that should work:

# pushes using the user that kicked off the action. Requires `jq` in the builder
git config user.name $(jq .pusher.username $GITHUB_PAYLOAD)
git config user.email $(jq .pusher.email $GITHUB_PAYLOAD)

git add --all
git commit -m "Publish to gh-pages branch"
git remote add pages https://x-access-token:$GITHUB_TOKEN@github.com/:owner/:repo.git
git push pages gh-pages -f

@ivoputzer and @nicolas-van could you try your workflow again and let me know if it still isn’t working?

3 Likes

To visitors, (2020-05-03)

This problem has been already fixed about 3 months ago.

Now, the GITHUB_TOKEN works well for deploying to GitHub Pages on public repositories and private repositories.

peaceiris/actions-gh-pages: GitHub Actions for GitHub Pages 

- uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./public




Old message:

@ethomson 

I tried it using peaceiris/actions-gh-pages but GitHub Pages building does not start. Action log

1 Like

Thanks @peaceiris , investigating further.

6 Likes

Hi @ethomson 

I found it. The following step works well for only my private repo. For private repositories, GITHUB_TOKEN works well but public repositories failed. Is this an expected behavior?

- name: Deploy
  uses: peaceiris/actions-gh-pages@v2.4.0
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    PUBLISH_BRANCH: gh-pages
    PUBLISH_DIR: ./public

Issues #9 | peaceiris/actions-gh-pages

5 Likes

I have a similar workflow/action using GITHUB_TOKEN in a priviate repository. And pushes to gh-pages will be picked up by Github Pages without a problem—but the repo has to be private. When I make it public, the environment does not seem to get updated.

7 Likes

It would be really handy if GitHub Actions can trigger GitHub Pages build using GITHUB_TOKEN.

You can do the “workaround” https://github.com/peaceiris/actions-gh-pages#1-add-ssh-deploy-key using SSH deploy keys, but it’s adding complexity and I’m not sure if this can be automated if you have many GitHub repos.

When you use GITHUB_TOKEN there is nothing to configure - you just create “GitHub Action” and you are done.

Thank you…

3 Likes

It seems to have been established that it is a bug by now. The fact it works as expected with private repositories, like reported by @bryanschuetz and tested by @peaceiris , but not with public repositories is an inconsistency in itself that can not be considered in another way than a bug.

Let’s just hope that the Github team will solve it one day or another ^^

17 Likes

I can confirm that a Private repository does “fix” the issue. It’s still a bit of a weird scenario and the error message really doesn’t help troubleshooting the issue :slight_smile:

3 Likes

I ran into this issue too.

https://github.com/rhysd/github-action-benchmark

While I was developing the action in private repository, it worked fine. But once I published it, deploying gh-pages started to fail.

2 Likes

Finally, GitHub Actions is going to be GA today. Thank you, the GitHub support team and the community. Also, I hope that this issue will be considered after Actions become stable.

2 Likes

As of last week I’m not even able to deloy using an access token anymore. Has something changed? I just end up with Page Build Errorr everytime. 

Edit: This was resolved by changing actions/checkout@master to actions/checkout@v1.

4 Likes

@ethomson Just re-iterating that this is still not working for public repositories, even after the General Availablity. You can push to the gh-pages branch with a GITHUB_TOKEN, but the push does not trigger a GitHub pages deploy.

Doing something else to trigger a deploy (like a manual empty commit) does trigger a deploy with the updated content however.

5 Likes

Seeing this same issue in my public repo. My action is setup on a schedule, so the ‘avoiding recursive actions’ feature should not even apply to this action. Also, I’m using checkout@v2. Action: https://github.com/lightswitch05/php-version-audit/blob/master/.github/workflows/auto-updates.yml

2 Likes

Also experienced this issue. Pushing to public repo with ${{ secrets.GITHUB_TOKEN }} does not trigger a successful github pages build. Manual workaround is to change the branch which github pages is to deploy for a moment and then change it back to the original branch.

2 Likes
- name: Deploy
      uses: peaceiris/actions-gh-pages@v2.8.0
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        PUBLISH_BRANCH: master
        PUBLISH_DIR: ./public
      with:
        keepFiles: true

I modify my  configuration here , now it is success. You should add  SSH deploy key following this :

https://github.com/marketplace/actions/github-pages-action#1-add-ssh-deploy-key

1 Like

@lovepoem, as commented in https://github.com/actions/checkout/issues/75#issuecomment-568468352, using a deployment key is not a solution, but an (uncomfortable) workaround. The default GITHUB_TOKEN allows to push changes to a branch of the same repo (which can be ‘gh-pages’). The issue is on GitHub’s deployment feature refusing to pick the commits pushed by the bot.