Merge pull request #1011 from RasaHQ/prepare-release-3.8.0a1 #1960
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "*" | |
pull_request: | |
env: | |
IS_TAG_BUILD: ${{ startsWith(github.event.ref, 'refs/tags') }} | |
# SECRETS | |
# - PYPI_TOKEN: publishing token for amn41 account, needs to be maintainer of | |
# RasaHQ/rasa-sdk on pypi (account credentials in 1password) | |
jobs: | |
quality: | |
name: Code Quality | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout git repository 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
- name: Set up Python 3.10 🐍 | |
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 | |
with: | |
python-version: '3.10' | |
- name: Read Poetry Version 🔢 | |
run: | | |
echo "POETRY_VERSION=$(scripts/poetry-version.sh)" >> $GITHUB_ENV | |
shell: bash | |
- name: Install poetry 🦄 | |
uses: Gr1N/setup-poetry@15821dc8a61bc630db542ae4baf6a7c19a994844 | |
with: | |
poetry-version: ${{ env.POETRY_VERSION }} | |
- name: Load Poetry Cached Libraries ⬇ | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
with: | |
path: ~/.cache/pypoetry/virtualenvs | |
key: ${{ runner.os }}-poetry-3.10-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: ${{ runner.os }}-poetry- | |
- name: Checkout target branch to be able to diff | |
if: github.event_name == 'pull_request' | |
run: | | |
git fetch origin "${{ github.base_ref }}" | |
echo "DOCSTRING_DIFF_BRANCH=origin/${{ github.base_ref }}" >> $GITHUB_ENV | |
# Fetch entire history for current branch so that `make lint-docstrings` | |
# can calculate the proper diff between the branches | |
git fetch --unshallow origin "${{ github.ref }}" | |
- name: Install Dependencies 📦 | |
run: make install | |
- name: Lint Code 🎎 | |
run: | | |
# If it's not a pull request, $DOCSTRING_DIFF_BRANCH is unset. | |
# This will result in an empty diff, which effictively means that | |
# make lint-docstrings will be skipped for other events than `pull_request` | |
make lint BRANCH=$DOCSTRING_DIFF_BRANCH | |
- name: Check Types 📚 | |
run: make types | |
test: | |
name: Run Tests | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: | |
python-version: [3.8, 3.9, '3.10'] | |
steps: | |
- name: Checkout git repository 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
- name: Set up Python ${{ matrix.python-version }} 🐍 | |
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Read Poetry Version 🔢 | |
run: | | |
echo "POETRY_VERSION=$(scripts/poetry-version.sh)" >> $GITHUB_ENV | |
shell: bash | |
- name: Install poetry 🦄 | |
uses: Gr1N/setup-poetry@15821dc8a61bc630db542ae4baf6a7c19a994844 | |
with: | |
poetry-version: ${{ env.POETRY_VERSION }} | |
- name: Load Poetry Cached Libraries ⬇ | |
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
with: | |
path: ~/.cache/pypoetry/virtualenvs | |
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: ${{ runner.os }}-poetry- | |
- name: Install Dependencies 📦 | |
run: make install | |
- name: Test Code 🔍 | |
run: make test | |
- name: Send Coverage Report 📊 | |
if: matrix.python-version == '3.10' | |
env: | |
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
COVERALLS_SERVICE_NAME: github | |
run: poetry run coveralls | |
docker_linter: | |
name: Lint Dockerfile | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
- name: Lint Dockerfile | |
uses: brpaz/hadolint-action@1623ba61710b974b55ba455930e6f2c8ef919778 | |
with: | |
dockerfile: "Dockerfile" | |
build_docker_image_set_env: | |
name: Prepare environment for Docker build | |
runs-on: ubuntu-22.04 | |
outputs: | |
# Tag name used for intermediate images created during Docker image builds, e.g. 3886 - a PR number | |
image_tag: ${{ steps.set_output.outputs.image_tag }} | |
# Return 'true' if tag version is equal or higher than the latest tagged rasa-sdk version | |
is_newest_version: ${{ steps.rasa_sdk_get_version.outputs.is_newest_version }} | |
steps: | |
# Due to an issue with checking out a wrong commit, we make sure | |
# to checkout HEAD commit for a pull request. | |
# More details: https://github.com/actions/checkout/issues/299 | |
- name: Checkout pull request HEAD commit instead of merge commit 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
if: github.event_name == 'pull_request' | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout git repository 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
if: github.event_name != 'pull_request' | |
# Set environment variables for a pull request | |
# | |
# In this scenario, we've created a PR #1234 | |
# | |
# Example output: | |
# IMAGE_TAG=1234 | |
- name: Set environment variables - pull_request | |
if: github.event_name == 'pull_request' && env.IS_TAG_BUILD == 'false' | |
run: | | |
echo "IMAGE_TAG=${{ github.event.number }}" >> $GITHUB_ENV | |
# Set environment variables for a tag | |
# | |
# In this scenario, we've pushed the '2.4.1' tag | |
# | |
# Example output: | |
# IMAGE_TAG=2.4.1 | |
- name: Set environment variables - push - tag | |
if: github.event_name == 'push' && env.IS_TAG_BUILD == 'true' | |
run: | | |
TAG_NAME=${GITHUB_REF#refs/tags/} | |
echo "IMAGE_TAG=${TAG_NAME}" >> $GITHUB_ENV | |
# Set environment variables for a branch | |
# | |
# In this scenario, we've pushed changes into the main branch | |
# | |
# Example output: | |
# IMAGE_TAG=main | |
- name: Set environment variables - push - branch | |
if: github.event_name == 'push' && env.IS_TAG_BUILD == 'false' | |
run: | | |
BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
echo "IMAGE_TAG=${BRANCH_NAME}" >> $GITHUB_ENV | |
- name: Set output | |
id: set_output | |
run: | | |
echo "image_tag=${{ env.IMAGE_TAG }}" >> $GITHUB_OUTPUT | |
- name: Check if tag version is equal or higher than the latest tagged rasa-sdk version | |
id: rasa_sdk_get_version | |
if: env.IS_TAG_BUILD == 'true' | |
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) | |
CURRENT_TAG=${GITHUB_REF#refs/tags/} | |
# Return 'true' if tag version is equal or higher than the latest tagged rasa-sdk version | |
IS_NEWEST_VERSION=$((printf '%s\n%s\n' "${LATEST_TAGGED_NON_ALPHA_RASA_SDK_VERSION}" "$CURRENT_TAG" \ | |
| sort -V -C && echo true || echo false) || true) | |
if [[ "${IS_NEWEST_VERSION}" == "true" && "$CURRENT_TAG" =~ ^[0-9.]+$ ]]; then | |
echo "is_newest_version=true" >> $GITHUB_OUTPUT | |
else | |
echo "is_newest_version=false" >> $GITHUB_OUTPUT | |
fi | |
build_docker_image: | |
name: Build Docker image | |
runs-on: ubuntu-22.04 | |
needs: [quality, test, docker_linter, build_docker_image_set_env] | |
steps: | |
# Due to an issue with checking out a wrong commit, we make sure | |
# to checkout HEAD commit for a pull request. | |
# More details: https://github.com/actions/checkout/issues/299 | |
- name: Checkout pull request HEAD commit instead of merge commit 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
if: github.event_name == 'pull_request' | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout git repository 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
if: github.event_name != 'pull_request' | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c | |
with: | |
version: v0.5.1 | |
driver: docker | |
- name: Set environment variables | |
run: | | |
echo "IMAGE_TAG=${{ needs.build_docker_image_set_env.outputs.image_tag }}" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: | | |
docker buildx bake --load | |
- name: Login to Docker Hub Registry 🔢 | |
if: github.event_name == 'push' && env.IS_TAG_BUILD == 'true' && github.repository == 'RasaHQ/rasa-sdk' | |
run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin || true | |
- name: Push Docker image 📦 | |
if: github.event_name == 'push' && env.IS_TAG_BUILD == 'true' && github.repository == 'RasaHQ/rasa-sdk' | |
run: | | |
IS_NEWEST_VERSION=${{ needs.build_docker_image_set_env.outputs.is_newest_version }} | |
# Push image | |
docker push rasa/rasa-sdk:${IMAGE_TAG} | |
# Tag the image as latest | |
if [[ "${IS_NEWEST_VERSION}" == "true" ]]; then | |
docker tag rasa/rasa-sdk:${IMAGE_TAG} rasa/rasa-sdk:latest | |
docker push rasa/rasa-sdk:latest | |
fi | |
deploy: | |
name: Deploy to PyPI | |
runs-on: ubuntu-22.04 | |
# deploy will only be run when there is a tag available | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
needs: [quality, test, build_docker_image] # only run after all other stages succeeded | |
steps: | |
- name: Checkout git repository 🕝 | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
- name: Set up Python 3.10 🐍 | |
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 | |
with: | |
python-version: '3.10' | |
- name: Read Poetry Version 🔢 | |
run: | | |
echo "POETRY_VERSION=$(scripts/poetry-version.sh)" >> $GITHUB_ENV | |
shell: bash | |
- name: Install poetry 🦄 | |
uses: Gr1N/setup-poetry@15821dc8a61bc630db542ae4baf6a7c19a994844 | |
with: | |
poetry-version: ${{ env.POETRY_VERSION }} | |
- name: Build ⚒️ Distributions | |
run: poetry build | |
- name: Publish to PyPI 📦 | |
uses: pypa/gh-action-pypi-publish@bea5cda687c2b79989126d589ef4411bedce0195 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_TOKEN }} | |
skip_existing: true | |
- name: Publish Release Notes 🗞 | |
if: env.IS_TAG_BUILD | |
env: | |
GITHUB_TAG: ${{ github.ref }} | |
GITHUB_REPO_SLUG: ${{ github.repository }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
GITHUB_TAG=${GITHUB_TAG/refs\/tags\//} | |
sudo apt-get update | |
sudo apt-get -y install pandoc | |
pip install -U github3.py pep440_version_utils | |
python3 ${GITHUB_WORKSPACE}/scripts/publish_gh_release_notes.py | |
- name: Get RASA SDK Version | |
env: | |
RASA_SDK_VERSION: ${{ github.ref }} | |
run: | | |
echo "RASA_SDK_VERSION=${RASA_SDK_VERSION/refs\/tags\//}" >> $GITHUB_ENV | |
- name: Notify Slack 💬 | |
if: env.IS_TAG_BUILD && success() | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
uses: Ilshidur/[email protected] | |
with: | |
args: "⚡ New *Rasa SDK* version ${{ env.RASA_SDK_VERSION }} has been released! Changelog: https://github.com/RasaHQ/rasa-sdk/blob/${{ env.RASA_SDK_VERSION }}/CHANGELOG.mdx" | |
- name: Notify Slack of Failure ⛔ | |
if: env.IS_TAG_BUILD && failure() | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
uses: Ilshidur/[email protected] | |
with: | |
args: "⛔️ *Rasa SDK* version ${{ env.RASA_SDK_VERSION }} could not be released 😱 GitHub Actions: https://github.com/RasaHQ/rasa-sdk/actions?query=branch%3A${{ env.RASA_SDK_VERSION }}" |