How to force GitHub Pages build?
Asked Answered
A

12

145

Every GitHub repository can have (or be) a GitHub Pages website, that can be built with Jekyll. GitHub builds the site every time you push a new commit.
Is there a way to force the refresh of the Github Pages website without pushing a new commit?

Antique answered 7/6, 2014 at 15:35 Comment(3)
Maybe this is in line with their cache policy? (https://mcmap.net/q/161066/-determining-a-page-is-outdated-on-github-pages)Youngling
Actually, you could contact GitHub support for a confirmation, and post an answer here. That could help others.Youngling
According to the documentation, github pages have a limit of 10 builds per hour. In my experience, if you go over the limit a new build is not triggered, even if you push a new commit.Cattima
A
185

From GitHub support, 2014-06-07:

It's not currently possible to manually trigger a rebuild, without pushing a commit to the appropriate branch.


Edit:

As Andy pointed out in the comments, you can push an empty commit with the command:

git commit -m 'rebuild pages' --allow-empty
git push origin <branch-name>

Edit 2:

Thanks to GitHub Actions, it's fairly easy to trigger a daily publish: https://mcmap.net/q/158554/-how-to-force-github-pages-build.

Antique answered 7/6, 2014 at 16:34 Comment(2)
If you are lucky like me, also check Github status because they might be down or having issues with background jobs/builds.Calabresi
tl,dr git logIntertype
A
26

If you want a quick script solution, here it is. Just do the following tasks only once, and run the script whenever you want to rebuild your GitHub page.

1. Create a personal access token for the command line:

  • Follow the official help here to create a personal access token. Basically, you have to log in your GitHub account and go to: Settings > Developer settings > Personal access tokens > Generate new token.
  • Tick repo scope.
  • Copy the token.

2. Create the following script:

  • Create a file called RebuildPage.sh and add the lines:

    #!/bin/bash
    curl -u yourname:yourtoken -X POST https://api.github.com/repos/yourname/yourrepo/pages/builds
    

    Here,

    • Replace yourname with your GitHub username.
    • Replace yourtoken with your copied personal access token.
    • Replace yourrepo with your repository name.

3. Run the script:

  • If you use Windows 10:

    • You need to setup Windows Subsystem for Linux, if not already done. Follow this to do so.
    • Remove the first line (#!/bin/bash) from the script and save the script as RebuildPage.bat. (i.e., replace .sh with .bat in the script file name)
    • Alternative to the above point: To get the double-click feature for running the .sh file:

      • Set bash.exe as the default program for .sh files.
      • Open regedit.exe and edit HKEY_CLASSES_ROOT\Applications\bash.exe\shell\open\command. Set the (Default) value to:

        "C:\Windows\System32\bash.exe" -c " \"./$(grep -oE '[^\\]+$' <<< '%L')\";"
        
    • Now double-click the script wheneven you want to rebuild your GitHub page. Done!

  • If you use Linux/Mac, running the script is as same as running other scripts. Done!

Additional notes for the solution:

This solution utilizes a API of GitHub REST API v3. Here is the official documentation for the API.

Abbreviation answered 8/1, 2019 at 9:40 Comment(1)
Thanks a lot! GH docs isn't clear about what permissions pages requires to trigger builds, so your reply helped a lot. Cheers o/Mcgehee
A
19

Now that GitHub Actions are available, this is trivial to do:

# File: .github/workflows/refresh.yml
name: Refresh

on:
  schedule:
    - cron:  '0 3 * * *' # Runs every day at 3am

jobs:
  refresh:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger GitHub pages rebuild
        run: |
          curl --fail --request POST \
            --url https://api.github.com/repos/${{ github.repository }}/pages/builds \
            --header "Authorization: Bearer $USER_TOKEN"
        env:
          # You must create a personal token with repo access as GitHub does
          # not yet support server-to-server page builds.
          USER_TOKEN: ${{ secrets.USER_TOKEN }}

Sample repo that does this: https://github.com/SUPERCILEX/personal-website/actions

Pages API: https://developer.github.com/v3/repos/pages/#request-a-page-build

Aidaaidan answered 10/5, 2020 at 1:24 Comment(1)
Isnt the USER_TOKEN getting added to build branch ? , it gets automatically deleted for me while using a react app build as it adds static chuck js in the gh-pages branchPonce
M
8

I had this problem for a while, and pushing to master branch didn't change anything on myapp.github.io, for two reasons :

1 - Build

No matter how many time I tried to push my work on master, build would not start. I found a workaround by modifying my file in Github online editor (open your index.html and edit it on Github website, then commit)

2 - Caching issues

Even after a successful build, I would still see the exact same page on myapp.github.io, and hard reloading with Ctrl + Shift + R wouldn't solve it. Instead, if using Chrome, inspect your page, head into the Application tab, select "Clear storage" in the left menu, and click on "Clear site data" at the bottom of the menu.

Mercedes answered 18/9, 2018 at 15:3 Comment(0)
N
7

This is doable as of v3 of the GitHub API, though it is currently in preview https://developer.github.com/v3/repos/pages/#request-a-page-build

POST /repos/:owner/:repo/pages/builds
Neocolonialism answered 17/12, 2018 at 23:44 Comment(1)
Looks like the docs have moved to this URL: docs.github.com/en/rest/reference/…Chiron
F
7

Even after I pushed my changes to GitHub repository, I was not able to see the changes today. Then I checked my repository settings for more information, there I could see, all these times the build was failing and that was the reason I was not able to see the changes.

enter image description here

You may also see a message as "Your site is having problems building: Unable to build page. Please try again later."

Then I was checking my recent commits and tried to find out what causes this issue. At the end I was able to fix the issue.

enter image description here

There was an additional comma in the tags (,) and that caused this issue.

enter image description here

You will not get relevant error messages if there are any issues in your .md file. I recommend you to check for the build status and compare the changes if you are facing the same issue.

Fatherinlaw answered 16/6, 2019 at 11:7 Comment(0)
L
6

The empty commit didn't work for me, but based on @benett answer, this worked for me:

Open Postman, create a new request with this URL: https://api.github.com/repos/[user_name]/[repo_name]/pages/builds (replace with your name and repo), and select POST method.

Before you run it, go to the headers tab and add a new key Accept with the value application/vnd.github.mister-fantastic-preview+json

Now you can run it and visit your pages again.

Lamentation answered 19/12, 2018 at 0:23 Comment(2)
This doesn't work for me, I get { "message": "Not Found", "documentation_url": "https://developer.github.com/v3/repos/pages/#request-a-page-build" }. Maybe because my repo is private?Jorgenson
I have the same message "Not Found" problem but my repo is public.Aristotelian
M
4

I was having trouble refreshing even though my Github Actions was showing that my site has been deployed.

Toggling the publishing source did the trick for me. I switched the publishing source from master to content and then back to master. You can check how to change the publishing source of the branch here

Malleolus answered 19/11, 2020 at 20:35 Comment(0)
P
2

I went through the same problem, to solve it I developed a githu action that works with scheduler and supports updating multiple gh-pages at the same time.

https://github.com/marketplace/actions/jekyll-update-github-pages-without-new-commit, the action update gh-pages without generate new commits.

name: Update all github pages

on:
  schedule:
    - cron: "30 0 * * *"

jobs:
  github-pages:
    runs-on: ubuntu-latest
    name: Update Github Pages Initiatives
    steps:
    - name: Jekyll update github pages without new commit
      uses: DP6/[email protected]
      with:
        DEPLOY_TOKEN: ${{ secrets.GH_PAGES_DEPLOY_TOKEN }}
        USER: ${{ secrets.GH_PAGES_USER }}
        FILTER:  'is%3Apublic%20org%3Adp6'

Log action

Pensioner answered 7/4, 2021 at 12:51 Comment(0)
C
0

Alternative Solution

You may have received an email from GitHub telling you that Jekyll did not succeed at building your site when you pushed it to your gh-pages. If this is the case, you can try to force push to trigger another build.

If you use a dedicated folder for the final website, let's say a public folder, you can try to rebuild your folder and add the folder to your commited changes. After that, you'll need to split those file into your gh-pages branch and force them to trigger another build even if the files did not change at all. The rest of the code bellow just removes the commits for the public folder for convenience and removes it from the local filesystem.

Code

git add public
git commit -am ":bug: triggering another jekyll build"
git push origin $(git subtree split --prefix public master):gh-pages --force
git reset HEAD~1
rm -rf public

Tips

If there are uncommited changes that are not part of the final site, you can stash them with the following command.

git stash

Then do the above command to manually force the Jekyll build and unstash them.

git stash pop

References

Complemental answered 17/11, 2018 at 18:29 Comment(0)
P
0

I surmise from other answers that this was once difficult?

  1. Go to Settings->Pages
  2. Just under "Change theme" you'll see a link to the actual Github action labeled "pages build and deployment workflow".
  3. Click Re-run all jobs
Passed answered 18/8, 2022 at 2:34 Comment(0)
E
0

I had this problem today: I'm a beginner doing a lot of things through Git web version: even though GitHub/Settings/Pages showed "Deployed 3 minutes ago" I could see the HTML in my Pages site was not updated.

However, also in settings it had "Your site was last deployed to the github-pages environment by the pages build and deployment workflow" which was a link to Actions on main page.

In GitHub web, on top menu bar, click "Actions" and you have a filter to show either all runs, or runs related to "pages-build-deployment". It seemed a bit strange there wasn't a way to run more directly, but by clicking one of the previous build runs, which are titled without hyphen "pages build deployment" that will then take you to the build screen and you can select "Re-run all jobs"

https://i.stack.imgur.com/2Bsu4.png

Exhibitive answered 7/4, 2023 at 5:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.