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

[INFRA-1144] Segregate PyPi from Docker image job #1161

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all 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
113 changes: 37 additions & 76 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,63 @@ on:
tags:
- "*"
workflow_dispatch:
inputs:
tag_version:
description: 'Tag version:'
required: true

jobs:
build_docker_image_set_env:
name: Prepare environment for Docker build
release-artifacts-docker:
name: Release Artifacts Docker
runs-on: ubuntu-22.04
if: github.repository == 'RasaHQ/rasa-sdk'

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 }}
tag_version: ${{ steps.set-tag-version.outputs.tag_version }}

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

# 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 image_tag
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "IMAGE_TAG=${TAG_NAME}" >> $GITHUB_ENV
echo "image_tag=${{ env.IMAGE_TAG }}" >> $GITHUB_OUTPUT

- name: Set is_newest_version
id: rasa_sdk_get_version
- name: Set tag version
id: set-tag-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)
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
if [[ -n "$GITHUB_REF" && "$GITHUB_REF" == refs/tags/* ]]; then
echo "TAG_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "tag_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
elif [[ -n "$INPUT_TAG_VERSION" ]]; then
echo "TAG_VERSION=$INPUT_TAG_VERSION" >> $GITHUB_ENV
echo "tag_version=$INPUT_TAG_VERSION" >> $GITHUB_OUTPUT
else
echo "is_newest_version=false" >> $GITHUB_OUTPUT
echo "No tag version found."
exit 1
fi

build_docker_image:
name: Build Docker image
runs-on: ubuntu-22.04
needs: [ build_docker_image_set_env ]
if: github.repository == 'RasaHQ/rasa-sdk'

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

env:
INPUT_TAG_VERSION: ${{ github.event.inputs.tag_version }}

- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env.TAG_VERSION }}

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c # v3.1.0

- name: Set environment variables
run: |
echo "IMAGE_TAG=${{ needs.build_docker_image_set_env.outputs.image_tag }}" >> $GITHUB_ENV

- name: Login to Docker Hub Registry 🔢
run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin || true

- name: Build and Push Docker image 📦
run: |
IS_NEWEST_VERSION=${{ needs.build_docker_image_set_env.outputs.is_newest_version }}

# Push image
IMAGE_NAME=rasa/rasa-sdk \
IMAGE_TAG=${GITHUB_REF#refs/tags/} \
IMAGE_NAME=rasa/rasa-sdk
IMAGE_TAG="${TAG_VERSION}"
make build-and-push-multi-platform-docker

# Tag the image as latest
if [[ "${IS_NEWEST_VERSION}" == "true" ]]; then
IMAGE_TAG=latest \
make build-and-push-multi-platform-docker
fi

deploy:
name: Deploy to PyPI

release-artifacts-pypi:
name: Release Artifacts PyPI
runs-on: ubuntu-22.04

# deploy will only be run when there is a tag available
needs: [ build_docker_image ] # only run after all other stages succeeded


steps:
- name: Checkout git repository 🕝
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Python 3.10 🐍
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435
Expand Down Expand Up @@ -127,7 +89,6 @@ jobs:
skip_existing: true

- name: Publish Release Notes 🗞
if: env.IS_TAG_BUILD
env:
GITHUB_TAG: ${{ github.ref }}
GITHUB_REPO_SLUG: ${{ github.repository }}
Expand All @@ -142,7 +103,7 @@ jobs:
release-artifact-slack-notifications:
name: Release Analytics Artifact Slack Notifications
runs-on: ubuntu-22.04
needs: [build_docker_image, deploy]
needs: [release-artifacts-docker, release-artifacts-pypi]
if: always() # Ensures this job runs regardless of the result of previous jobs

steps:
Expand All @@ -161,7 +122,7 @@ jobs:
with:
# Send notification to #release slack channel
channel-id: "C024Z61K9QU"
slack-message: ":rocket: New *Rasa SDK* version `${{ env.TAG_VERSION }}` has been released! More information can be found <https://github.com/RasaHQ/rasa-sdk/releases/tag/${{ env.TAG_VERSION }}|here>."
slack-message: ":rocket: New *Rasa SDK* version `${{ needs.release-artifacts-docker.outputs.tag_version }}` has been released! More information can be found <https://github.com/RasaHQ/rasa-sdk/releases/tag/${{ env.TAG_VERSION }}|here>."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

Expand All @@ -171,6 +132,6 @@ jobs:
with:
# Send notification to #devtribe slack channel
channel-id: "C061J0LGHU0"
slack-message: ":broken_heart: *Rasa SDK* release version `${{ env.TAG_VERSION }}` has failed! More information can be found <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>."
slack-message: ":broken_heart: *Rasa SDK* release version `${{ needs.release-artifacts-docker.outputs.tag_version }}` has failed! More information can be found <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}