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

Build docs preview and production builds in GitHub CI #10568

Merged
merged 8 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
170 changes: 165 additions & 5 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ on:
push:
branches:
- 'main'
- 'documentation'
tags:
- '**'
pull_request:

concurrency:
# group workflow runs based on the branch or the tag ref
Expand All @@ -16,6 +18,8 @@ concurrency:
# - GH_DOCS_WRITE_KEY: generated locally, added to github repo (public key)
# `ssh-keygen -t rsa -b 4096 -C "Github CI Docs Key" -N "" -f key`
# - GITHUB_TOKEN: (default, from github actions)
# - NETLIFY_AUTH_TOKEN: an access token to use when authenticating commands on Netlify
# - NETLIFY_SITE_ID: the API ID of the Netlify site for the docs

env:
DOCS_FOLDER: docs
Expand All @@ -25,10 +29,40 @@ env:
IS_MAIN_BRANCH: ${{ github.ref == 'refs/heads/main' }}

jobs:
changes:
name: Check for file changes
runs-on: ubuntu-latest
# don't run this for main branches of forks; only on pull request (not needed elsewhere)
if: github.repository == 'RasaHQ/rasa' && github.event_name == 'pull_request'
outputs:
# Both of the outputs below are strings but only one exists at any given time
backend: ${{ steps.changed-files.outputs.backend || steps.run-all.outputs.backend }}
docker: ${{ steps.changed-files.outputs.docker || steps.run-all.outputs.docker }}
docs: ${{ steps.changed-files.outputs.docs || steps.run-all.outputs.docs }}
steps:
- uses: actions/checkout@v2
- uses: RasaHQ/pr-changed-files-filter@c4f7116a04b8a4596313469429e2ad235f59d9c4
# Run the normal filters if the all-tests-required label is not set
id: changed-files
if: contains(github.event.pull_request.labels.*.name, 'status:all-tests-required') == false
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: .github/change_filters.yml
- name: Set all filters to true if all tests are required
# Set all filters to true if the all-tests-required label is set
# Bypasses all the change filters in change_filters.yml and forces all outputs to true
id: run-all
if: contains(github.event.pull_request.labels.*.name, 'status:all-tests-required')
run: |
echo "::set-output name=backend::true"
echo "::set-output name=docker::true"
echo "::set-output name=docs::true"

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
# don't run this for main branches of forks and on documentation branch
if: github.repository == 'RasaHQ/rasa' && github.ref != 'refs/heads/documentation' && github.event_name != 'pull_request'
outputs:
build_docs: ${{ steps.check_tag.outputs.build_docs }}

Expand Down Expand Up @@ -94,11 +128,12 @@ jobs:

echo "::set-output name=build_docs::false"

docs:
name: Build Docs
prebuild_docs:
name: Prebuild Docs
runs-on: ubuntu-latest
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
# don't run this for main branches of forks, would fail anyways
if: github.repository == 'RasaHQ/rasa' && needs.evaluate_release_tag.outputs.build_docs == 'true' && github.ref != 'refs/heads/documentation' && github.event_name != 'pull_request'

steps:
- name: Checkout git repository 🕝
Expand Down Expand Up @@ -144,7 +179,7 @@ jobs:
- name: Pre-build Docs 🧶
run: make prepare-docs

- name: Build & Publish Docs 🏃‍♀️
- name: Push docs to documentation branch 🏃‍♀️
env:
GH_DOCS_WRITE_KEY: ${{ secrets.GH_DOCS_WRITE_KEY }}
TMP_DOCS_FOLDER: /tmp/documentation-${{ github.run_id }}
Expand All @@ -169,3 +204,128 @@ jobs:
channel_id: ${{ secrets.SLACK_ALERTS_CHANNEL_ID }}
status: FAILED
color: warning


preview_docs:
name: Preview Docs
runs-on: ubuntu-latest
needs: [ changes ]
# don't run this for main branches of forks; only run on pull requests
if: github.repository == 'RasaHQ/rasa' && github.event_name == 'pull_request'

steps:
- name: Checkout git repository 🕝
if: needs.changes.outputs.docs == 'true'
uses: actions/checkout@v2

- name: Set up Python 3.7 🐍
if: needs.changes.outputs.docs == 'true'
uses: actions/setup-python@dc73133d4da04e56a135ae2246682783cc7c7cb6 # v2.2.2
with:
python-version: 3.7

- name: Set up Node 12.x 🦙
if: needs.changes.outputs.docs == 'true'
uses: actions/[email protected]
with:
node-version: '12.x'

- name: Read Poetry Version 🔢
if: needs.changes.outputs.docs == 'true'
run: |
echo "POETRY_VERSION=$(scripts/poetry-version.sh)" >> $GITHUB_ENV
shell: bash

- name: Install poetry 🦄
if: needs.changes.outputs.docs == 'true'
uses: Gr1N/setup-poetry@v7
with:
poetry-version: ${{ env.POETRY_VERSION }}

- name: Load Poetry Cached Libraries ⬇
if: needs.changes.outputs.docs == 'true'
uses: actions/cache@v1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ env.POETRY_VERSION }}-3.7-non-full-${{ hashFiles('**/poetry.lock') }}-${{ secrets.POETRY_CACHE_VERSION }}
restore-keys: ${{ runner.os }}-poetry-3.7-non-full

- name: Load Yarn Cached Packages ⬇
if: needs.changes.outputs.docs == 'true'
uses: actions/cache@v1
with:
path: docs/node_modules
key: ${{ runner.os }}-yarn-12.x-${{ hashFiles('docs/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-12.x

- name: Install Dependencies 📦
if: needs.changes.outputs.docs == 'true'
run: make install install-docs

- name: Pre-build Docs 🧶
if: needs.changes.outputs.docs == 'true'
run: make prepare-docs

- name: Preview draft build 🔬
if: needs.changes.outputs.docs == 'true'
id: preview_draft_build
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
DOCS_SITE_BASE_URL: /docs/rasa
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
run: |
make preview-docs
DEPLOY_URL="https://$PULL_REQUEST_NUMBER--rasahq-docs-rasa-v2.netlify.app${DOCS_SITE_BASE_URL}"
echo "::set-output name=preview_url::$DEPLOY_URL"

- name: Create a comment with help description
if: needs.changes.outputs.docs == 'true'
uses: RasaHQ/create-comment@v1
with:
mode: 'delete-previous'
id: comment_docs_previews
github-token: ${{ secrets.GITHUB_TOKEN }}
body: |
🚀 A preview of the docs have been deployed at the following URL: ${{ steps.preview_draft_build.outputs.preview_url }}

publish_docs:
name: Publish Docs
runs-on: ubuntu-latest
# don't run this for main branches of forks; only run on documentation branch
if: github.repository == 'RasaHQ/rasa' && github.ref == 'refs/heads/documentation'

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

- name: Set up Node 12.x 🦙
uses: actions/[email protected]
with:
node-version: '12.x'

- name: Load Yarn Cached Packages ⬇
uses: actions/cache@v1
with:
path: docs/node_modules
key: ${{ runner.os }}-yarn-12.x-${{ hashFiles('docs/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-12.x

- name: Install Dependencies 📦
run: make install-docs

- name: Publish production build ✅
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: make publish-docs

- name: Notify slack on failure
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@212e9f7a9ca33368c8dd879d6053972128258985 # v1.5.0
with:
channel_id: ${{ secrets.SLACK_ALERTS_CHANNEL_ID }}
status: FAILED
color: warning
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ docs: prepare-docs
livedocs:
cd docs/ && poetry run yarn start

preview-docs:
cd docs/ && yarn build && yarn deploy-preview --alias=${PULL_REQUEST_NUMBER} --message="Preview for Pull Request #${PULL_REQUEST_NUMBER}"

publish-docs:
cd docs/ && yarn build && yarn deploy

release:
poetry run python scripts/release.py

Expand Down
2 changes: 2 additions & 0 deletions changelog/10568.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update documentation workflows to build production builds in GitHub CI. Provide docs deploy previews to
pull requests that introduce docs changes.
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"develop": "docusaurus start --port 3000",
"build": "docusaurus build --out-dir build/docs/rasa",
"serve": "netlify dev --dir=build --port=5000",
"deploy": "netlify deploy --dir=build --alias=staging --open",
"deploy-preview": "netlify deploy --dir=build",
"deploy": "netlify deploy --dir=build --prod",
"new-version": "docusaurus docs:version",
"variables": "node scripts/compile_variables.js",
"program-outputs": "node scripts/compile_program_outputs.js",
Expand Down