Skip to content

Commit 1661cff

Browse files
committed
build: Specify the key to use
This way I could locally upload to maven central after the initial problem that the wrong key was used to sign This should fix #16433
1 parent 5463ed9 commit 1661cff

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

build/ci.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,17 @@ func doAndroidArchive(cmdline []string) {
755755
os.Rename(archive, meta.Package+".aar")
756756
if *signer != "" && *deploy != "" {
757757
// Import the signing key into the local GPG instance
758-
if b64key := os.Getenv(*signer); b64key != "" {
759-
key, err := base64.StdEncoding.DecodeString(b64key)
760-
if err != nil {
761-
log.Fatalf("invalid base64 %s", *signer)
762-
}
763-
gpg := exec.Command("gpg", "--import")
764-
gpg.Stdin = bytes.NewReader(key)
765-
build.MustRun(gpg)
758+
b64key := os.Getenv(*signer)
759+
key, err := base64.StdEncoding.DecodeString(b64key)
760+
if err != nil {
761+
log.Fatalf("invalid base64 %s", *signer)
762+
}
763+
gpg := exec.Command("gpg", "--import")
764+
gpg.Stdin = bytes.NewReader(key)
765+
build.MustRun(gpg)
766+
keyID, err := build.PGPKeyID(string(key))
767+
if err != nil {
768+
log.Fatal(err)
766769
}
767770
// Upload the artifacts to Sonatype and/or Maven Central
768771
repo := *deploy + "/service/local/staging/deploy/maven2"
@@ -771,6 +774,7 @@ func doAndroidArchive(cmdline []string) {
771774
}
772775
build.MustRunCommand("mvn", "gpg:sign-and-deploy-file", "-e", "-X",
773776
"-settings=build/mvn.settings", "-Durl="+repo, "-DrepositoryId=ossrh",
777+
"-Dgpg.keyname="+keyID,
774778
"-DpomFile="+meta.Package+".pom", "-Dfile="+meta.Package+".aar")
775779
}
776780
}

internal/build/pgp.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,15 @@ func PGPSignFile(input string, output string, pgpkey string) error {
5757
// Generate the signature and return
5858
return openpgp.ArmoredDetachSign(out, keys[0], in, nil)
5959
}
60+
61+
// PGPKeyID parses an armored key and returns the key ID.
62+
func PGPKeyID(pgpkey string) (string, error) {
63+
keys, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(pgpkey))
64+
if err != nil {
65+
return "", err
66+
}
67+
if len(keys) != 1 {
68+
return "", fmt.Errorf("key count mismatch: have %d, want %d", len(keys), 1)
69+
}
70+
return keys[0].PrimaryKey.KeyIdString(), nil
71+
}

0 commit comments

Comments
 (0)