11/**
22 * Usage:
3- * node publishMaven.js -task [upload|promote]
3+ * node publishMaven.js -task [gpg][ upload|promote]
44 *
5+ * gpg: Sign artifacts with GPG.
56 * upload: Upload artifacts to a nexus staging repo.
67 * promote: Promote a repo to get it picked up by Maven Central.
78 */
@@ -33,7 +34,9 @@ main(configs, artifactFolder);
3334function main ( ) {
3435 const argv = process . argv ;
3536 const task = argv [ argv . indexOf ( "-task" ) + 1 ] ;
36- if ( task === "upload" ) {
37+ if ( task === "gpg" ) {
38+ gpgSign ( configs , artifactFolder ) ;
39+ } else if ( task === "upload" ) {
3740 uploadToStaging ( configs , artifactFolder ) ;
3841 } else if ( task === "promote" ) {
3942 promoteToCentral ( configs ) ;
@@ -43,6 +46,27 @@ function main() {
4346 }
4447}
4548
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+
4670/**
4771 * Task upload: Upload artifacts to a nexus staging repo.
4872 *
@@ -141,7 +165,7 @@ function addChecksumsAndGpgSignature(configs, artifactFolder) {
141165 fs . readdirSync ( modulePath )
142166 . filter ( name => name . endsWith ( ".md5" ) || name . endsWith ( ".sha1" ) || name . endsWith ( ".asc" ) )
143167 . forEach ( name => fs . unlinkSync ( path . join ( modulePath , name ) ) ) ;
144-
168+
145169 const files = fs . readdirSync ( modulePath ) ;
146170 for ( let file of files ) {
147171 // calc md5.
@@ -153,7 +177,7 @@ function addChecksumsAndGpgSignature(configs, artifactFolder) {
153177 const sha1 = childProcess . execSync ( `sha1sum "${ path . join ( modulePath , file ) } "` ) ;
154178 const sha1Match = / ( [ a - z 0 - 9 ] { 40 } ) / . exec ( sha1 . toString ( ) ) ;
155179 fs . writeFileSync ( path . join ( modulePath , file + ".sha1" ) , sha1Match [ 0 ] ) ;
156-
180+
157181 // gpg sign.
158182 childProcess . execSync ( `gpg --batch --pinentry-mode loopback --passphrase "${ configs . gpgpass } " -ab "${ path . join ( modulePath , file ) } "` )
159183 }
0 commit comments