Skip to content

Commit cf9c8b2

Browse files
authored
Refactor version and URL extraction in bottle.yml
Updated version extraction logic and added error handling for URL parsing.
1 parent 08e9328 commit cf9c8b2

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

.github/workflows/bottle.yml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,40 @@ jobs:
3434
id: meta
3535
run: |
3636
set -euo pipefail
37-
37+
3838
FORMULA="Formula/mfc.rb"
39-
40-
VERSION="$(
41-
brew ruby -e 'require "formulary"; puts Formulary.factory(File.expand_path(ARGV.first)).version' \
42-
-- "${FORMULA}"
39+
40+
# Take the *last* matching URL (guards against accidental duplicates)
41+
URL="$(
42+
grep -E '^\s*url\s+"https://github.com/.*/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz"' "${FORMULA}" \
43+
| sed -E 's/^\s*url\s+"([^"]+)".*/\1/' \
44+
| tail -n 1
4345
)"
44-
46+
47+
if [[ -z "${URL}" ]]; then
48+
echo "Could not extract release tarball URL from ${FORMULA}" >&2
49+
echo "Expected a line like: url \"https://github.com/<org>/<repo>/archive/refs/tags/vX.Y.Z.tar.gz\"" >&2
50+
exit 1
51+
fi
52+
53+
VERSION="$(echo "${URL}" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz/\1/')"
4554
if [[ -z "${VERSION}" ]]; then
46-
echo "Could not determine version from ${FORMULA}" >&2
55+
echo "Could not parse version from URL: ${URL}" >&2
4756
exit 1
4857
fi
49-
58+
5059
TAG="mfc-${VERSION}"
5160
ROOT_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}"
52-
61+
5362
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
5463
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
5564
echo "root_url=${ROOT_URL}" >> "$GITHUB_OUTPUT"
5665
66+
echo "Formula URL: ${URL}"
67+
echo "Formula version: ${VERSION}"
68+
echo "Release tag: ${TAG}"
69+
echo "Bottle root_url: ${ROOT_URL}"
70+
5771
- name: Install formula with --build-bottle (from checked-out file)
5872
run: |
5973
set -euo pipefail
@@ -138,10 +152,21 @@ jobs:
138152
set -euo pipefail
139153
140154
FORMULA="Formula/mfc.rb"
141-
VERSION="$(brew ruby -e "require 'formula'; f = Formula.from_file('${FORMULA}'); puts f.version")"
142155
156+
URL="$(
157+
grep -E '^\s*url\s+"https://github.com/.*/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz"' "${FORMULA}" \
158+
| sed -E 's/^\s*url\s+"([^"]+)".*/\1/' \
159+
| tail -n 1
160+
)"
161+
162+
if [[ -z "${URL}" ]]; then
163+
echo "Could not extract release tarball URL from ${FORMULA}" >&2
164+
exit 1
165+
fi
166+
167+
VERSION="$(echo "${URL}" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz/\1/')"
143168
if [[ -z "${VERSION}" ]]; then
144-
echo "Could not determine version from ${FORMULA}" >&2
169+
echo "Could not parse version from URL: ${URL}" >&2
145170
exit 1
146171
fi
147172

0 commit comments

Comments
 (0)