Skip to content

trigger-image-tag-update #88

trigger-image-tag-update

trigger-image-tag-update #88

name: Update Rasa Pro Image Tag in Docker Compose file
# This workflow updates the Rasa Pro image tag in the `docker-compose.yml` file.
# It can be triggered manually or via a repository dispatch event when a Rasa Pro version is released.
# If triggered via repository dispatch, it compares the dispatched version with the latest version on PyPI.
# If the dispatched version and the latest PyPI version match, it updates the image tag in the Docker Compose file.
# If triggered manually, it checks directly for the latest version of Rasa Pro on PyPI.
# In either case, the workflow compares the latest version with the current version in the Docker Compose file.
# If an update is needed, it creates a new branch, commits the changes, and opens a pull request.
# If no update is needed, it stops the workflow without making any changes.
on:
workflow_dispatch:
repository_dispatch:
types: [trigger-image-tag-update]
env:
PYTHON_VERSION: "3.11"
jobs:
update_rasa_pro_image_tag:
name: Update Rasa Pro Image Tag in Docker Compose
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
ref: "main" # Use main branch for the workflow
- name: Set up Python ${{ env.PYTHON_VERSION }} 🐍
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Create and activate virtual environment
run: |
python -m venv .venv
. .venv/bin/activate
echo "PATH=$PATH" >> $GITHUB_ENV
- name: Install dependencies
run:
python -m pip install pep440-version-utils
- name: Fetch latest version from pypi
id: fetch_latest_version
run: |
rasa_pro_version=$(curl -s https://pypi.org/pypi/rasa-pro/json | jq -r '.info.version')
echo "LATEST_RASA_PRO_VERSION=${rasa_pro_version}" >> $GITHUB_ENV
- name: Set dispatched version env variable
if: github.event_name == 'repository_dispatch'
run: |
echo "DISPATCHED_RASA_PRO_VERSION=${{ github.event.client_payload.version }}" >> $GITHUB_ENV
- name: Compare pypi version to the dispatched release version
id: compare_versions
if: github.event_name == 'repository_dispatch'
run: |
should_update=$(python scripts/compare_rasa_pro_versions.py | tr -d '\n')
echo "should_update=${should_update}" >> $GITHUB_OUTPUT
- name: Extract current Rasa Pro version from docker-compose.yml
id: extract_current_version
run: |
current_version=$(grep -m 1 'image: europe-west3-docker.pkg.dev/rasa-releases/rasa-pro/rasa-pro:' docker-compose.yml | awk -F ':' '{print $3}')
echo "CURRENT_RASA_PRO_VERSION=${current_version}" >> $GITHUB_ENV
- name: Update Rasa Pro Image Tag
id: update_image_tag
if: (github.event_name == 'repository_dispatch' && steps.compare_versions.outputs.should_update == 'true') || github.event_name != 'repository_dispatch'
run: |
latest_tag=$(python scripts/update_rasa_pro_image_tag.py)
echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV
- name: Check if image tag changed
id: check_image_tag
if: steps.update_image_tag.outcome == 'success'
run: |
if [ "$LATEST_TAG" != "No updates." ]; then
echo "Image tag changed from $CURRENT_RASA_PRO_VERSION to $LATEST_TAG"
echo "image_tag_changed=true" >> $GITHUB_OUTPUT
else
echo "Image tag is already up-to-date."
echo "image_tag_changed=false" >> $GITHUB_OUTPUT
fi
- name: Create source branch name
if: steps.check_image_tag.outputs.image_tag_changed == 'true'
run: |
echo "SOURCE_BRANCH=update-rasa-pro-image-tag-to-${LATEST_RASA_PRO_VERSION}-${{ github.run_id }}-${{ github.run_attempt }}" >> $GITHUB_ENV
- name: Set up git user and checkout source branch
if: steps.check_image_tag.outputs.image_tag_changed == 'true'
run: |
git config --global user.name "rasabot"
git config --global user.email "[email protected]"
git checkout -b ${{ env.SOURCE_BRANCH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update file, commit and push changes
id: commit_push_changes
if: steps.check_image_tag.outputs.image_tag_changed == 'true'
run: |
sed -i "s|image: europe-west3-docker.pkg.dev/rasa-releases/rasa-pro/rasa-pro:$CURRENT_RASA_PRO_VERSION|image: europe-west3-docker.pkg.dev/rasa-releases/rasa-pro/rasa-pro:$LATEST_TAG|" docker-compose.yml
git add docker-compose.yml
git commit -m "Update Rasa Pro image tag to ${{ env.LATEST_RASA_PRO_VERSION }}"
git push origin ${{ env.SOURCE_BRANCH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Stop the workflow if no changes were made
if: steps.check_image_tag.outputs.image_tag_changed == 'false'
run: |
echo "No changes made to the image tag. Stopping the workflow."
exit 0
- name: Create pull request
if: steps.commit_push_changes.outcome == 'success'
uses: devops-infra/action-pull-request@ff118b4a7c24bac5a3c95acef59e9edd1fc37890 #v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: ${{ env.SOURCE_BRANCH }}
target_branch: "main"
body: "**Automated pull request for Rasa Pro image tag update.**"
title: Update Rasa Pro image tag to ${{ env.LATEST_RASA_PRO_VERSION }}