Skip to content

Commit 9f350f7

Browse files
committed
Create start-release.sh
script to start a release - create branch from version dev branch - initialize src/oas.md from last published version with empty history - adjust src/oas.md for new release - for new minor or major release: adjust schemas and tests - push branch to remote
1 parent 26c18ac commit 9f350f7

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

scripts/start-release.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
3+
# Author: @ralfhandl
4+
5+
# Run this script from the root of the repo. It is designed to be run manually in a development branch.
6+
7+
branch=$(git branch --show-current)
8+
9+
if [[ ! $branch =~ ^v[0-9]+\.[0-9]+-dev$ ]]; then
10+
echo "This script is intended to be run from a development branch, e.g. v3.2-dev"
11+
exit 1
12+
fi
13+
14+
vVersion=$(basename "$branch" "-dev")
15+
minor=${vVersion:1}
16+
17+
# Find last published spec version for this minor version
18+
lastSpec=$(git ls-tree origin/main versions/ --name-only | grep -E "/$minor\.[0-9].md" | tail -1)
19+
20+
if [ -z "$lastSpec" ]; then
21+
# Find last published spec version
22+
lastSpec=$(git ls-tree origin/main versions/ --name-only | grep -E "/.+\.[0-9].md" | tail -1)
23+
nextPatch=0
24+
releaseType="Release"
25+
else
26+
lastPatch=$(basename "$lastSpec" ".md" | cut --delimiter=. --fields=3)
27+
nextPatch=$((lastPatch + 1))
28+
releaseType="Patch release"
29+
fi
30+
31+
nextVersion="$minor.$nextPatch"
32+
33+
if [ -z "$lastSpec" ]; then
34+
echo "Could not find any published specification version in origin/main"
35+
exit 1
36+
fi
37+
38+
lastVersion=$(basename "$lastSpec" ".md")
39+
echo === Initialize src/oas.md for $nextVersion from $lastVersion
40+
41+
# Create PR branch from development branch
42+
prBranch="$branch-start-$nextVersion"
43+
if git ls-remote --exit-code --heads origin "$prBranch"; then
44+
echo "=== Failed: PR branch $prBranch already exists on the remote, please delete it and try again"
45+
exit 1
46+
fi
47+
if ! git checkout -b "$prBranch"; then
48+
echo "=== Failed: PR branch $prBranch already exists locally, please delete it and try again"
49+
exit 1
50+
fi
51+
52+
# Create empty orphan branch and add src/oas.md with last spec's content and no history
53+
orphan="v$minor-orphan"
54+
if ! git switch --orphan "$orphan"; then
55+
git switch "$branch"
56+
git branch -d "$prBranch"
57+
echo "=== Failed: please delete branch $orphan and try again"
58+
exit 1
59+
fi
60+
mkdir src
61+
git show "main:$lastSpec" > src/oas.md
62+
git add src/oas.md
63+
git commit -m "copy from $lastVersion"
64+
65+
# Merge orphan branch into PR branch, favoring orphan's version of src/oas.md
66+
git switch "$prBranch"
67+
git merge "$orphan" -X theirs --allow-unrelated-histories -m "reset src/oas.md history"
68+
git branch -D "$orphan"
69+
70+
# Bump version headline, add line to history table
71+
temp=$(mktemp)
72+
73+
historyTableHeader="\n| Version | Date | Notes |\n| ---- | ---- | ---- |\n"
74+
sed -z -e "s/\n## Version $lastVersion\n/\n## Version $nextVersion\n/" \
75+
-z -e "s/$historyTableHeader/$historyTableHeader| $nextVersion | TBD | $releaseType of the OpenAPI Specification $nextVersion |\n/" \
76+
src/oas.md > "$temp"
77+
mv -f "$temp" src/oas.md
78+
79+
git add src/oas.md
80+
git commit -m "bump version"
81+
82+
echo === Initialized src/oas.md
83+
84+
# when starting a new major or minor version
85+
if [ "$nextPatch" == "0" ]; then
86+
lastMinor=$(echo "$lastVersion" | cut -d . -f 1,2)
87+
88+
echo === Adjust schemas for new version $minor
89+
minorRegex=$(echo "$minor" | sed 's/\./\\\\\\./')
90+
lastMinorRegex=$(echo "$lastMinor" | sed 's/\./\\\\\\./')
91+
92+
for file in src/schemas/validation/*.yaml; do
93+
sed -e "s/$lastMinor/$minor/g" \
94+
-e "s/\^$lastMinorRegex\\\./\^$minorRegex\\\./g" \
95+
"$file" > "$temp"
96+
mv -f "$temp" "$file"
97+
done
98+
99+
echo === Adjust tests for new version $minor
100+
101+
sed -e "s/$lastMinor/$minor/g" tests/schema/schema.test.mjs > "$temp"
102+
mv -f "$temp" tests/schema/schema.test.mjs
103+
104+
for file in tests/schema/{pass,fail}/*.yaml; do
105+
sed -e "s/$lastMinor/$minor/g" "$file" > "$temp"
106+
mv -f "$temp" "$file"
107+
done
108+
109+
git commit --all -m "adjust schemas, test script, and test data"
110+
111+
echo === Adjusted tests
112+
fi
113+
114+
# Push PR branch to remote
115+
git push -u origin $prBranch
116+
117+
# Clean up
118+
git switch "$branch"
119+
echo === Done

0 commit comments

Comments
 (0)