Update AppVersion #834
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: Update AppVersion | |
on: | |
schedule: | |
# Run once a day at 08:00 | |
- cron: '0 8 * * *' | |
workflow_dispatch: {} | |
jobs: | |
open_pull_request: | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: | |
include: | |
- chart: rasa | |
app: rasa | |
- chart: rasa-action-server | |
app: rasa-x-demo | |
- chart: duckling | |
app: duckling | |
steps: | |
- name: Set up Python 3.8 π | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Checkout repository π | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Get the latest version of an app π· | |
run: | | |
DOCKERHUB_TAGS_URL="https://registry.hub.docker.com/v2/repositories/rasa/${{ matrix.app }}/tags?page_size=10000" | |
LATEST_VERSION=$(curl -s ${DOCKERHUB_TAGS_URL} | jq -r '.results[].name' | grep -E '^[0-9.]+$|^[0-9.]+(-r[0-9]+)$' | sort -Vr | head -n1) | |
echo "Latest version: ${LATEST_VERSION}" | |
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV | |
- name: Compare the latest version with a chart version β― | |
run: | | |
# Get current version in Chart.yaml using yq | |
sudo curl -L https://github.com/mikefarah/yq/releases/download/v4.9.6/yq_linux_amd64 --output /usr/local/bin/yq | |
sudo chmod +x /usr/local/bin/yq | |
CURRENT_CHART_VERSION=$(yq e .appVersion charts/${{ matrix.chart}}/Chart.yaml) | |
echo "Current appVersion: ${CURRENT_CHART_VERSION}" | |
echo "Latest version: ${LATEST_VERSION}" | |
if [[ "${CURRENT_CHART_VERSION}" == "${LATEST_VERSION}" ]] | |
then | |
echo "A newer version hasn't been found. Nothing to update." | |
echo "CREATE_UPDATE_PR=false" >> $GITHUB_ENV | |
else | |
echo "A newer version has been found. Bumping it now." | |
echo "CREATE_UPDATE_PR=true" >> $GITHUB_ENV | |
fi | |
- name: Check if duplicate branch exists π | |
run: | | |
BRANCH_NAME=$(git branch -a | grep -m 1 "bump-${{ matrix.app }}-version-to-${LATEST_VERSION}" || echo "") | |
# Set CREATE_UPDATE_PR to false if BRANCH_NAME is not empty ("") | |
if [[ ! -z ${BRANCH_NAME} ]]; then | |
echo "Found related branch ${BRANCH_NAME}." | |
echo "A PR for the ${{ matrix.chart }} chart with appVersion=${LATEST_VERSION} is already created!" | |
echo "CREATE_UPDATE_PR=false" >> $GITHUB_ENV | |
fi | |
- name: Get branch name βοΈ | |
id: get-branch-name | |
if: env.CREATE_UPDATE_PR == 'true' | |
run: | | |
echo "::set-output name=new_branch::bump-${{ matrix.app }}-version-to-${LATEST_VERSION}-${GITHUB_SHA:0:7}" | |
- name: Create new branch π£ | |
uses: peterjgrainger/action-create-branch@v2.0.1 | |
if: env.CREATE_UPDATE_PR == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
branch: ${{ steps.get-branch-name.outputs.new_branch }} | |
- name: Update Chart YAML containing the latest version π | |
if: env.CREATE_UPDATE_PR == 'true' | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git remote update origin --prune | |
git checkout ${{ steps.get-branch-name.outputs.new_branch }} | |
diff -Bwb "charts/${{ matrix.chart }}/Chart.yaml" <(yq e '.appVersion = "'${LATEST_VERSION}'"' -i charts/${{ matrix.chart }}/Chart.yaml) > /tmp/tmp_chart.patch || true | |
patch charts/${{ matrix.chart }}/Chart.yaml < /tmp/tmp_chart.patch || true | |
diff -Bwb "charts/${{ matrix.chart }}/values.yaml" <(yq e '.image.tag = "'${LATEST_VERSION}'"' charts/${{ matrix.chart }}/values.yaml) > /tmp/tmp_values.patch || true | |
patch charts/${{ matrix.chart }}/values.yaml < /tmp/tmp_values.patch || true | |
docker run --rm --volume "${{ github.workspace }}/charts/${{ matrix.chart }}/:/helm-docs" jnorwood/helm-docs:latest -d -l error > charts/${{ matrix.chart }}/README.md | |
git add -u | |
git commit -m "other: Bump version to ${LATEST_VERSION}" | |
git push origin ${{ steps.get-branch-name.outputs.new_branch }} | |
- name: Open pull request βοΈ | |
uses: repo-sync/pull-request@v2 | |
if: env.CREATE_UPDATE_PR == 'true' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
source_branch: ${{ steps.get-branch-name.outputs.new_branch }} | |
destination_branch: main | |
pr_title: "Bump the app version for the ${{ matrix.chart }} chart to ${LATEST_VERSION}" | |
pr_body: "Bump the app version for the ${{ matrix.chart }} chart to ${LATEST_VERSION}" |