Finishing the CI/CD

This commit is contained in:
sergiotarxz 2022-02-08 20:50:21 +01:00
parent 45a26af367
commit 00c30436e8
4 changed files with 83 additions and 2 deletions

View File

@ -11,6 +11,7 @@ COPY generate_release.sh /var/lib/aleta/
COPY aleta /var/lib/aleta/aleta
RUN chown -R aleta /var/lib/aleta/aleta
RUN mkdir /var/lib/aleta/output
RUN apk add gtk+3.0
USER aleta
CMD bash ~/generate_release.sh

View File

@ -1,7 +1,22 @@
cd $(dirname $0)
pushd aleta
git fetch
current_commit=$(git rev-parse HEAD)
if [ $current_commit == `git rev-parse @{u}` ]; then
echo 'Aleta is updated'
exit 0
fi
git pull
popd
if [ -e output ]; then
rm -rf output
fi
mkdir output
sudo docker build --no-cache -t aletareleaser:latest .
sudo docker run -v $(realpath output):/var/lib/aleta/output --rm -it aletareleaser
if [ ! -e output/aleta.tar.gz ]; then
echo "aleta.tar.gz not exists." 1>&2
exit 1
fi
perl create_aleta_release.pl

64
create_aleta_release.pl Normal file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env perl
use v5.30.0;
use strict;
use warnings;
use Data::Dumper;
use Mojo::UserAgent;
use Const::Fast;
use Path::Tiny;
use JSON;
use DateTime;
const my $config_file => "$ENV{HOME}/.config/aletareleaser.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 $datetime = DateTime->now->strftime("%Y%m%d%H%M");
my $commit = `git rev-parse HEAD`;
my $release = request(
POST => '/repos/sergiotarxz/AletaReleaser/releases' => form => {
body => "Aleta release from $datetime.",
name => "Aleta release from $datetime",
tag_name => "$datetime",
target_commitish => `git rev-parse HEAD`,
}
);
print Data::Dumper::Dumper $release;
my $release_id = $release->{id};
print Data::Dumper::Dumper request( POST =>
"/repos/sergiotarxz/AletaReleaser/releases/$release_id/assets?name=$datetime-aleta-build.tar.gz"
=> form => { attachment => { file => 'output/aleta.tar.gz' } } );
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 );
}

View File

@ -4,6 +4,7 @@ cd $HOME/aleta
echo 'will cite' | parallel --bibtex
bash tasks/build.sh
broadwayd :5 &
GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 bash tasks/build.sh
tar -C ~/.icons -czvf ~/output/result.tar.gz aleta
tar -C ~/.icons -czvf ~/output/aleta.tar.gz aleta