Skip to content

Commit a1b4e45

Browse files
committed
feat: If the specified URL returns 404, try to download the archive with gh command
1 parent e9ce615 commit a1b4e45

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
11+
* If the given URL is http://github.com/... and returns 404, then try to download the archive with the `gh` command and try to download the archive at http://github.com/...
12+
913
## [2.8.0] - 2025-04-23
1014

1115
### Changed

bin/setup-environment

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,43 @@ for my $a ( split /\s+/, $archives ) {
332332

333333
# download
334334
my $response = HTTP::Tiny->new->get($a);
335-
die "Failed: @{[Dumper($response)]}"
336-
unless $response->{success} && length $response->{content};
337335

338-
( my $fh, $file_path ) = tempfile( undef, SUFFIX => $ext );
339-
print $fh $response->{content};
336+
if (
337+
$response->{status} == 404
338+
&& system('gh auth status > /dev/null 2>&1') == 0
339+
&& $a =~ m{^https://github.com/([^/]+/[^/]+)/actions/runs/[0-9]+/artifacts/([0-9]+)$}
340+
) {
341+
my $repo = $1;
342+
my $artifact_id = $2;
343+
344+
my $cwd = getcwd();
345+
my $tmp_dir = tempdir( '/tmp/mt-dev-archive-temp-XXXXX', );
346+
347+
chdir $tmp_dir;
348+
349+
my $cmd = "gh api repos/$repo/actions/artifacts/$artifact_id/zip > archive.zip";
350+
my $res = `$cmd 2>&1` || "";
351+
die "$res\nGot an error: $cmd" if $?;
352+
353+
$cmd = "unzip -q archive.zip";
354+
$res = `$cmd 2>&1` || "";
355+
die "$res\nGot an error: $cmd" if $?;
356+
357+
unlink 'archive.zip';
358+
my ($filename) = `ls`;
359+
chomp $filename;
360+
361+
chdir $cwd;
362+
363+
$file_path = catfile( $tmp_dir, $filename );
364+
}
365+
elsif ( !$response->{success} || !$response->{content} ) {
366+
die "Failed: @{[Dumper($response)]}";
367+
}
368+
else {
369+
( my $fh, $file_path ) = tempfile( undef, SUFFIX => $ext );
370+
print $fh $response->{content};
371+
}
340372
}
341373
elsif ( $a =~ m{^/} ) {
342374
$file_path = $a;

0 commit comments

Comments
 (0)