Skip to content

Detect upstream Kafka updates #481

Detect upstream Kafka updates

Detect upstream Kafka updates #481

name: Detect upstream Kafka updates
env:
BASE_BRANCH: 3/edge
UPDATE_BRANCH: bot/update-kafka-version
on:
workflow_dispatch:
schedule:
- cron: '00 16 * * *'
jobs:
check:
name: Check if Kafka update is available
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- id: checkout
name: Checkout repo
uses: actions/checkout@v3
with:
ref: ${{ env.BASE_BRANCH }}
- id: get-current-version
name: Retrieve workload version
run: |
VERSION=$(yq '(.version|split("-"))[0]' snap/snapcraft.yaml)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
echo "risk=${BRANCH##*\/}" >> $GITHUB_OUTPUT
echo "track=${BRANCH%*\/*}" >> $GITHUB_OUTPUT
- id: check-latest-version
name: Check latest stable Kafka version available for download
run: |
LATEST_STABLE_VERSION=$(curl --silent https://downloads.apache.org/kafka/ | grep "\[DIR\]" | cut -d'>' -f3 | cut -d'/' -f1 | grep "^${{ steps.get-current-version.outputs.track }}" | sort | tail -n 1)
CURRENT_PUBLISHED_VERSION=${{ steps.get-current-version.outputs.version }}
STATUSCODE=$(curl --silent --head https://downloads.apache.org/kafka/${LATEST_STABLE_VERSION}/kafka_2.13-${LATEST_STABLE_VERSION}.tgz | head -n 1 | cut -d' ' -f2)
if [[ ${LATEST_STABLE_VERSION} != ${CURRENT_PUBLISHED_VERSION} ]] && [[ ${STATUSCODE} -eq 200 ]]
then
echo "decision=1" >> $GITHUB_OUTPUT
echo "New Kafka version available....."
else
echo "decision=0" >> $GITHUB_OUTPUT
echo "No updates to Kafka detected!"
fi
echo "version=${LATEST_STABLE_VERSION}" >> $GITHUB_OUTPUT
outputs:
decision: ${{ steps.check-latest-version.outputs.decision }}
latest: ${{ steps.check-latest-version.outputs.version }}
current: ${{ steps.get-current-version.outputs.version }}
create-or-update-pull-request:
name: Create or update pull request
if: needs.check.outputs.decision == '1'
runs-on: ubuntu-latest
timeout-minutes: 5
needs:
- check
steps:
- id: checkout
name: Checkout repo
uses: actions/checkout@v3
with:
ref: ${{ env.BASE_BRANCH }}
- id: record_latest_version
name: Record updated Kafka version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b ${{ env.UPDATE_BRANCH}}
# Update snapcraft file
sed -i "/^version:/s/${{ needs.check.outputs.current }}/${{ needs.check.outputs.latest }}/" snap/snapcraft.yaml
git add ./snap/snapcraft.yaml
git commit -m "Update Kafka Snap"
git push --set-upstream -f origin ${{ env.UPDATE_BRANCH}}
- id: check
name: Check if a PR already exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prs=$(gh pr list \
--json baseRefName,headRefName \
--jq '
map(select(.baseRefName == "${{ env.BASE_BRANCH }}" and .headRefName == "${{ env.UPDATE_BRANCH}}" ))
| length
')
if ((prs > 0)); then
echo "skip=true" >> "$GITHUB_OUTPUT"
fi
- name: create pull request
if: '!steps.check.outputs.skip'
id: cpr
run: gh pr create
--title "Update snap for new Kafka version"
--body "Update client snap with new version of Apache Kafka."
--base "${{ env.BASE_BRANCH }}"
--assignee deusebio
--reviewer deusebio
--label "automated pr"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}