-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·145 lines (114 loc) · 4.7 KB
/
release.sh
File metadata and controls
executable file
·145 lines (114 loc) · 4.7 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
set -euo pipefail
WORKFLOW=".github/workflows/build_binaries.yml"
# --- Pre-flight checks ---
if ! command -v gh &>/dev/null; then
echo "Error: gh CLI is not installed. Install it from https://cli.github.com"
exit 1
fi
if ! gh auth status &>/dev/null; then
echo "Error: gh CLI is not authenticated. Run 'gh auth login' first."
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Error: working directory has uncommitted changes. Commit or stash them first."
exit 1
fi
# --- Helper functions ---
# Read current default for a given input key
current_default() {
sed -n "/${1}:/,/default:/{s/.*default: \"\(.*\)\"/\1/p;}" "$WORKFLOW"
}
# Validate version format and that the tag exists upstream
validate_version() {
local version="$1" repo="$2" tag="$3"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: '$version' is not a valid version (expected X.Y.Z)"
exit 1
fi
if ! gh api "repos/${repo}/git/ref/tags/${tag}" &>/dev/null; then
echo "Error: tag '${tag}' not found in ${repo}"
exit 1
fi
}
# Prompt for a version, keeping current value if enter is pressed.
# Writes result to the variable named by $5.
prompt_version() {
local label="$1" key="$2" repo="$3" tag_prefix="$4" outvar="$5"
local current
current=$(current_default "$key")
read -rp "${label} [${current}]: " value
value="${value:-$current}"
validate_version "$value" "$repo" "${tag_prefix}${value}"
printf -v "$outvar" '%s' "$value"
}
# --- Prompt for versions ---
echo "This script will:"
echo " 1. Prompt for new component versions (press enter to keep current)"
echo " 2. Create a release-X.Y.Z branch from main"
echo " 3. Update version defaults in build_binaries.yml, commit, and push"
echo " 4. Open a PR and trigger the build workflow"
echo " 5. Docker deploy will auto-trigger after builds succeed"
echo " After builds pass, merge the PR. This will auto-create a GitHub release"
echo " with the build artifacts and auto-trigger the Docker deploy."
echo ""
echo "Current versions from ${WORKFLOW}:"
echo ""
OLD_SCIP=$(current_default "scip_version")
OLD_SOPLEX=$(current_default "soplex_version")
OLD_GCG=$(current_default "gcg_version")
OLD_IPOPT=$(current_default "ipopt_version")
prompt_version "SCIP" "scip_version" "scipopt/scip" "v" SCIP_VERSION
prompt_version "SoPlex" "soplex_version" "scipopt/soplex" "v" SOPLEX_VERSION
prompt_version "GCG" "gcg_version" "scipopt/gcg" "v" GCG_VERSION
prompt_version "IPOPT" "ipopt_version" "coin-or/Ipopt" "releases/" IPOPT_VERSION
echo ""
echo "Versions: SCIP=${SCIP_VERSION} SoPlex=${SOPLEX_VERSION} GCG=${GCG_VERSION} IPOPT=${IPOPT_VERSION}"
read -rp "Proceed? [Y/n] " confirm
[[ "${confirm:-Y}" =~ ^[Nn] ]] && exit 0
# --- Create release branch ---
BRANCH="release-${SCIP_VERSION}"
git checkout main
git pull --ff-only
if git show-ref --verify --quiet "refs/heads/${BRANCH}" || git show-ref --verify --quiet "refs/remotes/origin/${BRANCH}"; then
echo "Error: branch '${BRANCH}' already exists locally or on remote."
echo "Delete it first if you want to recreate it, or check it out manually."
exit 1
fi
git checkout -b "$BRANCH"
# --- Update version defaults ---
update_default() {
local key="$1" value="$2" file="$3"
sed -i.bak "/${key}:/,/default:/{s/default: \".*\"/default: \"${value}\"/;}" "$file"
rm -f "${file}.bak"
}
update_default "scip_version" "$SCIP_VERSION" "$WORKFLOW"
update_default "soplex_version" "$SOPLEX_VERSION" "$WORKFLOW"
update_default "gcg_version" "$GCG_VERSION" "$WORKFLOW"
update_default "ipopt_version" "$IPOPT_VERSION" "$WORKFLOW"
# --- Commit and push ---
changes=()
[[ "$SCIP_VERSION" == "$OLD_SCIP" ]] || changes+=("SCIP to ${SCIP_VERSION}")
[[ "$SOPLEX_VERSION" == "$OLD_SOPLEX" ]] || changes+=("SoPlex to ${SOPLEX_VERSION}")
[[ "$GCG_VERSION" == "$OLD_GCG" ]] || changes+=("GCG to ${GCG_VERSION}")
[[ "$IPOPT_VERSION" == "$OLD_IPOPT" ]] || changes+=("IPOPT to ${IPOPT_VERSION}")
if [[ ${#changes[@]} -eq 0 ]]; then
echo "No versions changed. Aborting."
git checkout main
git branch -d "$BRANCH"
exit 0
fi
MSG="update $(IFS=', '; echo "${changes[*]}")"
git add "$WORKFLOW"
git commit -m "$MSG"
git push -u origin "$BRANCH"
# --- Create PR and trigger build workflow ---
echo "Creating pull request..."
PR_URL=$(gh pr create --title "$MSG" --body "Automated release branch created by release.sh" --base main)
echo "Triggering build workflow..."
gh workflow run build_binaries.yml --ref "$BRANCH"
echo ""
echo "Done! Release branch '${BRANCH}' created and builds triggered."
echo "PR: ${PR_URL}"
echo "Docker deploy will run automatically after builds succeed."
echo "Monitor at: gh run list --workflow=build_binaries.yml"