#!/usr/bin/env perl # Copyright (C) 2020 Sean Whitton # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use 5.028; use strict; use warnings; use JSON; use YAML; $YAML::UseBlock = 1; use REST::Client; use API::GitForge qw(forge_access_token); use Getopt::Long; use Git::Wrapper; use Cwd; use Term::UI; my $term = Term::ReadLine->new("brand"); my $git = Git::Wrapper->new(getcwd); my $user = "~spwhitton"; # TODO could fetch from API my $dist = "unstable"; my ($remote, $clone_uri); my $quilt = "auto"; GetOptions "distribution|d=s" => \$dist, "remote=s" => \$remote, "quilt=s" => \$quilt; unless ($remote) { # see if there is a git.sr.ht remote; use that if possible as # clone to builds.sr.ht will be faster foreach my $r ($git->remote) { my ($u) = $git->remote("get-url", $r); $u =~ /git\.sr\.ht/ and $remote = $r, $clone_uri = $u; } } $remote ||= "origin"; $clone_uri or ($clone_uri) = $git->remote("get-url", $remote); chomp(my $source = `dpkg-parsechangelog -SSource`); chomp(my $version = `dpkg-parsechangelog -SVersion`); $source or die "couldn't determine source package name"; $version or die "couldn't determine source package version"; my $note = "Pre-upload checks for $source $version"; $git->fetch($remote); my ($branch) = $git->symbolic_ref("HEAD"); my ($commit) = $git->rev_parse({ verify => 1 }, "HEAD"); $git->for_each_ref({ contains => $branch }, "refs/remotes/$remote") or die "remote $remote doesn't appear to have a copy of your HEAD"; exit unless $term->ask_yn( prompt => "will run the build for $branch cloning from $remote with note \"$note\", " . "dist $dist, with --quilt=$quilt", default => "y" ); my $schroot = "$dist-amd64-sbuild"; my $changes = "${source}_${version}_multi.changes"; my $manifest->{image} = "debian/unstable"; $manifest->{sources} = [$clone_uri]; $manifest->{packages} = ["autopkgtest", "devscripts", "dgit", "lintian", "piuparts", "sbuild"]; $manifest->{tasks} = [ map +({ $_->[0] => join "\n", $_->[1]->@*, "" }), [ setup => [ "cd $source", "git checkout $commit", "git deborig || origtargz", join( " ", qw(sudo sbuild-createchroot --command-prefix=eatmydata --include=eatmydata), $dist, "/srv/chroot/$schroot" ), "sudo sbuild-adduser \$USER" ] ], [ build => [ "cd $source", "dgit --quilt=$quilt sbuild -d $dist --no-run-lintian" ] ], [lintian => ["lintian $changes"]], [autopkgtest => ["autopkgtest $changes -- schroot $schroot"]], [piuparts => ["sudo piuparts --no-eatmydata --schroot $schroot $changes"]] ]; my $client = REST::Client->new; $client->setHost("https://builds.sr.ht"); $client->addHeader("Authorization", "token " . forge_access_token "sr.ht"); $client->addHeader("Content-Type", "application/json"); $client->addHeader("charset", "UTF-8"); $client->POST( "/api/jobs", encode_json { note => $note, "access:read" => [$user], manifest => YAML::Dump $manifest }); my $resp = decode_json $client->responseContent; my $job_id = $resp->{id}; system "xdg-open", "https://builds.sr.ht/$user/job/$job_id#bottom"; # $client->GET("/api/jobs"); # my $jobs = decode_json $client->responseContent; # my ($job) = grep $_->{id} == $job_id, $jobs->{results}->@*; # my $job_host = $job->{runner}; # system "ssh", "-t", "builds@" . $job_host, "connect", $job_id;