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

docs: auto-deploy documentation from the Travis-CI build #2222

Closed

Conversation

oliver-sanders
Copy link
Member

If building a git tag (as opposed to a branch) then append the built docs to the current gh-pages branch and push back the result, GitHub will take care of the rest.

Documentation is built incrementally atop what has gone before so changes are not destructive, i.e we don't need to do a force push.

Every now and again we will want to remove older versions from the documentation, this can be done manually:

  • Check out the gh-pages branch and delete the relevant commit.
  • If the relevant commit is the first one, delete the relevant directory and squash the commit with the next one.

Example in motion:

Before this can work on metomi/rose

We need a GitHub o-auth token with the permission "public_repo". This then has to be provided to Travis-Ci (via the dashboard) as the environment variable GH_TOKEN.

etc/travis-scripts Outdated Show resolved Hide resolved
if ! rose make-docs --venv --dev --strict clean html slides pdf \
${DEFAULT_VERSION:-} >out 2>&1; then
# output is a bit long, only output it if the docs fail to build
cat out
Copy link
Member

Choose a reason for hiding this comment

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

To >&2?

Copy link
Member Author

Choose a reason for hiding this comment

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

Contains both 1 & 2, we could cat to &2 but Travis doesn't distinguish so it makes no difference either way.

Copy link
Member

Choose a reason for hiding this comment

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

(Agreed. However it would look neater to redirect error to standard error before an exit 1. Sorry, but my brain is wired to expect this pattern.)

bin/rose-make-docs Outdated Show resolved Hide resolved
etc/travis-scripts Outdated Show resolved Hide resolved
@oliver-sanders oliver-sanders force-pushed the docs-deploy-instructions branch 2 times, most recently from fbfbe2b to f4c2d02 Compare August 22, 2018 11:02
@oliver-sanders
Copy link
Member Author

De-conflicted.

@matthewrmshin
Copy link
Member

@sadielbartholomew please review, but do not merged until we have sorted out the admin.

Copy link
Contributor

@sadielbartholomew sadielbartholomew left a comment

Choose a reason for hiding this comment

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

Looks good & is functional, as described, as far as I can see & validate (obviously I cannot test deployment itself). A few minor points to consider while the admin is settled, but nothing essential.

@@ -58,19 +58,20 @@ initial_deployment () { # Create a new gh-pages branch from scratch.

subsequent_deployment () { # Add new version to documentation.
# update gh-pages branch
git pull "${REMOTE}" gh-pages -f
git fetch "${REMOTE}" gh-pages -f
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the merge stage no longer required, out of interest?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we branch from the upstream version by name:

git checkout -B gh-pages upstream/gh-pages

@@ -40,6 +40,7 @@
# --default-version=VERSION
# By default the current version is symlinked as the default version,
# provide an alternative version to override this.
# If set to 'none' then the default version will remain unchanged.
Copy link
Contributor

Choose a reason for hiding this comment

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

Throughout travis-scripts --default-version none is used as opposed to --default-version=none as documented. I've tested these out & only the former syntax seems to work, so ideally we can update this docstring accordingly to prevent confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well spotted!

export PATH="${PWD}/bin:${HOME}/fcm-master/bin:${HOME}/cylc-master/bin:$PATH"

TMP_DOCS_DIR="${TMPDIR:-/var/tmp}/temp-docs-dir"
DOCUMENTATION_FILES=!(doc|404*|CHANGES.md|_config.yml)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since (as briefly discussed in person) a bash -n travis-scripts vaildation is confused by this extended globbing line, consider appending a comment here identifying this as such (if I may be pedantic).

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea why bash -n doesn't like the extglobs, perhaps it doesn't support them. For proper linting of shell script use something like shellcheck.

# Cylc
if grep 'cylc' <<< "${args[@]}"; then
# install Cylc
wget 'https://github.com/cylc/cylc/archive/master.tar.gz' -O \
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we have migrated from the monolithic .yml file, it might be useful to move some/all of the site link definitions (or at least the bases e.g. https://github.com/[cylc/cylc/]) from which we extract files etc. to the head of the file so that they are immediately explicit? Then again it might be clearer to define them within the functions they are used only... I'll leave it for consideration.

Copy link
Member Author

Choose a reason for hiding this comment

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

https://github.com/cylc/cylc/ is only used once so I don't think we would have much to gain, of have I misunderstood?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is not much duplication, true, but the links are constants that are fundamental to the scripts, so putting them at the head of the script might be more appropriate & would make it clear where we are sourcing the codebase installations from. There is not much to gain now, admittedly, but may be useful for future reference. We can leave it be, though.

@oliver-sanders
Copy link
Member Author

oliver-sanders commented Sep 24, 2018

Update this against #2235 if it is merged first.
Deconflicted

@oliver-sanders
Copy link
Member Author

Time to create a metomi "actor" account which we can use to perform actions on the metomi repositories?

@oliver-sanders
Copy link
Member Author

As GitHub Pages builds from branches in the GitHub repository it is necessary to use a personal access token, no changes to Travis-CI will facilitate this.

Out of interest there is a script called travis-sphinx which some other projects are using. It does roughly the same thing as this PR but pushes in force mode.

Our Options:

  • Auto-deploy as in this PR.
  • Auto-deploy using this code but building the docs elsewhere (no real change):
    • On a different CI platform;
    • On Institutional or personal hardware.
  • Continue to build docs on institutional or personal hardware and deploy manually.
  • Move documentation elsewhere e.g. readthedocs.
    • URLs wouls have to be re-directed.
    • Would tie us in with the readthedocs theme.
    • Would need to research if we could continue to use our slide builder there.

@oliver-sanders
Copy link
Member Author

Rebased onto latest Rose.


# push gh-pages branch to GitHub where it will be auto-deployed to ghpages
set +o xtrace # prevent leakage of the GH_TOKEN env var
git push "https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" \
Copy link
Member

Choose a reason for hiding this comment

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

This will still reveal the GH_TOKEN variable if we do ps -f listing while the git push command is running?

@matthewrmshin matthewrmshin modified the milestones: 2018.11.0, next-release Nov 28, 2018
@matthewrmshin matthewrmshin modified the milestones: next-release, soon Jan 17, 2019
@matthewrmshin
Copy link
Member

Apologies. Push back for now as we cannot see how the Personal Access Token can be deployed properly.

@kinow
Copy link
Member

kinow commented Feb 2, 2019

Hey 👋 ! Just passing by, noticed this part

Every now and again we will want to remove older versions from the documentation, this can be done manually:

Check out the gh-pages branch and delete the relevant commit.
If the relevant commit is the first one, delete the relevant directory and squash the commit with the next one.

FWIW, I use ghp-import for my site. As I am not using Jekyll, in order to deploy to GitHub pages, I have a small script that builds calling a static site generator for Python. This puts the contents in a folder like ./blog... then I just execute:

$ ghp-import -n -m "Publishing kinoshita.eti.br" -p -r origin -b gh-pages blog

The important flags are -p to push to the branch after committing, -r to specify which git remote repo. The gh-pages is the branch, and blog is the local folder to push.

Have no idea if that'd be helpful. Maybe there's something in ghp-import that's helpful 👋

@oliver-sanders
Copy link
Member Author

oliver-sanders commented Feb 4, 2019

There is a sphinx-build wrapper thinggy called travis-sphinx which sits atop ghp-import. I looked into it but it seemed that implementing the required logic was probably simpler. Unfortunately ghp-import has the same issue with personal access tokens, we are waiting on GitHub to come up with a cleaner solution.

@matthewrmshin
Copy link
Member

I'll close this one down for now - until we find a way that does not require a personal access token.

@matthewrmshin matthewrmshin removed this from the soon milestone Mar 14, 2019
@oliver-sanders oliver-sanders mentioned this pull request Mar 22, 2019
@oliver-sanders
Copy link
Member Author

I'll close this one down for now - until we find a way that does not require a personal access token.

Wahoo, there is now an alternative!

We can now use "deploy-keys", these are specific to a repository, to work for purpose they need to be given write permission.

Here's a GH action which does the job - https://github.com/peaceiris/actions-gh-pages#️-create-ssh-deploy-key

The permissions of the key are a little broader than I would desire (would be nice to be able to specify write for the gh-pages branch only, and also to ban force pushes), however, the tokens are repo specific and have a much less scary scope than personal access tokens.

I'm testing it on the cylc-sphinx-extensions repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc infrastructure GH Actions, Codecov etc. wontfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants