Skip to content

Commit 58ee920

Browse files
Add debug token file #TASK-8067
1 parent 36c75ef commit 58ee920

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
# get_opencga_enterprise_branch.sh
3+
#
4+
# This script computes the correct opencga-enterprise branch to use for testing a PR in any Xetabase component repo.
5+
# It unifies the logic previously duplicated in java-common-libs, biodata, and opencga.
6+
#
7+
# Inputs:
8+
# 1. project (artifactId from pom.xml)
9+
# 2. base_ref (target branch of the PR)
10+
# 3. head_ref (source branch of the PR)
11+
#
12+
# Output:
13+
# Prints the resolved opencga-enterprise branch to stdout.
14+
# Exits with non-zero and error message if it cannot resolve a branch.
15+
16+
set -euo pipefail
17+
18+
project="$1"
19+
base_ref="$2"
20+
head_ref="$3"
21+
REPO_URI="https://$ZETTA_REPO_ACCESS_TOKEN@github.com/zetta-genomics/opencga-enterprise.git"
22+
23+
# 1. If the branch begins with 'TASK' and exists in the opencga-enterprise repository, return it
24+
if [[ $head_ref == TASK* ]]; then
25+
if [ "$(git ls-remote $REPO_URI $head_ref)" ] ; then
26+
echo "$head_ref";
27+
exit 0
28+
fi
29+
fi
30+
31+
# 2. If the base_ref is 'develop', always map to develop
32+
if [[ "$base_ref" == "develop" ]]; then
33+
echo "develop"
34+
exit 0
35+
fi
36+
37+
# 3. release-* branch logic
38+
if [[ "$base_ref" =~ ^release-([0-9]+)\. ]]; then
39+
major="${BASH_REMATCH[1]}"
40+
# Project-specific offset for release branch mapping
41+
case "$project" in
42+
java-common-libs)
43+
offset=3
44+
;;
45+
biodata|opencga)
46+
offset=1
47+
;;
48+
opencga-enterprise)
49+
# If the project is opencga-enterprise, use the branch as-is
50+
echo "$base_ref"
51+
exit 0
52+
;;
53+
*)
54+
echo "ERROR: Unknown project '$project' for release branch mapping" >&2
55+
exit 1
56+
;;
57+
esac
58+
new_major=$((major - offset))
59+
if (( new_major < 1 )); then
60+
echo "ERROR: Computed release branch version < 1 for $project (base_ref: $base_ref, offset: $offset)" >&2
61+
exit 1
62+
fi
63+
# Extract the rest of the version (minor and patch) from base_ref
64+
rest_version=$(echo "$base_ref" | sed -E "s/^release-[0-9]+(\..*)/\1/")
65+
target_branch="release-${new_major}${rest_version}"
66+
# Check if the exact branch exists (fix: do not escape quotes)
67+
if [ "$(git ls-remote --heads "$REPO_URI" "$target_branch")" ]; then
68+
echo "$target_branch"
69+
exit 0
70+
else
71+
echo "ERROR: No matching release branch '$target_branch' found in opencga-enterprise for $project (base_ref: $base_ref, offset: $offset)" >&2
72+
exit 1
73+
fi
74+
fi
75+
76+
# 4. Fallback: fail with clear error
77+
echo "ERROR: Could not resolve opencga-enterprise branch for project '$project' (base_ref: $base_ref, head_ref: $head_ref)" >&2
78+
exit 1
79+

0 commit comments

Comments
 (0)