-
Notifications
You must be signed in to change notification settings - Fork 29
112 lines (94 loc) · 4.62 KB
/
update_app_version.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
110
111
112
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/[email protected]
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 [email protected]
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}"