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 | 36ae364 | 2024-01-24 13:42:56 +0100 | [diff] [blame^] | 75 | # Krill |
| 76 | elsif ($project =~ m!^Krill$!i) { |
| 77 | _check('JAVA_HOME="'.$JAVA17_HOME.'" mvn clean test'); |
| 78 | } |
| 79 | |
Akron | 579efe0 | 2023-02-28 09:52:26 +0100 | [diff] [blame] | 80 | # Kalamar-Plugin-ExternalResources |
| 81 | elsif ($project =~ m!^Kalamar-Plugin-ExternalResources$!i) { |
| 82 | _check('go test ./...'); |
| 83 | } |
| 84 | |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 85 | # KorapSRU |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 86 | elsif ($project =~ m!^KorapSRU$!i) { |
Akron | 081c5d5 | 2024-01-11 13:10:22 +0100 | [diff] [blame] | 87 | _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test'); |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Akron | 081c5d5 | 2024-01-11 13:10:22 +0100 | [diff] [blame] | 90 | # Korap-Tokenizer |
| 91 | elsif ($project =~ m!^KorAP-Tokenizer$!i) { |
| 92 | _check('JAVA_HOME="'.$JAVA8_HOME.'" mvn clean test'); |
| 93 | } |
| 94 | |
| 95 | # Datok |
Akron | 579efe0 | 2023-02-28 09:52:26 +0100 | [diff] [blame] | 96 | elsif ($project =~ m!^Datok$!i) { |
| 97 | _check('make test'); |
| 98 | } |
| 99 | |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 100 | # Unknown Project |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 101 | else { |
Akron | 74994cf | 2022-11-15 14:28:00 +0100 | [diff] [blame] | 102 | print "Unknown project $project!\n\n"; |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 103 | 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 | |
Akron | 0e9e5f5 | 2022-11-23 09:47:47 +0100 | [diff] [blame] | 142 | _check('git push origin HEAD:refs/for/master'); |
Akron | 88ddd4a | 2022-11-08 10:41:35 +0100 | [diff] [blame] | 143 | |
| 144 | _check('git checkout master'); |
| 145 | _check('git branch -D ' . $branch); |
| 146 | |
| 147 | print "\n\nEverything done - thank you!\n\n" |
| 148 | |
| 149 | __END__ |
| 150 | |
| 151 | =pod |
| 152 | |
| 153 | This script is an alternative to C<import_github_pull_requests> |
| 154 | that ignores CI results on github and just requires the |
| 155 | URL of a specific GH pull request to send it through Gerrit. |
Helge | 4d96c36 | 2023-06-21 17:06:32 +0200 | [diff] [blame] | 156 | |
| 157 | Prerequisites: |
| 158 | Remote repository "github" |
| 159 | For Kustvakt and Koral Java 11 at /usr/lib/jvm/java-1.11.0-openjdk-amd6 |
| 160 | For KorapSRU and KalamarExport-Plugin Java 8 at /usr/lib/jvm/java-1.8.0-openjdk-amd6 |