From 00c30436e8dbb4947c096a57389b8af2fb7bfd59 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Tue, 8 Feb 2022 20:50:21 +0100 Subject: [PATCH] Finishing the CI/CD --- Dockerfile | 1 + build.sh | 15 ++++++++++ create_aleta_release.pl | 64 +++++++++++++++++++++++++++++++++++++++++ generate_release.sh | 5 ++-- 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 create_aleta_release.pl diff --git a/Dockerfile b/Dockerfile index b62fca8..1dbc480 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/build.sh b/build.sh index 2750493..eefc0a5 100644 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/create_aleta_release.pl b/create_aleta_release.pl new file mode 100644 index 0000000..cd20bc9 --- /dev/null +++ b/create_aleta_release.pl @@ -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 ); +} diff --git a/generate_release.sh b/generate_release.sh index 242086c..f2ddf26 100644 --- a/generate_release.sh +++ b/generate_release.sh @@ -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