Documentation with versions using GitHub Actions, mike and Cloudflare Pages #6546
niden
started this conversation in
Show and tell
Replies: 2 comments
-
this should be added to the docs - thank you so much for sharing @niden ❤️ |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for sharing! We're actively working on making versioning and multi-language setups simpler, so most of this will not be necessary anymore in the near future |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Related: #6513
We are in the process of converting our documentation with our next release, to use
mkdocs-material
. The biggest hurdle we had was understanding how versioning works withmike
. Loads of rabbit holes to follow and somewhat missing documents/pointers, but we made it in the end.I hope this post helps people that want to follow the same path.
Requirements:
mkdocs-material
as the theme with some pluginsmike
for versionsPretty straight forward. Following the manual, one can run the docker command for
mkdocs-material
and serve the documents locally, make alterations etc. and see them live. The unknown for us was how to incorporatemike
, check the output and deploy to Cloudflare Pages.Cloudflare Pages
Cloudflare Pages have been linked to the repository, and build whenever a commit happens in the
production
branch. (more on that further down)Local Environment
You will need to create a new docker image for yourself. Although a docker container exists for
mkdocs-material
, we could not find one formike
, so we created one for both. The image will containmkdocs
,mkdocs-material
and various plugins as well asmike
and the
requirements.txt
file is:Switch to the folder you have the Dockerfile and build it:
docker build -t mkdocs-mike .
and then enter it so that you can run commands
docker run -it --rm \ --network host \ -v "$PWD":/usr/src/myapp \ -w /usr/src/myapp \ mkdocs-mike /bin/bash
This will allow you to enter the image and run different commands such as
You can then load
http://localhost:8000/
in your browser and view your documents. When the time comes, you can runmike
also to produce the documents (it will be in thesite
folder)Doing it this way is indeed two steps, one to enter the dockerized environment and then run the
serve
command, but it offers access tomike
, so it helps in that respect. If you install packages directly on your machine, you can just install all the requirements and not have to deal with a docker container.Deployment
Deploying with
mike
is easy. The fastest way is to create the documents, was to copy them from thesite
folder to a temporary location. Of course, we had to change the permissions on the files since they were generated from the user in the container and not the host user. Then it was a matter of switching to theproduction
branch, and copy the documents over to the correct folder (3.1, 3.2, 4.1, 5.5 etc.). Commit and push upstream.Cloudflare Pages would detect the commit and deploy the site.
Workflow
The above worked but a pain after a while. The need is for things to be automated. Based on suggestions, we checked the Andruino-Cli project and how they handle this.
They deploy in GitHub pages, so the steps are a bit different but the way they detect branches and changes is great! Kudos.
In the repository we of course have the
master
branch. Off that, we create a new branch5.4.x
. The reason for thex
in the end is because this branch will host all the5.4
versions. It is also parsed in the GitHub workflow.In that branch we make any alterations we need. Once ready we push upstream and let the GitHub action do its magic.
The action does:
0-9.0-9.x
, then it proceeds with the deploymentrequirements.txt
)mike
targeting theproduction
branchTo determine the version we use a file in the root of the project called
VERSION
, which has one line in it:The first part (before the
|
) is the version, the second the alias. In this case, we are setting5.5
to be the latest branch. For5.4
the file would beJust before we run
mike
we need to pull from theproduction
branch to update references, and then set up the user that will make the commit.Once that is done,
mike
runs doing its magic, commits, and pushes to theproduction
branch. Cloudflare Pages detects the commit and publishes the site.Our workflow file is at the bottom of this post.
New Version
When creating a new version, we will make a new branch
5.6.x
and make the necessary changes to theVERSION
file as well as the GitHub action. If you notice, we like to have the name of the action reflect the version. Not a necessary step but we like it.After the documents are completed and before we deploy to live, we switch to the current latest version branch
5.5.x
and alter theVERSION
file, removing thelatest
alias. Push so that we get a deployment and then switch to the latest branch and push up to get the new latest version.Conclusion
Enjoyable and a bit frustrating trip, but we got there in the end. We only have some cosmetic issues to deal with but our documents are ready to be deployed with the next version of our framework.
Note, that we did not opt to use the
projects
plugin (yet), which could have been used instead ofmike
. We will have to experiment with that in the near future, and should it prove to be what we need, we will definitely switch to that workflow and update this post accordingly.GitHub Actions workflow file
Beta Was this translation helpful? Give feedback.
All reactions