Brian
Brian

Reputation: 253

How can I programmatically add resources to a GitHub Page?

I have a GitHub App set up to pull some data, authenticate with an installation token, and commit it to the associated repository every day. I would like this new data to be available on the GitHub Pages site for the repo which requires a GitHub Pages build. The GitHub App has read & write privs assigned on "Repository contents" and "Pages".

It appears that the daily commit is attempting to rebuild the page as in the repository's GitHub Pages settings after the daily commit I see:

Your site is having problems building: Page build failed.

An empty commit with my primary account (not the GitHub App) after a failed build triggers a successful rebuild as seen below.

October 23-25, 2018: https://github.com/btouellette/HHHFreshBotRedux/commits/master

Nothing in the GitHub documentation about these generic build failures (https://help.github.com/articles/generic-jekyll-build-failures/) appears relevant as I am not using a deploy key, the primary account the GitHub App is installed on has a verified e-mail address, and I'm only pushing static files and not using Jekyll at all.

Since I'm already authenticating with the GitHub API to commit the file I attempted to utilize the API endpoint to manually request a page build (https://developer.github.com/v3/repos/pages/#request-a-page-build). The documentation says this endpoint is enabled for GitHub Apps but when I attempt to call it I get the response "Resource not accessible by integration".

Is there some way to address the build failures, to get the page build API endpoint working with the GitHub App, or to find another way to make new files available on the GitHub Pages site progammatically?

Upvotes: 1

Views: 546

Answers (1)

Brian
Brian

Reputation: 253

By using 'basic' authentication in octokit and providing explicit user and password I'm able to successfully request a pages build. The build endpoint is enabled for GitHub Apps but only for user-to-server requests where the app is acting as a user with user credentials.

Alternately I found that I can reference the raw content in the GitHub repository directly rather than using relative links from within the GitHub Pages site. This works but having the files in the pages build is better as they are served via CDN.

So by using full URLs like: https://raw.githubusercontent.com/btouellette/HHHFreshBotRedux/master/docs/daily/20181025.json

Instead of relative URLs for the GitHub Pages site like: "daily/20181025.json"

I'm able to grab files in Javascript that have not been added to the GitHub Pages build but have been made available in the repository and use them to build out the site dynamically.

Upvotes: 1

Related Questions