Skip to content

Commit 339fc9b

Browse files
authored
Merge pull request #30 from movabletype/get-archive-from-recipe
Specify archive by recipe
2 parents 6270e0e + 0b941a9 commit 339fc9b

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [2.3.0] - 2023-07-13
10+
911
### Added
1012

1113
* Introduce UPDATE_DOCKER_IMAGE environment variable.
1214
* Setting this environment variable to "no" will skip updating the Docker image during `make up`.
15+
* ARCHIVE can now be specified in the recipe yaml file.
16+
* Specify url and integrity in the following format
17+
18+
```yaml
19+
mt-plugin-MTBlockEditor:
20+
archive:
21+
url: https://github.com/movabletype/mt-plugin-MTBlockEditor/releases/download/v1.1.10/MTBlockEditor-1.1.10.tar.gz
22+
integrity: sha512-VCrI5B/cv4FAEV7O9GPOsJGEATwRcw4GqjVCWZiMPSkC9jx2l0kjnTXl6M2Xvv/x6THnPQj9VgxX9B0MG7a25g==
23+
```
1324
1425
### Changed
1526

bin/setup-environment

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ use FindBin;
88
use lib "$FindBin::Bin/local/lib/perl5";
99

1010
use Cwd qw(realpath getcwd);
11+
use File::Path qw(mkpath);
1112
use IO::File;
1213
use JSON::PP qw(encode_json);
1314
use Data::Dumper;
1415
use Digest::MD5;
16+
use Digest::SHA;
1517
use Getopt::Long;
1618
use HTTP::Tiny;
1719
use Config::Tiny;
1820
use YAML::Tiny qw(LoadFile Dump);
19-
use File::Basename qw(basename fileparse);
21+
use File::Basename qw(basename fileparse dirname);
2022
use File::Spec::Functions qw(catfile);
2123
use File::Temp qw(tempfile tmpnam tempdir);
2224

@@ -57,6 +59,50 @@ sub handle_recipe {
5759
# checout branch and collect links
5860
my @volumes;
5961
for my $k ( keys %$data ) {
62+
if (my $archive = $data->{$k}{archive}) {
63+
my $url = $archive->{url};
64+
my $integrity = $archive->{integrity};
65+
66+
die "archive url and integrity is required: $k"
67+
unless $url && $integrity;
68+
69+
my $basename = basename($url);
70+
my $rel_path = catfile($k, $basename);
71+
my $full_path = catfile($archive_dir, $rel_path);
72+
73+
my ($algorithm) = $integrity =~ m{\Asha(\d+)};
74+
my $sha = Digest::SHA->new($algorithm);
75+
76+
if (-f $full_path) {
77+
$sha->addfile(IO::File->new($full_path, 'r'));
78+
my $digest = "sha$algorithm-" . $sha->base64_padded_digest;
79+
if ($digest eq $integrity) {
80+
$archives .= " $rel_path";
81+
next;
82+
}
83+
}
84+
85+
mkpath(dirname($full_path));
86+
my $response = HTTP::Tiny->new->get($url);
87+
die "Failed: @{[Dumper($response)]}"
88+
unless $response->{success} && length $response->{content};
89+
90+
$sha->add($response->{content});
91+
my $digest = "sha$algorithm-" . $sha->base64_padded_digest;
92+
if ($digest ne $integrity) {
93+
die "intergrity check failed: $url";
94+
}
95+
96+
my $fh = IO::File->new($full_path, 'w')
97+
or die "Can't open $full_path: $!";
98+
print $fh $response->{content};
99+
close $fh;
100+
101+
$archives .= " $rel_path";
102+
103+
next;
104+
}
105+
60106
my $repo = $data->{$k}{location};
61107
if (($ENV{CODESPACES} || '') eq 'true') {
62108
$repo =~ s{^git\@github.com:}{https://github.com/};
@@ -244,6 +290,8 @@ for my $r ( split /\s+/, $repos ) {
244290
}
245291

246292
for my $a ( split /\s+/, $archives ) {
293+
next unless $a;
294+
247295
my $file_path;
248296
my ( $basename, $ext ) = ( fileparse( $a, qr/\.[a-zA-Z\.]+$/ ) )[ 0, 2 ];
249297

0 commit comments

Comments
 (0)