Skip to content

Github actions build & PR preview #46

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

Merged
merged 10 commits into from
May 3, 2020

Conversation

LKedward
Copy link
Member

@LKedward LKedward commented May 2, 2020

This PR aims to resolve #41.

The approach here is to use github actions to explicitly build the site on push as opposed to the automatic github Jekyll build used currently; this action builds the site using Jekyll on the master branch and pushes to the 'gh-pages' branch. (Repo settings will therefore need to be changed by admin here to point to 'gh-pages' branch).

Additional actions are added for pull requests which are built and pushed to the 'gh-pages' branch under the path 'pr/<pr_number>'; therefore pull requests can be previewed at fortran-lang.org/pr/46/ for example.

To enable the 'pr/<pr_number>' sub-path, the site source has been updated such that all internal site links and references are prepended with {{site.baseurl}}, see here for explanation.

I'm not an expert on github actions so if anyone has more experience and feedback then let me know!

This has been tested on a private repo, but I'm not sure if any extra steps are required for this organisation repo.

LKedward added 4 commits May 2, 2020 16:33
This is required for when the site is built with a different base url.
Adds github actions to build site, build PR previews and delete closed PR previews.
@LKedward LKedward marked this pull request as draft May 2, 2020 15:56
@certik
Copy link
Member

certik commented May 2, 2020

Thanks for this! Yes, that's exactly what we need. How do I test it out?

@LKedward
Copy link
Member Author

LKedward commented May 2, 2020

... How do I test it out?

I'm going to see if I can merge into the master of my fork and demonstrate a working build and PR.

@milancurcic
Copy link
Member

Thank you @LKedward! Once you nail down the workflow, please document each step from a developer's point of view, either in a "How to contribute" section in README.md, or in CONTRIBUTING.md. I also don't know how this works.

@LKedward
Copy link
Member Author

LKedward commented May 2, 2020

Thank you @LKedward! Once you nail down the workflow, please document each step from a developer's point of view, either in a "How to contribute" section in README.md, or in CONTRIBUTING.md. I also don't know how this works.

Ah yes good point, I'll make sure to document this.

LKedward added 5 commits May 2, 2020 20:39
closePR action runs when a pull request comment
contains '#delete_preview' and will delete pr
site files from gh-pages branch.
This avoids a potential race condition on gh-pages
branch when merging a pull request.
When a PR preview is built, a banner is appended
to nav.html to indicate preview build with link
to github pull request.
Initially just detailing pull request workflow
and information for pull request previews.
@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

To test this out I have merged into my personal fork:

The rendered site files (for both the normal site and for PRs) are pushed to the 'gh-pages' orphan branch https://github.com/LKedward/fortran-lang.github.io/tree/gh-pages.

Before this can be merged, a 'gh-pages' branch needs to be created in this main repository by an admin as an orphan branch

@LKedward LKedward marked this pull request as ready for review May 3, 2020 09:47
If pull request description contains '#no_preview'
then the github action will not build a preview.
@milancurcic
Copy link
Member

Sounds good, I'll go ahead and create the orphan branch.

@certik
Copy link
Member

certik commented May 3, 2020

@milancurcic if you have time to set this up, please go ahead! I am quite busy today.

@milancurcic
Copy link
Member

@LKedward done. Is this PR ready to merge?

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

@LKedward done. Is this PR ready to merge?

Cheers @milancurcic, yep I'm happy with it - ready to merge!

@milancurcic milancurcic merged commit 350b0eb into fortran-lang:master May 3, 2020
@milancurcic
Copy link
Member

Okay, just merged. Do we now need to have a dummy PR to trigger the build? Notice that the site is currently broken.

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

Okay, just merged. Do we now need to have a dummy PR to trigger the build? Notice that the site is currently broken.

No, it's been built and pushed okay.

Can you check in the repo settings that the github pages are pointing to 'gh-pages' branch.
Like this:
Screenshot from 2020-05-03 19-08-44

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

Oh no, I think we can't use the gh-pages branch on github.io repos!
I didn't take this into account here. I think we need to revert since I can't think a solution atm.

@milancurcic
Copy link
Member

I just realized it too:

Screenshot from 2020-05-03 14-08-33

@milancurcic
Copy link
Member

Okay I just reverted this PR.

Regarding a possible solution, could we:

  1. Rename this repository so that it's not a user page, for example fortran-lang-website or similar;
  2. Set it up to serve from gh-pages

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

Okay I just reverted this PR.

Thanks.
Okay it looks like we have to do 1 but keep this repo:
So the current repo contents is moved to a separate repository and the github actions push the built html to this repository.
It's a bit of an upheaval unfortunately.

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

It's a bit of an upheaval unfortunately.

By this I just mean that all contributors will have to checkout a different repository.

Regarding the github action workflows I've put together here: there is very little that needs changing, I only need to change the repository that it pushes to.

@certik
Copy link
Member

certik commented May 3, 2020

That was a mistake of using a repo and serving it directly. A better approach is to have a repository with the sources, and the CI then builds the page from master and pushes it somewhere else to be served.

Second, the name of this repository fortran-lang.github.io is misleading anyway because it is actually serves at fortran-lang.org. So how about we rename this repository to fortran-lang.org, to keep all the history, stars, issues, etc.

Then we create a new repository that would actually serve fortran-lang.org. So that it is not confusing, perhaps it can be called fortran-lang.org.deploy or something like that.

And then setup a CI at fortran-lang.org that checks each PR (it builds it and pushes somewhere to be looked at, not at fortran-lang.org), and then every master will get built and pushed into fortran-lang.org.deploy to be served at fortran-lang.org.

@certik
Copy link
Member

certik commented May 3, 2020

Now when I think about it, let's just keep https://github.com/fortran-lang/fortran-lang.github.io as is, if GitHub allows it, but it will become the source repository. The fortran-lang.org domain will be served from the new repository, say fortran-lang.org.deploy. The same setup from my previous comment, but we don't need to rename this repository, so people don't need to update their setup.

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

That was a mistake of using a repo and serving it directly. A better approach is to have a repository with the sources, and the CI then builds the page from master and pushes it somewhere else to be served.

I disagree here, this approach, of using the 'gh-pages' branch is quite standard for so-called project sites, see here. Unfortunately I didn't realise github doesn't allow this approach for so-called organisation sites. (I can see no actual reason why it is disallowed here)

Second, the name of this repository fortran-lang.github.io is misleading anyway because it is actually serves at fortran-lang.org. So how about we rename this repository to fortran-lang.org, to keep all the history, stars, issues, etc.

Then we create a new repository that would actually serve fortran-lang.org. So that it is not confusing, perhaps it can be called fortran-lang.org.deploy or something like that.

And then setup a CI at fortran-lang.org that checks each PR (it builds it and pushes somewhere to be looked at, not at fortran-lang.org), and then every master will get built and pushed into fortran-lang.org.deploy to be served at fortran-lang.org.

We have to keep the rendered html at fortran-lang.github.io since this is a so-called organisation site which serves the site at https://<organization>.github.io. If we use any other repository it will not be an organisation site but simply a project site which is not served at the site root but under https://<organization>.github.io/<repository>.

See here for full explanation:
https://help.github.com/en/github/working-with-github-pages/about-github-pages#types-of-github-pages-sites

My proposition is similarly based on a two repository approach, but the unbuilt source (current repo contents) is moved to a new repository and fortran-lang.github.io is used for deployment via CI for the reasons mentioned above.

Unfortunately as I said, and as you point out, it is an upheaval meaning stars, issues etc are effectively lost.

@milancurcic
Copy link
Member

That was a mistake of using a repo and serving it directly.

No, I did it on purpose as an org page so that repository pages like stdlib automatically inherit the top-level domain.

I'm okay with either approach. For the site in production repository name, just fortran-lang.org is my preference.

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

To lay out my proposed solution more formally:

  • Rename existing fortran-lang.github.io repo to fortran-lang-source
    (We get to keep stars, issues, history, etc)

  • Create new fortran-lang.github.io repo

  • Update pull request CI to deploy to master on new fortran-lang.github.io

@certik
Copy link
Member

certik commented May 3, 2020

@LKedward that's fine, this will work.

Note that I routinely deploy from a deploy repository, e.g. https://www.theoretical-physics.com/, is served by https://github.com/certik/tfc-deploy and pushed into it from the https://gitlab.com/certik/theoretical-physics/ source repository. But perhaps it's different if we are part of an organization? I don't know.

@LKedward
Copy link
Member Author

LKedward commented May 3, 2020

The only reason the original workflow didn't work here is because github allows the workflow for project sites but not for organisation/user sites. (I had the workflow working in my fork, but because it was a fork it was a project site not an organisation site.)

@milancurcic
Copy link
Member

milancurcic commented May 3, 2020

We don't have to use an organization page. I chose that because of 2 benefits:

  1. You don't need to maintain a production repo (the one being served), it's done automatically and under the hood by GitHub;
  2. Project pages inherit top-level domain.

I don't think there are any other advantages. The obvious downside is that you can't do what we're now trying to do here, and we want to do it.

If the repo is called <orgname>.github.io and you chose to serve a page from it, then it's an org page (and ditto for <username>).

However, this doesn't mean that fortran-lang.github.io (this repo) must be an org page. If you disable serving in the settings, it's not a page anymore.

There's a number of solutions here that preserve repo metadata (stars, issues, etc.).

My favorite actually is to:

  1. Rename this repo so it's not an org page (preserves metadata);
  2. Deploy to gh-pages branch.

But deploying to master of another repo is okay too. It just seems like unnecessary added complexity of carrying a separate repo for deployment.

@milancurcic
Copy link
Member

We have to keep the rendered html at fortran-lang.github.io since this is a so-called organisation site which serves the site at https://.github.io. If we use any other repository it will not be an organisation site but simply a project site which is not served at the site root but under https://<organization>.github.io/<repository>.

@LKedward I don't think this matters at all because GitHub will redirect https://<organization>.github.io/<repository> to fortran-lang.org anyway. Am I wrong?

@certik
Copy link
Member

certik commented May 3, 2020 via email

@milancurcic
Copy link
Member

What do you mean by inherit top level domain? I think one can always serve to subdomains such as docs.fortran-lang.org with different repositories.

Example: https://fortran-lang.org/stdlib/. That page is served from the fortran-lang/stdlib repo. It's just a convenience feature, nothing major.

Yes, we can easily serve other project pages as subdomains, it's just a matter of adding a CNAME record.

I defer the choice of final implementation for this to you and Laurence. What matters to me is that we have automatic previews and preserve metadata, for both of which it looks like we have solutions.

@certik
Copy link
Member

certik commented May 3, 2020 via email

@LKedward
Copy link
Member Author

LKedward commented May 4, 2020

@LKedward I don't think this matters at all because GitHub will redirect https://<organization>.github.io/<repository> to fortran-lang.org anyway. Am I wrong?

Ah okay, yep you are right here.

My favorite actually is to:

  1. Rename this repo so it's not an org page (preserves metadata);
  2. Deploy to gh-pages branch.

I agree this is by far the simplest and least-disruptive solution.
We get to keep metadata and this pull request can be merged as is.

Does anyone know how this will affect existing forks?

Update: I've never renamed a repository before but it seems github is very accommodating to renaming repositories: the original repository url will redirect all web traffic and git operations to the new one (assuming we don't create another fortran-lang.github.io repo) so there aren't really any disadvantages to this approach!

@LKedward
Copy link
Member Author

LKedward commented May 7, 2020

I've reopened this PR in #54 for when the repo has been renamed.
I think fortran-lang.org makes sense as a repo name, what do you think?

@milancurcic
Copy link
Member

I agree. @certik what do you think?

@certik
Copy link
Member

certik commented May 7, 2020 via email

@milancurcic
Copy link
Member

Okay, I'm gonna rename the repo now.

@milancurcic
Copy link
Member

The rename seems like it worked. The website had about 1 minute of downtime while I was applying the custom domain in the settings. It is now served from gh-pages. I think we can now move forward and merge #54

@LKedward
Copy link
Member Author

LKedward commented May 7, 2020

Sounds good!

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.

Create a Preview for each PR
3 participants