-
Notifications
You must be signed in to change notification settings - Fork 308
109 lines (92 loc) · 3.57 KB
/
bump.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: bump
on: 'pull_request'
permissions:
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git checkout -b "$GITHUB_HEAD_REF"
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install semver
run: |-
npm install -g semver
- name: Bump
run: |-
set -e
push=0
config='[
{
"directory": "helm/charts/nack",
"dependencyName": "natsio/jetstream-controller"
},
{
"directory": "helm/charts/nats-kafka",
"dependencyName": "natsio/nats-kafka"
},
{
"directory": "helm/charts/nats-operator",
"dependencyName": "connecteverything/nats-operator"
},
{
"directory": "helm/charts/nats",
"dependencyName": "nats"
},
{
"directory": "helm/charts/surveyor",
"dependencyName": "natsio/nats-surveyor"
}
]'
deps='${{ steps.dependabot-metadata.outputs.updated-dependencies-json }}'
for i in $(seq 0 "$(("$(echo "$config" | jq length) - 1"))"); do
directory="$(echo "$config" | jq -r ".[$i].directory")"
dependencyName="$(echo "$config" | jq -r ".[$i].dependencyName")"
match="$(echo "$deps" | jq ".[] | select(.directory == \"/$directory\" and .dependencyName == \"$dependencyName\")")"
if [ -z "$match" ]; then
continue
fi
updateType="$(echo "$match" | jq -r ".updateType")"
prevVersion="$(echo "$match" | jq -r ".prevVersion")"
newVersion="$(echo "$match" | jq -r ".newVersion")"
echo "directory : $directory"
echo "dependencyName : $dependencyName"
echo "updateType : $updateType"
echo "prevVersion : $prevVersion"
echo "newVersion : $newVersion"
prevChartVersion=$(sed -rn 's/^version:\s+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' "$directory/Chart.yaml")
echo "prevChartVersion : $prevChartVersion"
semverIncr="patch"
if [ $updateType = "version-update:semver-major" ]; then
semverIncr="major"
if echo "$prevChartVersion" | grep -q "^0\."; then
semverIncr="minor"
fi
elif [ $updateType = "version-update:semver-minor" ]; then
semverIncr="minor"
fi
newChartVersion=$(semver -i "$semverIncr" "$prevChartVersion")
echo "newChartVersion : $newChartVersion"
sed -i "s|^appVersion:\s.*|appVersion: $newVersion|;s|^version:\s.*|version: $newChartVersion|" "$directory/Chart.yaml"
git add "$directory/Chart.yaml"
if git commit -m "[$(basename "$directory") helm] bump chart to version: $newChartVersion appVersion: $newVersion"; then
push=1
fi
done
if [ "$push" = "1" ]; then
git push -u origin "$GITHUB_HEAD_REF"
fi