Skip to content

Commit 63afb96

Browse files
maksym-iv-efkgrubb
andauthored
feat: Support multiple YAML keys update (#14)
* feat: Support multiple YAML keys update Support for multiple YAML keys update in the prepare-release action * Update actions/prepare-release/bump_yaml.sh Co-authored-by: Keli (Madison) Grubb <keligrubb324@gmail.com> --------- Co-authored-by: Keli (Madison) Grubb <keligrubb324@gmail.com>
1 parent e99a4ad commit 63afb96

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

actions/prepare-release/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ inputs:
2222
Required if `bump_version_yaml`
2323
bump_version_yaml_key:
2424
description: |
25-
Version key in the YAML file, in the [yq](https://mikefarah.gitbook.io/yq) format
25+
Version key in the YAML file, in the [yq](https://mikefarah.gitbook.io/yq) format.
26+
Coma-separated list of keys are supported (no spaces)
2627
Required if `bump_version_yaml`
2728
# Sensitive inputs
2829
github_token:
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env bash
22
set -e
3-
set -x
43

54
yaml_path=$1
65
yaml_key=$2
@@ -10,14 +9,22 @@ if [ -z "${yaml_path}" ]; then echo "'yaml_path (\$1)' is not set, exiting"; exi
109
if [ -z "${yaml_key}" ]; then echo "'yaml_key (\$2)' is not set, exiting"; exit 1; fi
1110
if [ -z "${new_release_version}" ]; then echo "'new_release_version (\$3)' is not set, exiting"; exit 1; fi
1211

13-
yq "${yaml_key} = \"${new_release_version}\"" ${yaml_path} > /tmp/new.yaml
14-
if grep -q ${new_release_version} /tmp/new.yaml; then
15-
echo 'Version update succeed, new:'
16-
grep ${new_release_version} /tmp/new.yaml
17-
else
18-
echo 'Version update failed, exiting'
19-
exit 1
20-
fi
12+
keys=$(echo $yaml_key | tr ',' '\n')
2113

22-
diff -U0 -w -b --ignore-blank-lines ${yaml_path} /tmp/new.yaml > /tmp/version.diff || true
23-
patch ${yaml_path} < /tmp/version.diff
14+
update_yaml_key() {
15+
yq "${1} = \"${new_release_version}\"" ${yaml_path} > /tmp/new.yaml
16+
if grep -q ${new_release_version} /tmp/new.yaml; then
17+
echo 'Version update succeeded, new:'
18+
grep ${new_release_version} /tmp/new.yaml
19+
else
20+
echo 'Version update failed, exiting'
21+
exit 1
22+
fi
23+
24+
diff -U0 -w -b --ignore-blank-lines ${yaml_path} /tmp/new.yaml > /tmp/version.diff || true
25+
patch ${yaml_path} < /tmp/version.diff
26+
}
27+
28+
for k in ${keys}; do
29+
update_yaml_key ${k}
30+
done

0 commit comments

Comments
 (0)