-
Notifications
You must be signed in to change notification settings - Fork 61
89 lines (72 loc) · 2.62 KB
/
deps-release-detect.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
name: Deps Release
on: 'pull_request'
permissions:
contents: write
jobs:
detect:
name: Detect
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Checkout
uses: actions/checkout@v4
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@v2
- name: Install node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install semver
run: |-
npm install -g semver
- name: Bump
run: |-
set -e
push=0
config='[
{
"directory": "cicd",
"dependencyName": "alpine"
}
]'
deps_file="./cicd/tag-deps-version.txt"
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"
tagPrevVersion="$(git ls-remote 2>/dev/null \
| grep -oE 'refs/tags/v[0-9]+\.[0-9]+\.[0-9]+' \
| cut -d'/' -f3 \
| xargs semver \
| tail -n 1)"
tagNewVersion="$(semver -i patch "$tagPrevVersion")"
echo "$tagPrevVersion" > "$deps_file"
echo "$tagNewVersion" >> "$deps_file"
git add "$deps_file"
if git commit -m "bump dependency release to $tagNewVersion"; then
push=1
fi
done
if [ "$push" = "1" ]; then
git push -u origin "$GITHUB_HEAD_REF"
fi