forked from gooddata/gooddata-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover-versions.sh
More file actions
executable file
·50 lines (44 loc) · 1.57 KB
/
discover-versions.sh
File metadata and controls
executable file
·50 lines (44 loc) · 1.57 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
#!/bin/bash
# (C) 2026 GoodData Corporation
# Discovers release versions for parallel doc generation.
# Outputs a JSON array suitable for GitHub Actions matrix strategy.
# Usage: discover-versions.sh [remote_name] [num_versions]
set -e
remote_name=${1:-origin}
num_versions=${2:-4}
git fetch "$remote_name" 2>/dev/null
# Build a map of section -> branch, keeping only the latest patch per section.
# Branches are three-part versions (e.g. rel/1.60.0). We strip the patch to get
# the section (e.g. 1.60), matching the original generate.sh behavior where
# ${target_section%.*} strips the patch component.
declare -A section_map
declare -a section_order
while IFS= read -r vers; do
# Strip patch: 1.60.0 -> 1.60
section="${vers%.*}"
if [ -z "${section_map[$section]+x}" ]; then
section_order+=("$section")
fi
# Later (higher patch) versions overwrite earlier ones for the same major.minor
section_map["$section"]="rel/$vers"
done < <(git branch -rl "$remote_name/rel/*" | sed 's|.*/rel/||' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n"$num_versions")
# Add dev branch if it exists
if git branch -rl "$remote_name/rel/dev" | grep -q "rel/dev"; then
if [ -z "${section_map[dev]+x}" ]; then
section_order+=("dev")
fi
section_map["dev"]="rel/dev"
fi
# Output as JSON array
echo -n "["
first=true
for section in "${section_order[@]}"; do
branch="${section_map[$section]}"
if [ "$first" = true ]; then
first=false
else
echo -n ","
fi
echo -n "{\"branch\":\"$branch\",\"section\":\"$section\"}"
done
echo "]"