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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate versioned documentation #951

Merged
merged 12 commits into from Oct 18, 2021
Merged

Conversation

CasperWA
Copy link
Member

@CasperWA CasperWA commented Sep 29, 2021

Closes #724.

IMPORTANT: This PR cannot be merged until the gh-pages branch has been "prepared". Which is a one-time event. (See "Next steps" below.)

Use mike

Update mkdocs.yml and dependencies.

Automated deployment

With this PR we will automate deployment of the documentation using mike, meaning it will be versioned.

In addition, we will update the documentation, specifically the latest version (alias master) with every push event to the master branch.

As a bonus I have added a couple of steps to the deployment workflow that appends the version's changelog to the GitHub release description.
To see an example of this go to OPTIMADE Gateway.
When using this, we should always have a 1st level markdown header in the description, since a # Changelog will be added to the description.

pre-commit hooks

This PR adds a new local hook that runs the invoke task create-api-reference-docs with a new special option --pre-commit.
The --pre-commit option ensures the hook will "fail" if it has updated the API reference docs and they have not been added to the index/staged.

I've allowed myself to extend pre-commit to include the following other hooks from the pre-commit-hooks library as well:

  • check-symlinks
  • destroyed-symlinks
  • requirements-txt-fixer

To learn more about what the hooks do see the pre-commit-hooks README.

The trailing-whitespace has also been updated to support markdown files, but respect the double end-of-the-line whitespace syntax.

Finally, the black hook version has been updated.

Next steps

The following steps are necessary for this PR to be able to be merged:

  • Use mike manually to setup a test branch to be used to setup the framework and initial testing.
    • Set default version/alias - I suggest latest as long as we're in v0 and stable when we get to v1.
    • Test manual deployment works.
  • Test automated deployment works.
  • "Overwrite" the "public" gh-pages branch with the fully working and setup test branch.
  • Merge this PR and watch it all fire off 馃殌

Alternatively, we can change the target deploy branch from gh-pages to the test branch and merge this to test the automated deployment - then "fix" it with another PR when we are satisfied.
Note: Actual publishing on PyPI should be disabled for all testing (duh).

@codecov
Copy link

codecov bot commented Sep 29, 2021

Codecov Report

Merging #951 (0ee9b66) into master (bb1baa8) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #951   +/-   ##
=======================================
  Coverage   92.92%   92.92%           
=======================================
  Files          67       67           
  Lines        3787     3787           
=======================================
  Hits         3519     3519           
  Misses        268      268           
Flag Coverage 螖
project 92.92% <酶> (酶)
validator 92.92% <酶> (酶)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update bb1baa8...0ee9b66. Read the comment docs.

@CasperWA
Copy link
Member Author

The awesome-pages plugin also supports setting up the navigation/ToC through the nav key in mkdocs.yml, which I think seems superior to the method we are currently using.
For more information see lukasgeiter/mkdocs-awesome-pages-plugin.

@ml-evs
Copy link
Member

ml-evs commented Sep 29, 2021

馃槏

@ml-evs
Copy link
Member

ml-evs commented Sep 29, 2021

Looks great so far @CasperWA, this is something I've been wanting to find the time for too.

Could we perhaps prepare this in a fork so we can actually do the gh pages builds without bringing down our current docs? I was able to do this for the providers dashboard after I enabled gh pages in my fork repo (in the normal way).

@CasperWA
Copy link
Member Author

Concerning the list of documentation version I suggest the following:

  • 0.16.4 (alias "stable")
  • latest (alias "master")

After making a new release, say v0.17.0, the list of versions will then be:

  • 0.17.0 (alias "stable")
  • 0.16.4
  • latest (alias "master")

As a note, the aliases will have their own folder in the gh-pages branch, but all pages will redirect to the aliased "version", i.e., if one goes to /master/index.html one will end up at /latest/index.html.
I also think removing the prepended v looks nicer.

@CasperWA
Copy link
Member Author

CasperWA commented Sep 29, 2021

Looks great so far @CasperWA, this is something I've been wanting to find the time for too.

Yup. Just did it in another project and thought this was the right time to implement it here as well :)

Could we perhaps prepare this in a fork so we can actually do the gh pages builds without bringing down our current docs? I was able to do this for the providers dashboard after I enabled gh pages in my fork repo (in the normal way).

Yeah, all the testing can be done in a separate branch. We can create a test-mike branch if you like and this can be used to test both deployment, how it will look, etc.
Essentially, we could build everything up in that branch and then overwrite gh-pages with it eventually (this is what I also did in the other project, so it works nicely).

Edit: I.e., no need to use a fork - we can just momentarily change the target branch for all deployment for testing - and then "fix" it afterwards?

@ml-evs
Copy link
Member

ml-evs commented Sep 30, 2021

After making a new release, say v0.17.0, the list of versions will then be:
* 0.17.0 (alias "stable")
* 0.16.4
* latest (alias "master")

Sounds good to me!

Edit: I.e., no need to use a fork - we can just momentarily change the target branch for all deployment for testing - and then "fix" it afterwards?

That also works.

Copy link
Contributor

@JPBergsma JPBergsma left a comment

Choose a reason for hiding this comment

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

I did not see anything wrong with the changes you made. There are however still enough things I do not know to about that I do not think I'm the right person to approve this

@CasperWA
Copy link
Member Author

CasperWA commented Oct 14, 2021

This might potentially "solve" this open closed vulnerability issue, since we will be moving to use mike instead of mkdocs' built-in dev-server. But also, the mkdocs built-in dev-server is never used in production as the GH Pages are statically served.

@CasperWA
Copy link
Member Author

I've tested the workflow extensively in the OPTIMADE Gateway repository, and it all seems to be working nicely. I'll update this, go over the setup again and align with the OPTIMADE Gateway setup and mark this as "ready for review".

CasperWA and others added 11 commits October 14, 2021 10:21
Checking that they actually point to the latest full version number.
This will deploy and update the `latest` version (alias `master`)
whenever a push event to `master` happens.
It will not update the CHANGELOG or other things. Indeed, it will fail
if the API Reference in the documentation has not been properly updated.

The "regular" CD workflow has been updated with versioned documentation
deployment, as well as a new feature:

The release description on GitHub will be updated with the changelog for
that particular version.
This changelog will be *appended* to the existing description.
One should now make sure to have a proper 1st level markdown header in
the description, since the appended changelog will introduce a similar
level header: `# Changelog`.
Added:
- check-symlinks
- destroyed-symlinks
- requirements-txt-fixer

And changed settings for `trailing-whitespace` to utilize the
`markdown-linebreak-ext` option instead of excluding README.md.
This is better, since it will now find and correct single trailing white
space, but not double (which is part of markdown syntax).

To learn more about what the hooks do see:
https://github.com/pre-commit/pre-commit-hooks#readme
Untracked files might be new files under the API Reference folder that
reflect new modules.
Update various parts of the documentation update workflows to be similar
to the tested workflows in the OPTIMADE Gateway.
@CasperWA CasperWA force-pushed the cwa/close-724-versioning-docs branch from beb9df1 to 072fb6b Compare October 14, 2021 08:51
@CasperWA CasperWA marked this pull request as ready for review October 14, 2021 09:41
@CasperWA
Copy link
Member Author

CasperWA commented Oct 14, 2021

To check out / review the "new" documentation one can do the following:

$ git fetch origin
$ git branch cwa/close-724-versioning-docs origin/cwa/close-724-versioning-docs
$ git checkout cwa/close-724-versioning-docs
$ pip install -U pip setuptools wheel
$ pip install -U -e .[docs]
$ mike serve -r origin -b new-gh-pages
Starting server at http://localhost:8000/
Press Ctrl+C to quit.

Then go to localhost:8000 and enjoy :)

@CasperWA
Copy link
Member Author

Important: Before merging this, the gh-pages branch should be "overwritten" with the new-gh-pages branch, and the new-gh-pages branch can then be removed.
This is very important.

Also note, I have gone through all versions (tags) that implemented the documentation, i.e., all the way back to v0.9.0 and "deployed" them to the new-gh-pages branch. The main difference is that all the documentation is generated/built using the latest versions for the documentation packages.

Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Great work @CasperWA, happy to leave the final branch/release process up to you.

Shall we release 0.16.5 after this PR?

Comment on lines +65 to +67
- name: Deploy documentation
if: env.RELEASE_RUN == 'false'
run: mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest master
Copy link
Member

@ml-evs ml-evs Oct 15, 2021

Choose a reason for hiding this comment

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

One minor worry with this, can we test the mike deploy (without pushing to master) inside pull requests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not completely sure what you mean by "testing mike deploy inside pull requests"? Do you mean you wish to see the would-be documentation if the new changes are implemented?

If this is what you meant, then no, I think this is out-of-scope for mike.
However, one can always do:

$ mike build -b burner-branch-for-my-new-fancy-head-branch-for-a-pr
$ mike serve -b burner-branch-for-my-new-fancy-head-branch-for-a-pr

or simply just mkdocs serve - which I would probably recommend to use locally at all times instead of mike. mike should really only be used to deal with the versioned edition/branch of the documentation.

For a reviewer one would need to fetch and use the PR's head branch and test this locally of course.
If you want more of a look at the new docs in the PR we need to set something else up.

.github/workflows/cd_release.yml Show resolved Hide resolved
Copy link
Contributor

@JPBergsma JPBergsma left a comment

Choose a reason for hiding this comment

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

$ git fetch origin
$ git branch cwa/close-724-versioning-docs origin/cwa/close-724-versioning-docs
$ git checkout cwa/close-724-versioning-docs
$ pip install -U pip setuptools wheel
$ pip install -U -e .[docs]
$ mike serve -r origin -b new-gh-pages
Starting server at http://localhost:8000/
Press Ctrl+C to quit.
    

I have followed these instructions and I got a fully functioning website, so it seems everything is OK.

@CasperWA
Copy link
Member Author

Great work @CasperWA, happy to leave the final branch/release process up to you.

Shall we release 0.16.5 after this PR?

Cheers.

And sure - let's put everything to the test right away 馃槄 ..... 馃槵

@CasperWA CasperWA merged commit 4a86bab into master Oct 18, 2021
@CasperWA CasperWA deleted the cwa/close-724-versioning-docs branch October 18, 2021 12:03
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.

Versioning in Docs
3 participants