-
-
Notifications
You must be signed in to change notification settings - Fork 170
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 publish docs to GH Pages #1129
Open
mickmcgrath13
wants to merge
23
commits into
StackStorm:master
Choose a base branch
from
mickmcgrath13:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2f000a4
initial action to publish gh-pages
mickmcgrath13 5a85d8d
put gh actions workflow in the correct place
mickmcgrath13 664d580
add virtualenv
mickmcgrath13 dbac6d3
install virtualenv with pip3
mickmcgrath13 fae5676
debugging
mickmcgrath13 2d18a98
alias python
mickmcgrath13 cb63d3a
just specify python instead of python3.6
mickmcgrath13 03f7221
remove python alias stuff
mickmcgrath13 0dd9541
troubleshooting
mickmcgrath13 354e2b7
use python3.8
mickmcgrath13 54cfd49
include makefile in trigger
mickmcgrath13 de8024e
add nojekyll file
mickmcgrath13 16150cd
add nojekyll to build not to root of repo
mickmcgrath13 d2bb369
remove circleci
mickmcgrath13 0006eb2
Merge branch 'master' of github.com:mickmcgrath13/st2docs
mickmcgrath13 dff9e1f
re-add circleci
mickmcgrath13 9b8039d
read python_version from env var
mickmcgrath13 45cd54a
fix python version for gha workflow and use peaceiris action for gh p…
mickmcgrath13 2f85300
default value for PYTHON_VERSION in makefile
mickmcgrath13 897b95e
enhanced version handling
mickmcgrath13 b802387
figure out variables first
mickmcgrath13 bee2261
comment out the concurrency test
mickmcgrath13 4bb846a
Merge branch 'master' into master
cognifloyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
name: Publish Docs | ||
|
||
# TODO: this is commented out unless someone is testing with it | ||
# on: | ||
# push: | ||
# branches: | ||
# - master | ||
|
||
# # filter on version branches: | ||
# # circleci filtered on version branches like this: | ||
# # filters: | ||
# # branches: | ||
# # only: | ||
# # - master | ||
# # - /v[0-9]+\.[0-9]+/ | ||
# # full regex filtering not supported: https://github.community/t/using-regex-for-filtering/16427 | ||
# # subset filtering supported: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet | ||
# - v[0-9]+.[0-9]+ | ||
# paths: | ||
# - "docs/**" | ||
# - ".github/workflows/publish-docs.yml" | ||
# - "Makefile" | ||
|
||
|
||
jobs: | ||
|
||
# publish GA if this is a GA publish | ||
publish-ga: | ||
|
||
# running a gh-pages publish while one is ongoing will result in the previous execution being cancelled in favor of the subsequent one | ||
# use concurrency to ensure these jobs don't overwrite each other | ||
concurrency: | ||
group: gh-pages-build | ||
cancel-in-progress: false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Determine if latest GA version | ||
run: | | ||
export BRANCH_OR_TAG_NAME=${GITHUB_REF##*/} | ||
export IS_LATEST_GA_VERSION="0" | ||
|
||
# GA_VER=$(curl -sSL https://stackstorm.com/packages/install.sh|grep ^BRANCH=|sed 's/[^0-9.]*//g') | ||
GA_VER=9.9 | ||
if [ "${BRANCH_OR_TAG_NAME}" = "v${GA_VER}" ]; then | ||
echo "Current GA Version. Deploy root" | ||
IS_LATEST_GA_VERSION="1" | ||
else | ||
echo "Not current GA version" | ||
fi | ||
|
||
|
||
# debug output | ||
echo "BRANCH_OR_TAG_NAME: $BRANCH_OR_TAG_NAME" | ||
echo "GA_VER: $GA_VER" | ||
echo "IS_LATEST_GA_VERSION: $IS_LATEST_GA_VERSION" | ||
|
||
# set for next github action step | ||
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files | ||
echo "IS_LATEST_GA_VERSION=$IS_LATEST_GA_VERSION" >> $GITHUB_ENV | ||
|
||
- name: Build | ||
if: ${{ env.IS_LATEST_GA_VERSION == '1' }} | ||
env: | ||
python_version: python3.8 | ||
run: | | ||
make st2 | ||
sudo apt-get update | ||
# python3-dev is already available | ||
# sudo apt install python3-dev | ||
sudo apt install libldap2-dev | ||
sudo apt install libsasl2-dev | ||
sudo pip3 install virtualenv | ||
make docs | ||
|
||
# turn off jekyll so that url routing works properly with underscores | ||
touch docs/build/html/.nojekyll | ||
|
||
# since deploying the root in gh pages will wipe away any other versioned subdirectories, | ||
# deploy the latest ga version to a `ga` subdirectory, and use routing to point the root docs.stackstorm.com to `docs.stackstorm.com/ga` | ||
- name: Deploy to Root GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
if: ${{ env.IS_LATEST_GA_VERSION == '1' }} | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: docs/build/html | ||
destination_dir: "ga" | ||
|
||
|
||
# publish the version or 'latest' subdirectory | ||
publish-version: | ||
concurrency: | ||
group: gh-pages-build | ||
cancel-in-progress: false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: extract version subdirectory | ||
env: | ||
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | ||
run: | | ||
export BRANCH_OR_TAG_NAME=${GITHUB_REF##*/} | ||
|
||
# set up subdirectory path | ||
# `/latest` if default branch | ||
# branch name otherwise | ||
if [ "${BRANCH_OR_TAG_NAME}" == "${DEFAULT_BRANCH}" ]; then | ||
export PUBLISH_SUBDIRECTORY="latest" | ||
else | ||
# remove the preceeding "v" | ||
export PUBLISH_SUBDIRECTORY=$(echo "${BRANCH_OR_TAG_NAME}" | sed 's/^v\(.*\)$/\1/') | ||
fi | ||
|
||
# debug output | ||
echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" | ||
echo "BRANCH_OR_TAG_NAME: $BRANCH_OR_TAG_NAME" | ||
echo "PUBLISH_SUBDIRECTORY: $PUBLISH_SUBDIRECTORY" | ||
|
||
# set for next github action step | ||
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files | ||
echo "PUBLISH_SUBDIRECTORY=$PUBLISH_SUBDIRECTORY" >> $GITHUB_ENV | ||
|
||
- name: Build | ||
env: | ||
python_version: python3.8 | ||
run: | | ||
make st2 | ||
sudo apt-get update | ||
# python3-dev is already available | ||
# sudo apt install python3-dev | ||
sudo apt install libldap2-dev | ||
sudo apt install libsasl2-dev | ||
sudo pip3 install virtualenv | ||
make docs | ||
|
||
# turn off jekyll so that url routing works properly with underscores | ||
touch docs/build/html/.nojekyll | ||
|
||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: docs/build/html | ||
destination_dir: ${{ env.PUBLISH_SUBDIRECTORY}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
name: Publish Docs | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
# filter on version branches: | ||
# circleci filtered on version branches like this: | ||
# filters: | ||
# branches: | ||
# only: | ||
# - master | ||
# - /v[0-9]+\.[0-9]+/ | ||
# full regex filtering not supported: https://github.community/t/using-regex-for-filtering/16427 | ||
# subset filtering supported: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet | ||
- v[0-9]+.[0-9]+ | ||
paths: | ||
- "docs/**" | ||
- ".github/workflows/publish-docs.yml" | ||
- "Makefile" | ||
|
||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: extract subdirectory | ||
env: | ||
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | ||
run: | | ||
export BRANCH_OR_TAG_NAME=${GITHUB_REF##*/} | ||
|
||
# set up subdirectory path | ||
# `/latest` if default branch | ||
# branch name otherwise | ||
if [ "${BRANCH_OR_TAG_NAME}" == "${DEFAULT_BRANCH}" ]; then | ||
export PUBLISH_SUBDIRECTORY="latest" | ||
else | ||
# remove the preceeding "v" | ||
export PUBLISH_SUBDIRECTORY=$(echo "${BRANCH_OR_TAG_NAME}" | sed 's/^v\(.*\)$/\1/') | ||
fi | ||
|
||
# debug output | ||
echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" | ||
echo "BRANCH_OR_TAG_NAME: $BRANCH_OR_TAG_NAME" | ||
echo "PUBLISH_SUBDIRECTORY: $PUBLISH_SUBDIRECTORY" | ||
|
||
# set for next github action step | ||
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files | ||
echo "PUBLISH_SUBDIRECTORY=$PUBLISH_SUBDIRECTORY" >> $GITHUB_ENV | ||
|
||
- name: Determine if latest GA version | ||
run: | | ||
export BRANCH_OR_TAG_NAME=${GITHUB_REF##*/} | ||
export IS_LATEST_GA_VERSION="0" | ||
|
||
GA_VER=$(curl -sSL https://stackstorm.com/packages/install.sh|grep ^BRANCH=|sed 's/[^0-9.]*//g') | ||
if [ "${BRANCH_OR_TAG_NAME}" = "v${GA_VER}" ]; then | ||
echo "Current GA Version. Deploy root" | ||
IS_LATEST_GA_VERSION="1" | ||
else | ||
echo "Not current GA version" | ||
fi | ||
|
||
|
||
# debug output | ||
echo "BRANCH_OR_TAG_NAME: $BRANCH_OR_TAG_NAME" | ||
echo "IS_LATEST_GA_VERSION: $IS_LATEST_GA_VERSION" | ||
|
||
# set for next github action step | ||
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files | ||
echo "IS_LATEST_GA_VERSION=$IS_LATEST_GA_VERSION" >> $GITHUB_ENV | ||
|
||
- name: Build | ||
env: | ||
python_version: python3.8 | ||
run: | | ||
make st2 | ||
sudo apt-get update | ||
# python3-dev is already available | ||
# sudo apt install python3-dev | ||
sudo apt install libldap2-dev | ||
sudo apt install libsasl2-dev | ||
sudo pip3 install virtualenv | ||
make docs | ||
|
||
# turn off jekyll so that url routing works properly with underscores | ||
touch docs/build/html/.nojekyll | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: docs/build/html | ||
destination_dir: ${{ env.PUBLISH_SUBDIRECTORY}} | ||
|
||
|
||
# TODO: running a gh-pages publish while one is ongoing will result in the previous execution being cancelled in favor of the subsequent one | ||
# We cannot use the following step without ensuring it won't cancel other active gh-pages deployments | ||
|
||
# since deploying the root in gh pages will wipe away any other versioned subdirectories, | ||
# deploy the latest ga version to a `ga` subdirectory, and use routing to point the root docs.stackstorm.com to `docs.stackstorm.com/ga` | ||
# - name: Deploy to Root GitHub Pages | ||
# uses: peaceiris/actions-gh-pages@v3 | ||
# if: ${{ env.IS_LATEST_GA_VERSION == '1' }} | ||
# with: | ||
# github_token: ${{ secrets.GITHUB_TOKEN }} | ||
# publish_dir: docs/build/html | ||
# destination_dir: "ga" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start,
Per existing CircleCI config, there's also a need for additional routing logic depending on the branch:
st2docs/.circleci/config.yml
Lines 41 to 61 in 6c65852
From what I understand the logic looks this way:
master
branch build ->/latest/
st2docs dirv.X.Y.Z
latest stable branch ->/
st2docs dirvX.Y.Z
branch build ->vX.Y
st2docs dirThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be possible with the
destination_dir: subdir
option:https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-deploy-to-subdirectory-destination_dir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, the
destination_dir: subdir
option works well for/latest
and/X.Y
site directories. so 🎉One difference, however, is that if we deploy to the root for the latest GA version like we do for S3, we'll lose all other subdirectories. For example, if we have
/1.0
and/latest
, and then we determine that the current version is also the latest GA release, deploying the site to/
will wipe away/1.0
and/latest
. I've confirmed this with testing.To get around this, we could implement the action to deploy the latest GA release to a
/ga
subdirectory, and we can use URL routing to pointdocs.stackstorm.com
todocs.stackstorm.com/ga
. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, we have a bigger issue:
When we push to github pages, a bot will run a
pages-build-deployment
pipeline. If we push togh-pages
again while an existingpages-build-deployment
pipeline is running, github will cancel the previous deployment in favor of the subsequent one:This means that we cannot push to
gh-pages
while there is an ongoing gh pages deployment, and it is non-trivial to "wait" until the gh pages deployment is finished. I suspect it's possible, though I've not looked into how it might be done (it'd probably involve the github api and some sort of polling logic).This will also impact us when we want to run a deployment to existing version branches as we'd have to wait until each is finished before triggering the next one..
One thing that might help is that we could utilize the concurrency feature for our workflow. This will help ensure that our workflows don't run while another of our workflows are running, but we don't seem to have control over the
pages-build-deployment
pipeline.https://stackoverflow.com/questions/70631168/github-actions-going-through-with-pages-build-deployment
Using
concurrency
might help because it's likely the gh pages will finish before any subsequent builds do, but it's a risk. It's possible that the gh pages deployment will take some time in which case our st2docs build might finish before and cancel the existingpages-build-deployment
pipeline.Concurrency was not working with my testing of multiple jobs in the same workflow, however.. (test here: https://github.com/StackStorm/st2docs/pull/1129/files#diff-7b112bd01a3c7000d73727a7e66cbfb9cf00a47702c94fda157e23f46e20db17R1)
However, it also means that we have to run two builds for the same thing...
One possible workaround is to use routing logic in Route53 or cloudfront to point the latest GA release instead of using a
/ga
subdirectory. I can think of 2 ways to do this:alternatively, it might be possible in the future to publish to GH Pages without the bot, but for now, that's our only option, I think:
https://github.community/t/github-pages-bot-added-to-our-repos-unannounced/218214/13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example pipeline here: https://github.com/mickmcgrath13/st2docs/actions/runs/2531438591
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand the issue. The
pages-build-deployment
pipeline that github runs will be deploying whatever is on the gh-pages branch.So, if we have two merges into the gh-pages branch at about the same time, and two builds start, then the build for the older commit should be canceled. But, because the newer commit should include everything from the previous commit, I don't think that's a problem. What else am I missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the issue was that if we are deploying say to version 3.7 of the docs, and then do a deploy to latest whilst its still running the deploy for v3.7. The v3.7 one will be cancelled, and we won't get the update to v3.7.
Though it isn't a frequent occurrance, that we push doc changes to the older branches, so as long as we can re-trigger the branched build I would have thought that would be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the time
pages-build-deployment
runs for latest (cancelling the previous deployment), the updated 3.7 sources will already be committed to the gh-pages branch.pages-build-deployment
redeploys everything ingh-pages
afaik, so the nextpages-build-deployment
run will include both 3.7 and latest in the deployed changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my previous notes:
One thing that can possibly work around these issues is to always only build gh pages in a pipeline based on the base branch. the base branch gh-pages pipeline will also
clone
other versions/subdirectories and build those.then we have pipelines for version-specific branches that just trigger the base gh-pages pipeline to rebuild everything
an all-in-one pipeline at the base branch that builds root and subdirectories would also mitigate special routing requirements (i.e. we just build all the subdirectories we need)
just some thoughts..