Skip to content

Commit d8ec616

Browse files
committed
tool for extracting gems
1 parent 1948bc3 commit d8ec616

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,10 @@ task :binary, [:platform] => [:compile] do |_, args|
7575

7676
FileUtils.mv(package, 'pkg')
7777
end
78+
79+
desc 'Fetch gems from a GitHub Actions run URL'
80+
task :fetch_gems, [:url] do |_, args|
81+
url = args[:url] || ENV['URL']
82+
abort 'Usage: rake fetch_gems[url]' unless url
83+
sh "libexec/fetch-gems #{url}"
84+
end

libexec/fetch-gems

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# libexec/fetch-gems <url-or-run-id>
5+
# Downloads all artifacts from a GitHub Actions run, extracts the gems,
6+
# and places them in the pkg/ directory for easy publishing.
7+
8+
URL_OR_ID=$1
9+
10+
if [[ -z "$URL_OR_ID" ]]; then
11+
echo "Usage: $0 <github-actions-run-url-or-id>"
12+
exit 1
13+
fi
14+
15+
# Extract run ID from URL or use as is if it's already an ID
16+
if [[ "$URL_OR_ID" =~ /actions/runs/([0-9]+) ]]; then
17+
RUN_ID="${BASH_REMATCH[1]}"
18+
elif [[ "$URL_OR_ID" =~ ^[0-9]+$ ]]; then
19+
RUN_ID="$URL_OR_ID"
20+
else
21+
echo "Error: Could not parse run ID from '$URL_OR_ID'"
22+
exit 1
23+
fi
24+
25+
# Determine repo - default to rubyjs/libv8-node but allow override via GH_REPO env var
26+
REPO=${GH_REPO:-rubyjs/libv8-node}
27+
28+
echo "Fetching artifacts for run $RUN_ID in $REPO..."
29+
30+
# Create a temporary directory for downloading
31+
TMP_DIR=$(mktemp -d -t libv8-node-artifacts-XXXXXX)
32+
trap 'rm -rf "$TMP_DIR"' EXIT
33+
34+
# Download all artifacts
35+
gh run download "$RUN_ID" --repo "$REPO" -D "$TMP_DIR"
36+
37+
# Ensure pkg directory exists
38+
mkdir -p pkg
39+
40+
# Move all .gem files to pkg/
41+
# Artifacts are downloaded into subdirectories named after the artifact
42+
echo "Extracting gems..."
43+
found_gems=0
44+
while IFS= read -r gem_file; do
45+
gem_name=$(basename "$gem_file")
46+
mv -v "$gem_file" "pkg/$gem_name"
47+
found_gems=$((found_gems + 1))
48+
done < <(find "$TMP_DIR" -name "*.gem")
49+
50+
if [ "$found_gems" -eq 0 ]; then
51+
echo "No gems found in artifacts for run $RUN_ID."
52+
exit 1
53+
fi
54+
55+
echo ""
56+
echo "Successfully downloaded $found_gems gem(s) to pkg/:"
57+
ls -1 pkg/*.gem
58+
59+
echo ""
60+
echo "To publish all downloaded gems, run:"
61+
echo " gem push pkg/*.gem"
62+
echo ""
63+
echo "To publish a specific gem:"
64+
echo " gem push pkg/<gem-filename>"

0 commit comments

Comments
 (0)