Repository navigation
Expand file tree
/
Copy pathprepare-release.sh
More file actions
executable file
·103 lines (90 loc) · 2.95 KB
/
Copy pathprepare-release.sh
File metadata and controls
executable file
·103 lines (90 loc) · 2.95 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
#!/usr/bin/env bash
# Prepare the downstream repositories for the first release of a new minor or major version:
# create the release/vX.Y branch where it is missing and make it the default branch where it
# is the newest one. Uses the gh CLI with your login.
set -euo pipefail
if (( $# != 1 )); then
echo "Usage: ./prepare-release.sh <version>" >&2
exit 2
fi
version="$1"
IFS=. read -r major minor _ <<< "$version"
lane="release/v$major.$minor"
lane_key=$(( major * 1000 + minor ))
repos=(
graphql-platform-commercial
nitro-client-publish
nitro-client-upload
nitro-client-validate
nitro-fusion-publish
nitro-fusion-upload
nitro-fusion-validate
nitro-mcp-publish
nitro-mcp-upload
nitro-mcp-validate
nitro-openapi-publish
nitro-openapi-upload
nitro-openapi-validate
nitro-schema-download
nitro-schema-publish
nitro-schema-upload
nitro-schema-validate
)
# nitro-azure-pipelines-tasks is released for stable versions only.
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
repos+=(nitro-azure-pipelines-tasks)
fi
prepare_repo() {
local repo="ChilliCream/$1"
local lanes exists newest_key base_key base_sha lane_version sha lane_major lane_minor key default_branch
lanes=$(gh api --paginate "repos/$repo/git/matching-refs/heads/release/v" \
--jq '.[] | select(.ref | test("/v[0-9]+\\.[0-9]+$")) | "\(.ref | ltrimstr("refs/heads/release/v")) \(.object.sha)"')
exists=false
newest_key=$lane_key
base_key=-1
base_sha=""
while read -r lane_version sha; do
if [[ -z "$lane_version" ]]; then
continue
fi
IFS=. read -r lane_major lane_minor <<< "$lane_version"
key=$(( lane_major * 1000 + lane_minor ))
if (( key > newest_key )); then
newest_key=$key
fi
if (( key == lane_key )); then
exists=true
elif (( key < lane_key && key > base_key )); then
base_key=$key
base_sha="$sha"
fi
done <<< "$lanes"
if [[ "$exists" == "false" && -n "$base_sha" ]]; then
echo "$repo: creating $lane"
gh api "repos/$repo/git/refs" --silent -f ref="refs/heads/$lane" -f sha="$base_sha"
exists=true
fi
if [[ "$exists" == "true" ]] && (( newest_key == lane_key )); then
default_branch=$(gh api "repos/$repo" --jq .default_branch)
if [[ "$default_branch" != "$lane" ]]; then
echo "$repo: making $lane the default branch"
gh api --method PATCH "repos/$repo" --silent -f default_branch="$lane"
fi
fi
}
# Each repository is independent, so prepare them all at once and report every failure at the end.
pids=()
for name in "${repos[@]}"; do
prepare_repo "$name" &
pids+=("$!")
done
failed=()
for i in "${!pids[@]}"; do
if ! wait "${pids[$i]}"; then
failed+=("${repos[$i]}")
fi
done
if (( ${#failed[@]} > 0 )); then
echo "Failed to prepare: ${failed[*]}" >&2
exit 1
fi