Skip to content

Commit

Permalink
Merge pull request #9731 from RasaHQ/update_docs_workflow
Browse files Browse the repository at this point in the history
Update documentation workflow to only publish one version per major
  • Loading branch information
m-vdb authored Oct 6, 2021
2 parents 52f036c + 1f97f69 commit 6d01906
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 6 deletions.
75 changes: 74 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,85 @@ 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' # 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 version
id: rasa_get_version
run: |
# Get latest tagged Rasa version
git fetch --depth=1 origin "+refs/tags/*:refs/tags/*"
# Fetch branch history
git fetch --prune --unshallow
LATEST_TAGGED_NON_ALPHA_RASA_VERSION=$(git tag | sort -r -V | grep -E "^[0-9.]+$" | head -n1)
echo "LATEST_TAGGED_NON_ALPHA_RASA_VERSION=${LATEST_TAGGED_NON_ALPHA_RASA_VERSION}" >> $GITHUB_ENV
# Return 'true' if tag version is equal or higher than the latest tagged Rasa version
IS_LATEST_VERSION=$((printf '%s\n%s\n' "${LATEST_TAGGED_NON_ALPHA_RASA_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_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_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' # don't run this for main branches of forks, would fail anyways
needs: [ evaluate_release_tag ]
if: github.repository == 'RasaHQ/rasa' && 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
12 changes: 7 additions & 5 deletions scripts/push_docs_to_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ 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/
Expand All @@ -33,10 +33,12 @@ NEW_VERSION=
EXISTING_VERSION=
if [[ "$GITHUB_REF" =~ $PATTERN_FOR_NEW_VERSION ]]
then
NEW_VERSION=$(echo $GITHUB_REF | sed -E "s/^refs\/tags\/([0-9]+)\.([0-9]+)\.0$/\1.\2.x/")
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.x/")
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 Down

0 comments on commit 6d01906

Please sign in to comment.