blob: bb4b6c83c7f00d33be98e0b2974f20944635a28c [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
Akron57625182024-01-24 13:45:27 +010013unless (-d $JAVA17_HOME) {
Akron081c5d52024-01-11 13:10:22 +010014 $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) {
Akron01ea9212024-01-24 13:42:01 +010062 _check('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) {
Helge7cd2a612024-07-17 12:23:51 +020067 _check('JAVA_HOME="'.$JAVA17_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) {
Akron56ba1a92024-01-24 13:42:32 +010072 _check('JAVA_HOME="'.$JAVA17_HOME.'" mvn clean test');
Akron39dae912022-11-23 09:41:53 +010073}
74
Akron36ae3642024-01-24 13:42:56 +010075# Krill
76elsif ($project =~ m!^Krill$!i) {
77 _check('JAVA_HOME="'.$JAVA17_HOME.'" mvn clean test');
78}
79
Akron579efe02023-02-28 09:52:26 +010080# Kalamar-Plugin-ExternalResources
81elsif ($project =~ m!^Kalamar-Plugin-ExternalResources$!i) {
82 _check('go test ./...');
83}
84
Akron88ddd4a2022-11-08 10:41:35 +010085# KorapSRU
Akron74994cf2022-11-15 14:28:00 +010086elsif ($project =~ m!^KorapSRU$!i) {
Akron081c5d52024-01-11 13:10:22 +010087 _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test');
Akron88ddd4a2022-11-08 10:41:35 +010088}
89
Akron081c5d52024-01-11 13:10:22 +010090# Korap-Tokenizer
91elsif ($project =~ m!^KorAP-Tokenizer$!i) {
92 _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test');
93}
94
95# Datok
Akron579efe02023-02-28 09:52:26 +010096elsif ($project =~ m!^Datok$!i) {
97 _check('make test');
98}
99
Akron74994cf2022-11-15 14:28:00 +0100100# Unknown Project
Akron88ddd4a2022-11-08 10:41:35 +0100101else {
Akron74994cf2022-11-15 14:28:00 +0100102 print "Unknown project $project!\n\n";
Akron88ddd4a2022-11-08 10:41:35 +0100103 exit(1);
104};
105
106
107
108_check('git commit --amend --no-edit');
109
110{
111 my $ret = `git log -1 --pretty=%B`;
112 my $newret = '';
113 my $change_id = '';
114 my $first = 1;
115 foreach my $line (split "\n", $ret) {
116 if ($first) {
117 chomp $line;
118 $line .= " (closes #$pr)\n";
119 $first = 0;
120 }
121 elsif ($line =~ /^Change-Id: /) {
122 $change_id = $line;
123 next;
124 };
125 $newret .= $line . "\n";
126 };
127
128 if ($change_id) {
129 $newret .= "\n" . $change_id."\n\n";
130 };
131
132 my $msg_file = tempfile();
133 $msg_file->spurt($newret);
134
135 print "===================================\n";
136 print $newret;
137 print "===================================\n";
138
139 _check('git commit -F ' . $msg_file . ' --amend');
140};
141
Akron0e9e5f52022-11-23 09:47:47 +0100142_check('git push origin HEAD:refs/for/master');
Akron88ddd4a2022-11-08 10:41:35 +0100143
144_check('git checkout master');
145_check('git branch -D ' . $branch);
146
147print "\n\nEverything done - thank you!\n\n"
148
149__END__
150
151=pod
152
153This script is an alternative to C<import_github_pull_requests>
154that ignores CI results on github and just requires the
155URL of a specific GH pull request to send it through Gerrit.
Helge4d96c362023-06-21 17:06:32 +0200156
157Prerequisites:
158Remote repository "github"
159For Kustvakt and Koral Java 11 at /usr/lib/jvm/java-1.11.0-openjdk-amd6
Helge7cd2a612024-07-17 12:23:51 +0200160For KorapSRU Java 8 at /usr/lib/jvm/java-1.8.0-openjdk-amd6
161For KalamarExport-Plugin Java 17 at /usr/lib/jvm/java-17-openjdk-amd64