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

GitHub action to publish docs to GH Pages #1129

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
version: 2
jobs:
st2docs:
environment:
python_version: python3.6
docker:
- image: circleci/python:3.6
steps:
Expand Down Expand Up @@ -59,7 +61,6 @@ jobs:
else
echo "Not current GA version"
fi

workflows:
version: 2
build-deploy:
Expand All @@ -72,4 +73,4 @@ workflows:
branches:
only:
- master
- /v[0-9]+\.[0-9]+/
- /v[0-9]+\.[0-9]+/
146 changes: 146 additions & 0 deletions .github/workflows/publish-docs-concurrency-test.yml
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}}
112 changes: 112 additions & 0 deletions .github/workflows/publish-docs.yml
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
Copy link
Member

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:

name: Deploy to docs.stackstorm.com
command: |
if [ "${CIRCLE_BRANCH}" = "master" ]; then
aws s3 sync generated-site/st2docs/ \
s3://${ST2DOCS_BUCKET}/latest
else
S3_OBJ=$(echo "${CIRCLE_BRANCH}" | sed 's/^v\(.*\)$/\1/')
aws s3 sync generated-site/st2docs/ \
s3://${ST2DOCS_BUCKET}/${S3_OBJ}
fi
- run:
# Check the install scripts to see if this is the current GA version
name: Check if current GA branch, in which case also deploy to main site
command: |
GA_VER=$(curl -sSL https://stackstorm.com/packages/install.sh|grep ^BRANCH=|sed 's/[^0-9.]*//g')
if [ "${CIRCLE_BRANCH}" = "v${GA_VER}" ]; then
aws s3 sync generated-site/st2docs/ \
s3://${ST2DOCS_BUCKET}/
else
echo "Not current GA version"
fi

From what I understand the logic looks this way:

  • master branch build -> /latest/ st2docs dir
  • v.X.Y.Z latest stable branch -> / st2docs dir
  • other vX.Y.Z branch build -> vX.Y st2docs dir

Copy link
Author

@mickmcgrath13 mickmcgrath13 Jun 20, 2022

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

Copy link
Author

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 point docs.stackstorm.com to docs.stackstorm.com/ga. Thoughts?

Copy link
Author

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 to gh-pages again while an existing pages-build-deployment pipeline is running, github will cancel the previous deployment in favor of the subsequent one:
image

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 existing pages-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:

  1. have some logic in the github action pipeline that modifies entries in route53/cloudfront
  2. manually update entries in route53/cloudfront as part of the GA release process

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

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

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?

Copy link
Contributor

@amanda11 amanda11 Jul 22, 2022

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.

Copy link
Member

@cognifloyd cognifloyd Jul 22, 2022

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 in gh-pages afaik, so the next pages-build-deployment run will include both 3.7 and latest in the deployed changes.

Copy link
Author

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 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.

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..


# 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"
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ DOC_BUILD_DIR := docs/build

BINARIES := bin

PYTHON_VERSION := python3.6
PYTHON_VERSION := ${python_version}

# set python version if it is not set (i.e. python_version env var not provided)
PYTHON_VERSION ?= python3.6

# All components are prefixed by st2
COMPONENTS := $(wildcard st2*)
Expand Down