forked from OAI/OpenAPI-Specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-release.sh
More file actions
127 lines (99 loc) · 3.85 KB
/
start-release.sh
File metadata and controls
127 lines (99 loc) · 3.85 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
# Author: @ralfhandl
# Run this script from the root of the repo. It is designed to be run manually in a development branch.
repoUrl="https://github.com/OAI/OpenAPI-Specification"
remote=$(git remote -v | grep "$repoUrl.git (fetch)" | head -1 | cut --fields=1)
branch=$(git branch --show-current)
if [[ ! $branch =~ ^v[0-9]+\.[0-9]+-dev$ ]]; then
echo "This script is intended to be run from a development branch, e.g. v3.2-dev"
exit 1
fi
vVersion=$(basename "$branch" "-dev")
minor=${vVersion:1}
# Find last published spec version for this minor version
lastSpec=$(git ls-tree $remote/main versions/ --name-only | grep -E "/$minor\.[0-9].md" | tail -1)
if [ -z "$lastSpec" ]; then
# Find last published spec version
lastSpec=$(git ls-tree $remote/main versions/ --name-only | grep -E "/.+\.[0-9].md" | tail -1)
nextPatch=0
releaseType="Release"
else
lastPatch=$(basename "$lastSpec" ".md" | cut --delimiter=. --fields=3)
nextPatch=$((lastPatch + 1))
releaseType="Patch release"
fi
nextVersion="$minor.$nextPatch"
if [ -z "$lastSpec" ]; then
echo "Could not find any published specification version in $remote/main"
exit 1
fi
lastVersion=$(basename "$lastSpec" ".md")
echo === Initialize src/oas.md for $nextVersion from $lastVersion
# Create PR branch from development branch
prBranch="$branch-start-$nextVersion"
if git ls-remote --exit-code --heads $remote "$prBranch"; then
echo "=== Failed: PR branch $prBranch already exists on the remote, please delete it and try again"
exit 1
fi
if ! git checkout -b "$prBranch"; then
echo "=== Failed: PR branch $prBranch already exists locally, please delete it and try again"
exit 1
fi
# Create empty orphan branch and add src/oas.md with last spec's content and no history
orphan="v$minor-orphan"
if ! git switch --orphan "$orphan"; then
git switch "$branch"
git branch -d "$prBranch"
echo "=== Failed: please delete branch $orphan and try again"
exit 1
fi
mkdir src
git show "main:$lastSpec" > src/oas.md
git add src/oas.md
git commit -m "copy from $lastVersion"
# Merge orphan branch into PR branch, favoring orphan's version of src/oas.md
git switch "$prBranch"
git merge "$orphan" -X theirs --allow-unrelated-histories -m "reset src/oas.md history"
git branch -D "$orphan"
# Bump version headline, add line to history table
temp=$(mktemp)
historyTableHeader="\n| Version | Date | Notes |\n| ---- | ---- | ---- |\n"
sed -z -e "s/\n## Version $lastVersion\n/\n## Version $nextVersion\n/" \
-z -e "s/$historyTableHeader/$historyTableHeader| $nextVersion | TBD | $releaseType of the OpenAPI Specification $nextVersion |\n/" \
src/oas.md > "$temp"
mv -f "$temp" src/oas.md
git add src/oas.md
git commit -m "bump version"
echo === Initialized src/oas.md
# when starting a new major or minor version
if [ "$nextPatch" == "0" ]; then
lastMinor=$(echo "$lastVersion" | cut -d . -f 1,2)
echo === Adjust schemas for new version $minor
minorRegex=$(echo "$minor" | sed 's/\./\\\\\\./')
lastMinorRegex=$(echo "$lastMinor" | sed 's/\./\\\\\\./')
for file in src/schemas/validation/*.yaml; do
sed -e "s/$lastMinor/$minor/g" \
-e "s/\^$lastMinorRegex\\\./\^$minorRegex\\\./g" \
"$file" > "$temp"
mv -f "$temp" "$file"
done
for file in src/schemas/validation/*.md; do
sed -e "s/$lastMinor/$minor/g" \
"$file" > "$temp"
mv -f "$temp" "$file"
done
echo === Adjust tests for new version $minor
sed -e "s/$lastMinor/$minor/g" tests/schema/schema.test.mjs > "$temp"
mv -f "$temp" tests/schema/schema.test.mjs
for file in tests/schema/{pass,fail}/*.yaml; do
sed -e "s/$lastMinor/$minor/g" "$file" > "$temp"
mv -f "$temp" "$file"
done
git commit --all -m "adjust schemas, test script, and test data"
echo === Adjusted schemas and tests
fi
# Push PR branch to remote
git push -u $remote $prBranch
# Clean up
git switch "$branch"
echo === Done