2022-04-26 23:49:01 +02:00
|
|
|
use v5.30.0;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Const::Fast;
|
|
|
|
|
|
|
|
use Path::Tiny qw/path/;
|
|
|
|
use JSON;
|
2022-05-05 01:31:03 +02:00
|
|
|
use File::pushd;
|
2022-04-26 23:49:01 +02:00
|
|
|
|
|
|
|
use Mojo::URL;
|
|
|
|
use Mojo::UserAgent;
|
|
|
|
|
|
|
|
my $tag = $ARGV[0];
|
|
|
|
my $title = $ARGV[1] // "Automated release without title $tag";
|
|
|
|
my $description = $ARGV[2] // '';
|
|
|
|
|
|
|
|
const my $config_file => "$ENV{HOME}/.config/openmg_releaser.json";
|
|
|
|
|
|
|
|
if ( !-f $config_file ) {
|
|
|
|
die "No credentials in $config_file.";
|
|
|
|
}
|
|
|
|
my $config_file_contents = path($config_file)->slurp_utf8;
|
|
|
|
my $config = decode_json($config_file_contents);
|
|
|
|
my $username = $config->{username} // die "No user in config.";
|
|
|
|
my $token = $config->{token} // die "No token in config.";
|
|
|
|
my $host = $config->{host} // die "No host in config.";
|
|
|
|
my $commit = `git rev-parse HEAD`;
|
2022-05-05 01:31:03 +02:00
|
|
|
my $clone_path = Path::Tiny->tempdir;
|
|
|
|
system qw/git clone/,
|
|
|
|
'https://gitea.sergiotarxz.freemyip.com/sergiotarxz/mangareader/',
|
|
|
|
$clone_path;
|
2022-04-26 23:49:01 +02:00
|
|
|
|
2022-05-05 01:31:03 +02:00
|
|
|
my @subs = (compile('x86_64'), compile('aarch64'));
|
|
|
|
|
|
|
|
my $arch = shift;
|
2022-04-26 23:49:01 +02:00
|
|
|
my $release = request(
|
|
|
|
POST => '/repos/sergiotarxz/mangareader/releases' => json => {
|
|
|
|
body => $description,
|
|
|
|
name => $title,
|
|
|
|
tag_name => $tag,
|
|
|
|
target_commitish => 'main',
|
|
|
|
}
|
|
|
|
);
|
2022-05-05 01:31:03 +02:00
|
|
|
|
2022-04-26 23:49:01 +02:00
|
|
|
print Data::Dumper::Dumper $release;
|
2022-05-05 01:31:03 +02:00
|
|
|
my $release_id = $release->{id};
|
|
|
|
|
|
|
|
for my $sub (@subs) {
|
|
|
|
$sub->() if ref $sub eq 'CODE';
|
|
|
|
}
|
|
|
|
|
|
|
|
sub compile {
|
|
|
|
my $arch = shift;
|
|
|
|
my $flatpak_builder_file = 'me.sergiotarxz.openmg.json';
|
|
|
|
my $app_id = 'me.sergiotarxz.openmg';
|
|
|
|
my $app_output_name = path("openmg-$arch-$tag.flatpak")->absolute;
|
2022-05-09 00:09:29 +02:00
|
|
|
system 'cp', '/usr/bin/qemu-aarch64',
|
|
|
|
"$ENV{HOME}/.local/share/flatpak/runtime/org.gnome.Sdk/aarch64/master/active/files/bin/";
|
2022-05-05 01:31:03 +02:00
|
|
|
|
|
|
|
my $push = pushd $clone_path;
|
|
|
|
system 'flatpak-builder', '--force-clean', '--arch', $arch, '--install', '--user',
|
|
|
|
'build', $flatpak_builder_file, $app_id
|
|
|
|
and return 1;
|
|
|
|
system 'flatpak', 'build-bundle', '--arch', $arch,
|
|
|
|
path( $ENV{HOME} )->child('.local/share/flatpak/repo/'),
|
|
|
|
$app_output_name, $app_id
|
|
|
|
and return 1;
|
|
|
|
return sub {
|
|
|
|
print Data::Dumper::Dumper request( POST =>
|
|
|
|
"/repos/sergiotarxz/mangareader/releases/$release_id/assets?name=@{[$app_output_name->basename]}"
|
|
|
|
=> form => { attachment => { file => "" . $app_output_name } } );
|
|
|
|
}
|
|
|
|
}
|
2022-04-26 23:49:01 +02:00
|
|
|
|
|
|
|
sub request {
|
|
|
|
my $method = shift // die "No method passed.";
|
|
|
|
my $endpoint = shift // die "No endpoint passed.";
|
|
|
|
my $body_type = shift // die "No body type passed.";
|
|
|
|
my $body = shift // die "No body passed.";
|
|
|
|
my $ua = Mojo::UserAgent->new();
|
|
|
|
my $url = Mojo::URL->new("https://$host/api/v1/$endpoint");
|
|
|
|
$url->query( token => $token );
|
|
|
|
say $url;
|
|
|
|
my $tx = $ua->build_tx( $method => $url => {} => $body_type => $body );
|
|
|
|
$ua->start($tx);
|
|
|
|
my $response = $tx->result;
|
|
|
|
say $response->code;
|
|
|
|
say $response->message;
|
|
|
|
return decode_json( $response->body );
|
|
|
|
}
|