1
1
/**
2
2
* Usage:
3
- * node publishMaven.js -task [upload|promote]
3
+ * node publishMaven.js -task [gpg][ upload|promote]
4
4
*
5
+ * gpg: Sign artifacts with GPG.
5
6
* upload: Upload artifacts to a nexus staging repo.
6
7
* promote: Promote a repo to get it picked up by Maven Central.
7
8
*/
@@ -33,7 +34,9 @@ main(configs, artifactFolder);
33
34
function main ( ) {
34
35
const argv = process . argv ;
35
36
const task = argv [ argv . indexOf ( "-task" ) + 1 ] ;
36
- if ( task === "upload" ) {
37
+ if ( task === "gpg" ) {
38
+ gpgSign ( configs , artifactFolder ) ;
39
+ } else if ( task === "upload" ) {
37
40
uploadToStaging ( configs , artifactFolder ) ;
38
41
} else if ( task === "promote" ) {
39
42
promoteToCentral ( configs ) ;
@@ -43,6 +46,27 @@ function main() {
43
46
}
44
47
}
45
48
49
+ /**
50
+ * Task gpg: Sign artifacts with GPG.
51
+ *
52
+ * Required binaries:
53
+ * - gpg
54
+ *
55
+ * Required Environment Variables:
56
+ * - artifactFolder: folder containing *.jar/*.pom files.
57
+ * - GPGPASS: passphrase of GPG key.
58
+ */
59
+ function gpgSign ( configs , artifactFolder ) {
60
+ const props = [ "artifactFolder" , "gpgpass" ] ;
61
+ for ( const prop of props ) {
62
+ if ( ! configs [ prop ] ) {
63
+ console . error ( `${ prop } is not set.` ) ;
64
+ process . exit ( 1 ) ;
65
+ }
66
+ }
67
+ addChecksumsAndGpgSignature ( configs , artifactFolder ) ;
68
+ }
69
+
46
70
/**
47
71
* Task upload: Upload artifacts to a nexus staging repo.
48
72
*
@@ -141,7 +165,7 @@ function addChecksumsAndGpgSignature(configs, artifactFolder) {
141
165
fs . readdirSync ( modulePath )
142
166
. filter ( name => name . endsWith ( ".md5" ) || name . endsWith ( ".sha1" ) || name . endsWith ( ".asc" ) )
143
167
. forEach ( name => fs . unlinkSync ( path . join ( modulePath , name ) ) ) ;
144
-
168
+
145
169
const files = fs . readdirSync ( modulePath ) ;
146
170
for ( let file of files ) {
147
171
// calc md5.
@@ -153,7 +177,7 @@ function addChecksumsAndGpgSignature(configs, artifactFolder) {
153
177
const sha1 = childProcess . execSync ( `sha1sum "${ path . join ( modulePath , file ) } "` ) ;
154
178
const sha1Match = / ( [ a - z 0 - 9 ] { 40 } ) / . exec ( sha1 . toString ( ) ) ;
155
179
fs . writeFileSync ( path . join ( modulePath , file + ".sha1" ) , sha1Match [ 0 ] ) ;
156
-
180
+
157
181
// gpg sign.
158
182
childProcess . execSync ( `gpg --batch --pinentry-mode loopback --passphrase "${ configs . gpgpass } " -ab "${ path . join ( modulePath , file ) } "` )
159
183
}
0 commit comments