Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Last active September 4, 2020 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arthurattwell/ac7d2d1c310eea6eac63727db4193ec7 to your computer and use it in GitHub Desktop.
Save arthurattwell/ac7d2d1c310eea6eac63727db4193ec7 to your computer and use it in GitHub Desktop.
Trigger a GitHub Pages rebuild
#!/bin/bash
# This script will trigger a rebuild on a repo's GitHub Pages site,
# without having to create a new commit.
# To use this script:
# 1. Save this script to an easilyt accessible place, where you'll run it.
# 2. Create a personal access token on GitHub. In Your profile > Settings
# > Developer settings > Personal access tokens
# 3. Save the token in a text file. Idealy, alongside the script as token.txt
# 4. Run the script from the Terminal with ./trigger-gh-pages-build.sh
# 5. It will ask you for your GitHub username, the repo name, and the token file.
#
# Thanks to https://stackoverflow.com/a/54088985/1781075
echo "GitHub username"
read yourname
echo "GitHub repo name"
read yourrepo
echo "Path to GitHub token, e.g. token.txt"
echo "Hit enter for default token.txt"
read yourtokenpath
if [[ $yourtokenpath = "" ]];
then
yourtokenpath="token.txt"
fi
yourtoken=$(cat $yourtokenpath)
echo "Triggering GitHub Pages rebuild on"
echo "$yourname/$yourrepo using token $yourtoken"
curl -u $yourname:$yourtoken -X POST https://api.github.com/repos/$yourname/$yourrepo/pages/builds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment