Skip to content

Commit fd7c300

Browse files
authored
Simplify bin/bump-version (#368)
Over in #360 (comment), I noticed that bash was complaining about this script: ```bash bin/bump-version: line 9: ((: patch_level == 'major' || patch_level == 'minor' || patch_level == 'patch': syntax error: operand expected (error token is "'major' || patch_level == 'minor' || patch_level == 'patch'") ``` I started to dig into it, but the `while` loop isn't needed, the `case` statement felt unecessarily complex so I simplified it to use an `if` statement. I also changed the argument from a flag-based argument to simple ordered argument, as again it seemed simpler and it matches the style of the bump version script over in `dependabot-core` so it's easier for engineers working across repos. If we later have additional flags, we can always switch it back later. Lastly, I found `patch_version` confusing given that `patch` is a specific value that can be used, so I renamed it to `version_type`.
1 parent 9cc71e7 commit fd7c300

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ jobs:
193193
```bash
194194
git checkout main
195195
git pull
196-
bin/bump-version -p patch # patch | minor | major
196+
bin/bump-version minor # major | minor | patch
197197
```
198198
- Merge the PR after getting it reviewed
199199
- Create a new release tagged as `v1.X.X` format:

bin/bump-version

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
11
#!/bin/bash
22

3-
usage() { echo "Usage: $0 -p [major | minor | patch]" 1>&2; exit 1; }
3+
usage() { echo "Usage: $0 [ major | minor | patch ]" 1>&2; exit 1; }
44

5-
while getopts "p:" o; do
6-
case "${o}" in
7-
p)
8-
patch_level=${OPTARG}
9-
(( patch_level == 'major' || patch_level == 'minor' || patch_level == 'patch'))
10-
;;
11-
*)
12-
usage
13-
;;
14-
esac
15-
done
5+
version_type=$1
6+
if [ "$version_type" == "major" ] || [ "$version_type" == "minor" ] || [ "$version_type" == "patch" ]; then
7+
new_version=$(npm version "$version_type" --no-git-tag-version)
8+
echo "$new_version"
169

17-
echo "$patch_level"
18-
19-
if [[ -z "${patch_level}" ]]; then
10+
git checkout -b "${new_version}"-release-notes
11+
git add package.json package-lock.json
12+
echo "Creating commit / PR linking to the releases notes URL."
13+
echo "This URL will 404 until the release is actually tagged, which you should do as soon as the PR is merged."
14+
git commit -m "${new_version}" -m "Release notes: https://github.com/dependabot/fetch-metadata/releases/tag/v${new_version}"
15+
gh pr create --fill # `fill` re-uses the title / body from the commit
16+
echo "PR created for ${new_version}"
17+
else
2018
usage
2119
fi
22-
23-
new_version=$(npm version "${patch_level}" --no-git-tag-version)
24-
git checkout -b "${new_version}"-release-notes
25-
git add package.json package-lock.json
26-
27-
echo "Creating commit / PR linking to the releases notes URL."
28-
echo "This URL will 404 until the release is actually tagged, which you should do as soon as the PR is merged."
29-
git commit -m "${new_version}" -m "Release notes: https://github.com/dependabot/fetch-metadata/releases/tag/v${new_version}"
30-
gh pr create --fill # `fill` re-uses the title / body from the commit
31-
echo "PR created for ${new_version}"

0 commit comments

Comments
 (0)