blob: 41d74d672ddc6f9344d95202256734f846a7f2b3 [file] [log] [blame]
Akron88ddd4a2022-11-08 10:41:35 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Mojo::File 'tempfile';
5use Mojo::UserAgent;
Akron88ddd4a2022-11-08 10:41:35 +01006
7our @ARGV;
8
Akron081c5d52024-01-11 13:10:22 +01009my $JAVA8_HOME = '/usr/lib/jvm/java-1.8.0-openjdk-amd64';
10my $JAVA11_HOME = '/usr/lib/jvm/java-1.11.0-openjdk-amd64';
11my $JAVA17_HOME = '/usr/lib/jvm/java-1.17.0-openjdk-amd64';
12
13if (-d $JAVA17_HOME) {
14 $JAVA17_HOME = '/opt/java/jdk-17.0.2';
15};
16
Akron88ddd4a2022-11-08 10:41:35 +010017my $url = $ARGV[0];
18
19sub _check {
20 my $cmd = shift;
Akron53d18212022-11-15 15:25:17 +010021 CHECK:
Akron88ddd4a2022-11-08 10:41:35 +010022 print "\n\n" . 'Do "' . $cmd . '"? (y/n)', "\n";
23
24 my $x = <STDIN>;
25 chomp($x);
26 if ($x eq 'y' || $x eq 'Y') {
27 system $cmd;
Akron53d18212022-11-15 15:25:17 +010028 } elsif ($x eq 'n' || $x eq 'N') {
Akron88ddd4a2022-11-08 10:41:35 +010029 exit;
Akron53d18212022-11-15 15:25:17 +010030 } else {
31 print "Please answer with 'y' or 'n'.\n";
32 goto CHECK;
Akron88ddd4a2022-11-08 10:41:35 +010033 };
34};
35
Akron74994cf2022-11-15 14:28:00 +010036unless ($url) {
Helge4d96c362023-06-21 17:06:32 +020037 print 'git_gerrit_pull https://github.com/KorAP/.../pull/..' . "\n";
Akron88ddd4a2022-11-08 10:41:35 +010038 exit;
39};
40
41_check('git checkout master');
42
43_check('git pull origin master');
44
Akron74994cf2022-11-15 14:28:00 +010045$url =~ m!KorAP/([^/]+?)/pull/(\d+?)$!;
Akron88ddd4a2022-11-08 10:41:35 +010046
47my $ua = Mojo::UserAgent->new;
48
49print "Fetch $url...\n";
50
Akron74994cf2022-11-15 14:28:00 +010051my $project = $1;
52my $pr = $2;
Akron88ddd4a2022-11-08 10:41:35 +010053my $branch = $ua->get($url)->res->dom->at('.commit-ref.head-ref')->all_text;
54
55_check('git fetch github pull/' . $pr . '/head:' . $branch);
56_check('git checkout ' . $branch);
57_check('git rebase master');
58
59
Akron88ddd4a2022-11-08 10:41:35 +010060# Kustvakt
Akron74994cf2022-11-15 14:28:00 +010061if ($project =~ m!^Kustvakt$!i) {
Akron081c5d52024-01-11 13:10:22 +010062 _check('cd full && JAVA_HOME="'.$JAVA17_HOME.'" mvn clean test');
Akron88ddd4a2022-11-08 10:41:35 +010063}
64
65# KalamarExport-Plugin
Akron74994cf2022-11-15 14:28:00 +010066elsif ($project =~ m!^Kalamar-Plugin-Export$!i) {
Akron081c5d52024-01-11 13:10:22 +010067 _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test');
Akron88ddd4a2022-11-08 10:41:35 +010068}
69
Akron39dae912022-11-23 09:41:53 +010070# Koral
71elsif ($project =~ m!^Koral$!i) {
Akron081c5d52024-01-11 13:10:22 +010072 _check('JAVA_HOME="'.$JAVA11_HOME.'" mvn clean test');
Akron39dae912022-11-23 09:41:53 +010073}
74
Akron579efe02023-02-28 09:52:26 +010075# Kalamar-Plugin-ExternalResources
76elsif ($project =~ m!^Kalamar-Plugin-ExternalResources$!i) {
77 _check('go test ./...');
78}
79
Akron88ddd4a2022-11-08 10:41:35 +010080# KorapSRU
Akron74994cf2022-11-15 14:28:00 +010081elsif ($project =~ m!^KorapSRU$!i) {
Akron081c5d52024-01-11 13:10:22 +010082 _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test');
Akron88ddd4a2022-11-08 10:41:35 +010083}
84
Akron081c5d52024-01-11 13:10:22 +010085# Korap-Tokenizer
86elsif ($project =~ m!^KorAP-Tokenizer$!i) {
87 _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test');
88}
89
90# Datok
Akron579efe02023-02-28 09:52:26 +010091elsif ($project =~ m!^Datok$!i) {
92 _check('make test');
93}
94
Akron74994cf2022-11-15 14:28:00 +010095# Unknown Project
Akron88ddd4a2022-11-08 10:41:35 +010096else {
Akron74994cf2022-11-15 14:28:00 +010097 print "Unknown project $project!\n\n";
Akron88ddd4a2022-11-08 10:41:35 +010098 exit(1);
99};
100
101
102
103_check('git commit --amend --no-edit');
104
105{
106 my $ret = `git log -1 --pretty=%B`;
107 my $newret = '';
108 my $change_id = '';
109 my $first = 1;
110 foreach my $line (split "\n", $ret) {
111 if ($first) {
112 chomp $line;
113 $line .= " (closes #$pr)\n";
114 $first = 0;
115 }
116 elsif ($line =~ /^Change-Id: /) {
117 $change_id = $line;
118 next;
119 };
120 $newret .= $line . "\n";
121 };
122
123 if ($change_id) {
124 $newret .= "\n" . $change_id."\n\n";
125 };
126
127 my $msg_file = tempfile();
128 $msg_file->spurt($newret);
129
130 print "===================================\n";
131 print $newret;
132 print "===================================\n";
133
134 _check('git commit -F ' . $msg_file . ' --amend');
135};
136
Akron0e9e5f52022-11-23 09:47:47 +0100137_check('git push origin HEAD:refs/for/master');
Akron88ddd4a2022-11-08 10:41:35 +0100138
139_check('git checkout master');
140_check('git branch -D ' . $branch);
141
142print "\n\nEverything done - thank you!\n\n"
143
144__END__
145
146=pod
147
148This script is an alternative to C<import_github_pull_requests>
149that ignores CI results on github and just requires the
150URL of a specific GH pull request to send it through Gerrit.
Helge4d96c362023-06-21 17:06:32 +0200151
152Prerequisites:
153Remote repository "github"
154For Kustvakt and Koral Java 11 at /usr/lib/jvm/java-1.11.0-openjdk-amd6
155For KorapSRU and KalamarExport-Plugin Java 8 at /usr/lib/jvm/java-1.8.0-openjdk-amd6