-
Notifications
You must be signed in to change notification settings - Fork 5
109 lines (99 loc) · 3.97 KB
/
on_kafka_update_available.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 }}