From c57619cb84012ba88113302d5b0d1119a14dc2e8 Mon Sep 17 00:00:00 2001 From: tczekajlo Date: Fri, 3 Dec 2021 15:42:13 +0100 Subject: [PATCH] Update documentation workflow to only publish one version per major --- .github/workflows/documentation.yml | 64 ++++++++++++++++++++++++++++- docs/package.json | 3 +- docs/yarn.lock | 2 +- scripts/push_docs_to_branch.sh | 19 +++++---- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 2e7344111..e0341efe2 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -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 🕝 diff --git a/docs/package.json b/docs/package.json index 64b72668c..198b1069c 100644 --- a/docs/package.json +++ b/docs/package.json @@ -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": [ diff --git a/docs/yarn.lock b/docs/yarn.lock index 6861e79ac..de101b474 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -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== diff --git a/scripts/push_docs_to_branch.sh b/scripts/push_docs_to_branch.sh index 7155f6317..8076ff695 100755 --- a/scripts/push_docs_to_branch.sh +++ b/scripts/push_docs_to_branch.sh @@ -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 @@ -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 @@ -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..." @@ -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