Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use Mojo::File 'tempfile'; |
| 5 | use Mojo::UserAgent; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 6 | |
| 7 | our @ARGV; |
| 8 | |
Akron | 081c5d5 | 2024-01-11 13:10:22 +0100 | [diff] [blame] | 9 | my $JAVA8_HOME = '/usr/lib/jvm/java-1.8.0-openjdk-amd64'; |
| 10 | my $JAVA11_HOME = '/usr/lib/jvm/java-1.11.0-openjdk-amd64'; |
| 11 | my $JAVA17_HOME = '/usr/lib/jvm/java-1.17.0-openjdk-amd64'; |
| 12 | |
| 13 | if (-d $JAVA17_HOME) { |
| 14 | $JAVA17_HOME = '/opt/java/jdk-17.0.2'; |
| 15 | }; |
| 16 | |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 17 | my $url = $ARGV[0]; |
| 18 | |
| 19 | sub _check { |
| 20 | my $cmd = shift; |
Akron | 53d1821 | 2022-11-15 15:25:17 +0100 | [diff] [blame] | 21 | CHECK: |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 22 | 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; |
Akron | 53d1821 | 2022-11-15 15:25:17 +0100 | [diff] [blame] | 28 | } elsif ($x eq 'n' || $x eq 'N') { |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 29 | exit; |
Akron | 53d1821 | 2022-11-15 15:25:17 +0100 | [diff] [blame] | 30 | } else { |
| 31 | print "Please answer with 'y' or 'n'.\n"; |
| 32 | goto CHECK; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 33 | }; |
| 34 | }; |
| 35 | |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 36 | unless ($url) { |
Helge | 4d96c36 | 2023-06-21 17:06:32 +0200 | [diff] [blame] | 37 | print 'git_gerrit_pull https://github.com/KorAP/.../pull/..' . "\n"; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 38 | exit; |
| 39 | }; |
| 40 | |
| 41 | _check('git checkout master'); |
| 42 | |
| 43 | _check('git pull origin master'); |
| 44 | |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 45 | $url =~ m!KorAP/([^/]+?)/pull/(\d+?)$!; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 46 | |
| 47 | my $ua = Mojo::UserAgent->new; |
| 48 | |
| 49 | print "Fetch $url...\n"; |
| 50 | |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 51 | my $project = $1; |
| 52 | my $pr = $2; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 53 | my $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 | |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 60 | # Kustvakt |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 61 | if ($project =~ m!^Kustvakt$!i) { |
Akron | 01ea921 | 2024-01-24 13:42:01 +0100 | [diff] [blame] | 62 | _check('JAVA_HOME="'.$JAVA17_HOME.'" mvn clean test'); |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | # KalamarExport-Plugin |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 66 | elsif ($project =~ m!^Kalamar-Plugin-Export$!i) { |
Akron | 081c5d5 | 2024-01-11 13:10:22 +0100 | [diff] [blame] | 67 | _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test'); |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Akron | 39dae91 | 2022-11-23 09:41:53 +0100 | [diff] [blame] | 70 | # Koral |
| 71 | elsif ($project =~ m!^Koral$!i) { |
Akron | 56ba1a9 | 2024-01-24 13:42:32 +0100 | [diff] [blame^] | 72 | _check('JAVA_HOME="'.$JAVA17_HOME.'" mvn clean test'); |
Akron | 39dae91 | 2022-11-23 09:41:53 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Akron | 579efe0 | 2023-02-28 09:52:26 +0100 | [diff] [blame] | 75 | # Kalamar-Plugin-ExternalResources |
| 76 | elsif ($project =~ m!^Kalamar-Plugin-ExternalResources$!i) { |
| 77 | _check('go test ./...'); |
| 78 | } |
| 79 | |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 80 | # KorapSRU |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 81 | elsif ($project =~ m!^KorapSRU$!i) { |
Akron | 081c5d5 | 2024-01-11 13:10:22 +0100 | [diff] [blame] | 82 | _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test'); |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Akron | 081c5d5 | 2024-01-11 13:10:22 +0100 | [diff] [blame] | 85 | # Korap-Tokenizer |
| 86 | elsif ($project =~ m!^KorAP-Tokenizer$!i) { |
| 87 | _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test'); |
| 88 | } |
| 89 | |
| 90 | # Datok |
Akron | 579efe0 | 2023-02-28 09:52:26 +0100 | [diff] [blame] | 91 | elsif ($project =~ m!^Datok$!i) { |
| 92 | _check('make test'); |
| 93 | } |
| 94 | |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 95 | # Unknown Project |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 96 | else { |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 97 | print "Unknown project $project!\n\n"; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 98 | 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 | |
Akron | 0e9e5f5 | 2022-11-23 09:47:47 +0100 | [diff] [blame] | 137 | _check('git push origin HEAD:refs/for/master'); |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 138 | |
| 139 | _check('git checkout master'); |
| 140 | _check('git branch -D ' . $branch); |
| 141 | |
| 142 | print "\n\nEverything done - thank you!\n\n" |
| 143 | |
| 144 | __END__ |
| 145 | |
| 146 | =pod |
| 147 | |
| 148 | This script is an alternative to C<import_github_pull_requests> |
| 149 | that ignores CI results on github and just requires the |
| 150 | URL of a specific GH pull request to send it through Gerrit. |
Helge | 4d96c36 | 2023-06-21 17:06:32 +0200 | [diff] [blame] | 151 | |
| 152 | Prerequisites: |
| 153 | Remote repository "github" |
| 154 | For Kustvakt and Koral Java 11 at /usr/lib/jvm/java-1.11.0-openjdk-amd6 |
| 155 | For KorapSRU and KalamarExport-Plugin Java 8 at /usr/lib/jvm/java-1.8.0-openjdk-amd6 |