-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
check-spec-version.sh
executable file
·50 lines (41 loc) · 1.64 KB
/
check-spec-version.sh
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
#!/bin/bash
# exit when any command fails
set -e
download_newest_spec_output=$(swift run bagbutik-cli download-newest-spec)
echo "$download_newest_spec_output"
if [[ $download_newest_spec_output =~ Spec\ file\ downloaded\ to\ (.+) ]]; then
spec_file_path=${BASH_REMATCH[1]}
else
echo "No path to a spec file found in output from Bagbutik CLI"
exit 42
fi
current_version="$(cat spec-version)"
downloaded_version="$(jq -r '.info.version' $spec_file_path)"
echo "Current version: $current_version"
echo "Downloaded version: $downloaded_version"
if [ "$current_version" == "$downloaded_version" ]; then
echo "No new spec found."
exit 0
else
echo "New spec is found. Will generate new endpoints and models (if no pull request is found)."
fi
pr_list_output=$(gh pr list --search "$downloaded_version type:pr is:open")
if [[ $pr_list_output =~ Update\ from\ new\ spec ]]; then
echo "A pull request for this version has already been created."
exit 0
else
echo "No pull requests has been created for this version."
fi
docs_ouput=$(swift run bagbutik-cli download-newest-docs --spec-path $spec_file_path)
warnings=$(grep -zo "⚠️.*" <<< "$docs_ouput" || echo "" >&2)
swift run bagbutik-cli generate --spec-path $spec_file_path
rm $spec_file_path
echo $downloaded_version > spec-version
git config --local user.email "[email protected]"
git config --local user.name "Bagbutik CI"
git checkout -b spec-$downloaded_version
git add .
git commit -m "Update from new spec ($downloaded_version)"
git push -u origin spec-$downloaded_version
create_pr_output=$(gh pr create --fill --body "$warnings")
echo "Pull request created: $create_pr_output"