Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Action to automatically publish PRs to GitHub Pages #52

Merged
merged 8 commits into from
Mar 7, 2024

Conversation

achabotl
Copy link
Member

@achabotl achabotl commented Mar 6, 2024

This is a follow-up to #51 with fixes:

  • Fix make target to install dependencies
  • Enable the workflow to write to the repo, which we need to write to the gh-pages branch.
  • Force-push the gh-pages branch because we're overwriting the content every time.
  • Specify the CNAME so we can redirect from conference.scipy.org. Github automatically adds a CNAME file if you're publishing from a branch. But since the action wipes the gh-pages branch every time, the CNAME file goes away. ghp-import has the option to recreate it every time.

Because we're not keeping the history of the gh-pages branch, we end up
with a new commit every time. Github refuses that we push that branch
because it doesn't match the history.
The docs [1] adds a CNAME file if you're publishing from a branch. But
since the action wipes the `gh-pages` branch every time, I think the
CNAME file will go away.

ghp-import has the option to recreate it every time.

[1]: https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#configuring-a-subdomain
@achabotl achabotl changed the title Fix make target name in Github action to publish site Github Action to automatically publish PRs to GitHub Pages Mar 6, 2024
Copy link
Contributor

@matthewfeickert matthewfeickert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achabotl I'm a bit confused as to why you need to use ghp-import and manually do this work instead of just using GitHub Actions to do this (under https://github.com/scipy-conference/conference.scipy.org/settings/pages)

image

(I tend to do this in a 2 step process of building the website and uplaoding the artifacts and then in a deploy step actually doing the deployment using actions/configure-pages and actions/deploy-pages.)

As you're just overwriting the history on the gh-pages branch

ghp-import -m "Generate Pelican site ${timestamp}" --no-history --branch gh-pages output

is there a reason to use a branch at all?

* Run on push events to 'main' as the default branch has been renamed from 'master'.
* Add running the build job on pull_request events to allow testing builds of the
  website in advance.
* Scope concurrency to the workflow level, which allows for per branch runs to not conflict.
* Split the workflow into a build and deploy job. In the build job have the built website
  be uploaded as a run artifact. In the deploy job this artifact is then downloaded
  and and deployed to GitHub Pages.
   - For the deploy job, set the permissions to allow for the default GITHUB_TOKEN to perform
     the deployment.
   - Use the github-pages environment as required by GitHub Actions.
   - Run the deploy job on either:
      * push events to main (a merged PR)
      * workflow_dispatch events that happen on any branch, to allow for hotfixing
@matthewfeickert
Copy link
Contributor

To be (hopefully) more helpful than just asking questions I opened up PR #53 targetting this PR's branch that impliments the changes I'm suggesting.

@achabotl
Copy link
Member Author

achabotl commented Mar 7, 2024

Thanks @matthewfeickert. I used the gh-pages for the same reason you're using the actions: habit! :D

Also, again, I'm weary of the Beta tag on on using Github Actions. That said, I'll merge PR #53 into this one and go for actions.

…-deployment

ci: Use GitHub Actions to perform deployment
@achabotl
Copy link
Member Author

achabotl commented Mar 7, 2024

And it works! Well, @matthewfeickert, now you've set a precedent, and I'll copy and paste this workflow file into all my future projects for the next decade. ;)

@achabotl
Copy link
Member Author

achabotl commented Mar 7, 2024

Config updated.
Screenshot 2024-03-07 at 09 56 02

@achabotl achabotl merged commit c258ecc into main Mar 7, 2024
2 checks passed
@achabotl achabotl deleted the publish-gh-pages branch March 7, 2024 15:56
@matthewfeickert
Copy link
Contributor

Also, again, I'm weary of the Beta tag on on using Github Actions.

I think the "beta" here is relatively benign, as I've been using this across multiple orgs for more than a year with no issues. I've always found it to more mean "there might be API changes in the future" given the docs (https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow) but it is at least a supported service from GitHub.

Config updated.

@achabotl I see that the custom domain isn't set. Is this being handled a different way so that https://scipy-conference.github.io/conference.scipy.org/ properly redirects to https://conference.scipy.org/?

Can you also check the "Enforce HTTPS" button?

@achabotl
Copy link
Member Author

achabotl commented Mar 7, 2024

I'm working with Jim and Numfocus to setup the DNS first. If I setup the custom domain, https://scipy-conference.github.io/conference.scipy.org/ is inaccessible and I can't see whether or not it works.

I'll enable HTTPS once the DNS is set up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants