Skip to content

Commit

Permalink
Merge pull request #620 from RasaHQ/fix_docs
Browse files Browse the repository at this point in the history
Update documentation workflow to only publish one version per major
  • Loading branch information
Tomasz Czekajlo authored Dec 6, 2021
2 parents 0d031ea + c57619c commit a55d1c0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
64 changes: 63 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,74 @@ on:
env:
DOCS_FOLDER: docs
DOCS_BRANCH: documentation
TAG_NAME: ${GITHUB_REF#refs/tags/}
IS_TAG_BUILD: ${{ startsWith(github.event.ref, 'refs/tags') }}
IS_MASTER_BRANCH: ${{ github.ref == 'refs/heads/main' }}

jobs:
evaluate_release_tag:
name: Evaluate release tag
runs-on: ubuntu-latest
if: github.repository == 'RasaHQ/rasa-sdk' # don't run this for main branches of forks, would fail anyways
outputs:
build_docs: ${{ steps.check_tag.outputs.build_docs }}

steps:
- name: Checkout git repository 🕝
uses: actions/checkout@v2

- name: Check if tag version is equal or higher than the latest tagged Rasa SDK version
id: rasa_sdk_get_version
run: |
# Get latest tagged Rasa SDK version
git fetch --depth=1 origin "+refs/tags/*:refs/tags/*"
# Fetch branch history
git fetch --prune --unshallow
LATEST_TAGGED_NON_ALPHA_RASA_SDK_VERSION=$(git tag | sort -r -V | grep -E "^[0-9.]+$" | head -n1)
echo "LATEST_TAGGED_NON_ALPHA_RASA_SDK_VERSION=${LATEST_TAGGED_NON_ALPHA_RASA_SDK_VERSION}" >> $GITHUB_ENV
# Return 'true' if tag version is equal or higher than the latest tagged Rasa SDK version
IS_LATEST_VERSION=$((printf '%s\n%s\n' "${LATEST_TAGGED_NON_ALPHA_RASA_SDK_VERSION}" "$TAG_NAME" \
| sort -V -C && echo true || echo false) || true)
if [[ "${IS_LATEST_VERSION}" == "true" && "$TAG_NAME" =~ ^[0-9.]+$ ]]; then
echo "::set-output name=is_latest_version::true"
else
echo "::set-output name=is_latest_version::false"
fi
# MAJOR.MINOR.MICRO(PATCH)
# docs are built on every minor tag for the latest major (when 3.0 is out, the latest major is 3.0)
# (technically it'll be always the latest version)
#
# docs are built on every micro tag for the latest minor of
# - the latest major (when 3.0 is out, the latest major is 3.0)
# - the previous major (when 3.0 is out, the previous major is 2.0, the latest minor on this version being 2.8)
- name: Check if it's a micro tag for the latest minor
if: env.IS_TAG_BUILD == 'true'
id: check_tag
run: |
IS_LATEST_VERSION=${{ steps.rasa_sdk_get_version.outputs.is_latest_version }}
# the latest major (when 3.0 is out, the latest major is 3.0)
# build docs on push to the main branch
if [[ "${IS_LATEST_VERSION}" == "true" || "${IS_MASTER_BRANCH}" == "true" ]]; then
echo "::set-output name=build_docs::true"
exit 0
fi
# the previous major (when 3.0 is out, the previous major is 2.0, the latest minor on this version being 2.8)
CURRENT_MAJOR_VERSION=$(echo ${LATEST_TAGGED_NON_ALPHA_RASA_SDK_VERSION} | awk -F\. '{print $1}')
PREVIOUS_MAJOR_LATEST_VERSION=$(git tag | sort -r -V | grep -E "^[0-9.]+$" | grep -vE "^${CURRENT_MAJOR_VERSION}" | head -n1)
# Return 'true' if tag version is equal or higher than the latest previous major version
IS_PREVIOUS_MAJOR_LATEST_VERSION=$((printf '%s\n%s\n' "${PREVIOUS_MAJOR_LATEST_VERSION}" "$TAG_NAME" \
| sort -V -C && echo true || echo false) || true)
if [[ "${IS_PREVIOUS_MAJOR_LATEST_VERSION}" == "true" ]]; then
echo "::set-output name=build_docs::true"
exit 0
fi
echo "::set-output name=build_docs::false"
docs:
name: Build Docs
runs-on: ubuntu-latest
if: github.repository == 'RasaHQ/rasa-sdk' # don't run this for main branches of forks, would fail anyways
needs: [ evaluate_release_tag ]
if: github.repository == 'RasaHQ/rasa-sdk' && needs.evaluate_release_tag.outputs.build_docs == 'true' # don't run this for main branches of forks, would fail anyways

steps:
- name: Checkout git repository 🕝
Expand Down
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"remark-sources": "^1.1.0",
"sass": "^1.26.10",
"sass-loader": "^9.0.3",
"styled-components": "^4.2.0"
"styled-components": "^4.2.0",
"fs-extra": "^9.0.1"
},
"browserslist": {
"production": [
Expand Down
2 changes: 1 addition & 1 deletion docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8718,7 +8718,7 @@ fs-extra@^8.1, fs-extra@^8.1.0:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^9.0:
fs-extra@^9.0, fs-extra@^9.0.1:
version "9.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
Expand Down
19 changes: 12 additions & 7 deletions scripts/push_docs_to_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ set -Eeuo pipefail

TODAY=`date "+%Y%m%d"`
# we build new versions only for minors and majors
PATTERN_FOR_NEW_VERSION="^refs/tags/[0-9]+\\.[0-9]+\\.0$"
PATTERN_FOR_MICRO_VERSION="^refs/tags/[0-9]+\\.[0-9]+\\.[1-9][0-9]*$"
PATTERN_FOR_NEW_VERSION="^refs/tags/[0-9]+\\.0\\.0$"
PATTERN_FOR_EXISTING_VERSION="^refs/tags/[0-9]+\\.[0-9]+\\.[0-9]+$"
MAIN_REF=refs/heads/main
VARIABLES_JSON=docs/docs/variables.json
SOURCES_FILES=docs/docs/sources/
CHANGELOG=docs/docs/changelog.mdx

[[ ! $GITHUB_REF =~ $PATTERN_FOR_NEW_VERSION ]] \
&& [[ ! $GITHUB_REF =~ $PATTERN_FOR_MICRO_VERSION ]] \
&& [[ ! $GITHUB_REF =~ $PATTERN_FOR_EXISTING_VERSION ]] \
&& [[ $GITHUB_REF != $MAIN_REF ]] \
&& echo "Not on main or tagged version, skipping." \
&& exit 0
Expand All @@ -31,10 +31,12 @@ NEW_VERSION=
EXISTING_VERSION=
if [[ "$GITHUB_REF" =~ $PATTERN_FOR_NEW_VERSION ]]
then
NEW_VERSION=${GITHUB_REF/refs\/tags\//}
elif [[ "$GITHUB_REF" =~ $PATTERN_FOR_MICRO_VERSION ]]
NEW_VERSION=$(echo $GITHUB_REF | sed -E "s/^refs\/tags\/([0-9]+)\.([0-9]+)\.0$/\1.x/")
if [[ -n ${CI} ]]; then echo "New version: ${NEW_VERSION}"; fi
elif [[ "$GITHUB_REF" =~ $PATTERN_FOR_EXISTING_VERSION ]]
then
EXISTING_VERSION=$(echo $GITHUB_REF | sed -E "s/^refs\/tags\/([0-9]+)\.([0-9]+)\.[0-9]+$/\1.\2.0/")
EXISTING_VERSION=$(echo $GITHUB_REF | sed -E "s/^refs\/tags\/([0-9]+)\.([0-9]+)\.[0-9]+$/\1.x/")
if [[ -n ${CI} ]]; then echo "Existing version: ${EXISTING_VERSION}"; fi
fi

# clone the $DOCS_BRANCH in a temp directory
Expand All @@ -46,6 +48,9 @@ then
EXISTING_VERSION=$NEW_VERSION
fi

# install yarn dependencies in the temp directory
cd $TMP_DOCS_FOLDER/docs && yarn install && cd - || exit 1

if [ ! -z "$EXISTING_VERSION" ]
then
echo "Updating docs for existing version $EXISTING_VERSION..."
Expand All @@ -71,7 +76,7 @@ fi
CURRENTLY_EDITING_VERSION=${EXISTING_VERSION:-$NEW_VERSION}
if [ -n "$CURRENTLY_EDITING_VERSION" ]
then
cd $TMP_DOCS_FOLDER/docs && yarn run update-versioned-sources -- $CURRENTLY_EDITING_VERSION && cd -
cd $TMP_DOCS_FOLDER/docs && yarn run update-versioned-sources $CURRENTLY_EDITING_VERSION && cd - || exit 1
fi

cd $TMP_DOCS_FOLDER
Expand Down

0 comments on commit a55d1c0

Please sign in to comment.