Skip to content

Commit 9c9a3d3

Browse files
committed
make build using the same branch if possible
1 parent 26ef602 commit 9c9a3d3

1 file changed

Lines changed: 98 additions & 39 deletions

File tree

.github/workflows/automaticRelease.yaml

Lines changed: 98 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,43 @@ jobs:
3232
steps:
3333
- name: Checkout code
3434
uses: actions/checkout@v5
35-
- name: Use MathCAT from GitHub latest tag
35+
- name: Use matching MathCAT branch if available (fallback to latest)
3636
shell: bash
3737
run: |
38-
VERSION=$(curl -fsSL https://raw.githubusercontent.com/NSoiffer/MathCAT/latest/Cargo.toml \
39-
| sed -n 's/^version = "\(.*\)"/\1/p' | head -n1)
40-
if [ -z "$VERSION" ]; then
41-
echo "Failed to read MathCAT version from latest tag" >&2
42-
exit 1
38+
# Determine branch/ref for PRs and pushes
39+
if [ -n "${GITHUB_HEAD_REF:-}" ]; then
40+
REF="$GITHUB_HEAD_REF"
41+
else
42+
REF="${GITHUB_REF#refs/heads/}"
43+
fi
44+
echo "Detected ref: $REF"
45+
REMOTE=https://github.com/NSoiffer/MathCAT.git
46+
47+
if git ls-remote --heads "$REMOTE" "$REF" | grep -q "refs/heads/$REF"; then
48+
echo "Using MathCAT branch $REF"
49+
sed -i.bak \
50+
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", branch = "'" \
51+
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", branch = "'" \
52+
Cargo.toml
53+
# finish the branch replacement (sed quoting split across lines)
54+
sed -i "s|branch = \"'\"|branch = \"$REF\"|g" Cargo.toml
55+
sed -i "s|branch = \"'\"|branch = \"$REF\"|g" Cargo.toml
56+
else
57+
echo "No matching branch in MathCAT; falling back to latest tag"
58+
VERSION=$(curl -fsSL https://raw.githubusercontent.com/NSoiffer/MathCAT/latest/Cargo.toml \
59+
| sed -n 's/^version = "\(.*\)"/\1/p' | head -n1)
60+
if [ -z "$VERSION" ]; then
61+
echo "Failed to read MathCAT version from latest tag" >&2
62+
exit 1
63+
fi
64+
echo "Syncing package version to MathCAT $VERSION"
65+
sed -i.bak \
66+
-e "/^\[package\]/,/^\[/{s/^version = \".*\"/version = \"$VERSION\"/;}" \
67+
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest" }|' \
68+
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest", features = ["include-zip"] }|' \
69+
Cargo.toml
70+
rm -f Cargo.toml.bak
4371
fi
44-
echo "Syncing package version to MathCAT $VERSION"
45-
sed -i.bak \
46-
-e "/^\[package\]/,/^\[/{s/^version = \".*\"/version = \"$VERSION\"/;}" \
47-
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest" }|' \
48-
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest", features = ["include-zip"] }|' \
49-
Cargo.toml
50-
rm -f Cargo.toml.bak
5172
echo "--- Cargo.toml after sync ---"
5273
cat Cargo.toml
5374
- name: Build Rust Library
@@ -83,22 +104,41 @@ jobs:
83104
steps:
84105
- name: Checkout code
85106
uses: actions/checkout@v5
86-
- name: Use MathCAT from GitHub latest tag
107+
- name: Use matching MathCAT branch if available (fallback to latest)
87108
shell: bash
88109
run: |
89-
VERSION=$(curl -fsSL https://raw.githubusercontent.com/NSoiffer/MathCAT/latest/Cargo.toml \
90-
| sed -n 's/^version = "\(.*\)"/\1/p' | head -n1)
91-
if [ -z "$VERSION" ]; then
92-
echo "Failed to read MathCAT version from latest tag" >&2
93-
exit 1
110+
if [ -n "${GITHUB_HEAD_REF:-}" ]; then
111+
REF="$GITHUB_HEAD_REF"
112+
else
113+
REF="${GITHUB_REF#refs/heads/}"
114+
fi
115+
echo "Detected ref: $REF"
116+
REMOTE=https://github.com/NSoiffer/MathCAT.git
117+
118+
if git ls-remote --heads "$REMOTE" "$REF" | grep -q "refs/heads/$REF"; then
119+
echo "Using MathCAT branch $REF"
120+
sed -i.bak \
121+
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", branch = "'" \
122+
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", branch = "'" \
123+
Cargo.toml
124+
sed -i "s|branch = \"'\"|branch = \"$REF\"|g" Cargo.toml
125+
sed -i "s|branch = \"'\"|branch = \"$REF\"|g" Cargo.toml
126+
else
127+
echo "No matching branch in MathCAT; falling back to latest tag"
128+
VERSION=$(curl -fsSL https://raw.githubusercontent.com/NSoiffer/MathCAT/latest/Cargo.toml \
129+
| sed -n 's/^version = "\(.*\)"/\1/p' | head -n1)
130+
if [ -z "$VERSION" ]; then
131+
echo "Failed to read MathCAT version from latest tag" >&2
132+
exit 1
133+
fi
134+
echo "Syncing package version to MathCAT $VERSION"
135+
sed -i.bak \
136+
-e "/^\[package\]/,/^\[/{s/^version = \".*\"/version = \"$VERSION\"/;}" \
137+
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest" }|' \
138+
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest", features = ["include-zip"] }|' \
139+
Cargo.toml
140+
rm -f Cargo.toml.bak
94141
fi
95-
echo "Syncing package version to MathCAT $VERSION"
96-
sed -i.bak \
97-
-e "/^\[package\]/,/^\[/{s/^version = \".*\"/version = \"$VERSION\"/;}" \
98-
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest" }|' \
99-
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest", features = ["include-zip"] }|' \
100-
Cargo.toml
101-
rm -f Cargo.toml.bak
102142
echo "--- Cargo.toml after sync ---"
103143
cat Cargo.toml
104144
- name: Set up Python
@@ -138,22 +178,41 @@ jobs:
138178
steps:
139179
- name: Checkout code
140180
uses: actions/checkout@v5
141-
- name: Use MathCAT from GitHub latest tag
181+
- name: Use matching MathCAT branch if available (fallback to latest)
142182
shell: bash
143183
run: |
144-
VERSION=$(curl -fsSL https://raw.githubusercontent.com/NSoiffer/MathCAT/latest/Cargo.toml \
145-
| sed -n 's/^version = "\(.*\)"/\1/p' | head -n1)
146-
if [ -z "$VERSION" ]; then
147-
echo "Failed to read MathCAT version from latest tag" >&2
148-
exit 1
184+
if [ -n "${GITHUB_HEAD_REF:-}" ]; then
185+
REF="$GITHUB_HEAD_REF"
186+
else
187+
REF="${GITHUB_REF#refs/heads/}"
188+
fi
189+
echo "Detected ref: $REF"
190+
REMOTE=https://github.com/NSoiffer/MathCAT.git
191+
192+
if git ls-remote --heads "$REMOTE" "$REF" | grep -q "refs/heads/$REF"; then
193+
echo "Using MathCAT branch $REF"
194+
sed -i.bak \
195+
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", branch = "'" \
196+
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", branch = "'" \
197+
Cargo.toml
198+
sed -i "s|branch = \"'\"|branch = \"$REF\"|g" Cargo.toml
199+
sed -i "s|branch = \"'\"|branch = \"$REF\"|g" Cargo.toml
200+
else
201+
echo "No matching branch in MathCAT; falling back to latest tag"
202+
VERSION=$(curl -fsSL https://raw.githubusercontent.com/NSoiffer/MathCAT/latest/Cargo.toml \
203+
| sed -n 's/^version = "\(.*\)"/\1/p' | head -n1)
204+
if [ -z "$VERSION" ]; then
205+
echo "Failed to read MathCAT version from latest tag" >&2
206+
exit 1
207+
fi
208+
echo "Syncing package version to MathCAT $VERSION"
209+
sed -i.bak \
210+
-e "/^\[package\]/,/^\[/{s/^version = \".*\"/version = \"$VERSION\"/;}" \
211+
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest" }|' \
212+
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest", features = ["include-zip"] }|' \
213+
Cargo.toml
214+
rm -f Cargo.toml.bak
149215
fi
150-
echo "Syncing package version to MathCAT $VERSION"
151-
sed -i.bak \
152-
-e "/^\[package\]/,/^\[/{s/^version = \".*\"/version = \"$VERSION\"/;}" \
153-
-e 's|mathcat = { path = "../MathCAT/" }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest" }|' \
154-
-e 's|mathcat = { path = "../MathCAT/", features = \["include-zip"\] }|mathcat = { git = "https://github.com/NSoiffer/MathCAT", tag = "latest", features = ["include-zip"] }|' \
155-
Cargo.toml
156-
rm -f Cargo.toml.bak
157216
echo "--- Cargo.toml after sync ---"
158217
cat Cargo.toml
159218
- name: Set up Python

0 commit comments

Comments
 (0)