Skip to content

Commit

Permalink
fix: additional fixes to zod schemas to pass through signing config a…
Browse files Browse the repository at this point in the history
…nd publish via a script (#3234)
  • Loading branch information
armandobelardo authored Mar 21, 2024
1 parent c4b78da commit 79fb0c8
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 23 deletions.
21 changes: 21 additions & 0 deletions fern/apis/public-api/generators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@ groups:
license: MIT
config:
client_class_name: Fern
java-sdk:
audiences:
- external
generators:
- name: fernapi/fern-java-sdk
version: 0.8.6
output:
location: maven
coordinate: com.fern.api:fern-java-sdk
username: fernapi
password: ${MAVEN_PASSWORD}
# TODO: uncomment after this config is released
# signature:
# keyId: ${MAVEN_CENTRAL_SECRET_KEY_KEY_ID}
# password: ${MAVEN_CENTRAL_SECRET_KEY_PASSWORD}
# secretKey: ${MAVEN_CENTRAL_SECRET_KEY}
github:
repository: fern-api/java-sdk
license: MIT
config:
client_class_name: Fern
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import com.fern.java.output.GeneratedGradleProperties;
import com.fern.java.output.GeneratedPublishScript;
import org.immutables.value.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -259,6 +261,11 @@ public final void runInPublishMode(
publishEnvVars.put(GeneratedBuildGradle.MAVEN_SIGNING_KEY_ID, signature.getKeyId());
publishEnvVars.put(GeneratedBuildGradle.MAVEN_SIGNING_PASSWORD, signature.getPassword());
publishEnvVars.put(GeneratedBuildGradle.MAVEN_SIGNING_KEY, signature.getSecretKey());
runCommandBlocking(
new String[] { "./.publish/prepare.sh" },
Paths.get(generatorConfig.getOutput().getPath()),
publishEnvVars);

}
runCommandBlocking(
new String[] { "gradle", "publish" },
Expand Down Expand Up @@ -318,12 +325,12 @@ private void addRootProjectFiles(Optional<MavenCoordinate> maybeMavenCoordinate,
.pluginId("signing")
.build());
buildGradle.addCustomBlocks("signing {\n"
+ " sign publishing.publications\n"
+ " def signingKeyId = findProperty(\"signingKeyId\")\n"
+ " def signingKey = findProperty(\"signingKey\")\n"
+ " def signingPassword = findProperty(\"signingPassword\")\n"
+ " useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)\n"
+ " sign(publishing.publications)\n"
+ "}");
// Generate an empty gradle.properties file
addGeneratedFile(GeneratedGradleProperties.getGeneratedFile());
// Generate script to populate that file
addGeneratedFile(GeneratedPublishScript.getGeneratedFile());
}
if (addTestBlock) {
buildGradle.addCustomBlocks("test {\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ public static String getPublishWorkflow(String registryUrl,
+ " architecture: x64\n"
+ "\n"
+ " - name: Publish to maven\n"
+ " run: |\n"
+ " run: |\n";

if (maybeSignatureGithubInfo.isPresent()) {
content = content
+ " ./.publish/prepare.sh\n";
}
content = content
+ " ./gradlew publish\n"
+ " env:\n"
+ " MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public abstract class GeneratedBuildGradle extends GeneratedFile {
public static final String JAVA_LIBRARY_PLUGIN_ID = "java-library";
public static final String MAVEN_PUBLISH_PLUGIN_ID = "maven-publish";

public static final String MAVEN_SIGNING_KEY_ID = "ORG_GRADLE_PROJECT_signingKeyId";
public static final String MAVEN_SIGNING_KEY_ID = "MAVEN_SIGNATURE_KID";

public static final String MAVEN_SIGNING_KEY = "ORG_GRADLE_PROJECT_signingKey";
public static final String MAVEN_SIGNING_KEY = "MAVEN_SIGNATURE_SECRET_KEY";

public static final String MAVEN_SIGNING_PASSWORD = "ORG_GRADLE_PROJECT_signingPassword";
public static final String MAVEN_SIGNING_PASSWORD = "MAVEN_SIGNATURE_PASSWORD";

public abstract List<GradlePlugin> plugins();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.fern.java.output;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class GeneratedGradleProperties {
private static final RawGeneratedFile GENERATED_FILE = RawGeneratedFile.builder()
.filename("gradle.properties")
.contents("")
.build();

private GeneratedGradleProperties() {}

public static RawGeneratedFile getGeneratedFile() {
return GENERATED_FILE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.fern.java.output;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class GeneratedPublishScript {
private static final RawGeneratedFile GENERATED_FILE = RawGeneratedFile.builder()
.filename("prepare.sh")
.contents("# Write key ring file\n" +
"echo $MAVEN_SIGNATURE_SECRET_KEY > armored_key.asc\n" +
"gpg -o publish_key.gpg --dearmor armored_key.asc\n\n" +
"# Generate gradle.properties file\n" +
"echo \"signing.keyId=$MAVEN_SIGNATURE_KID\" > gradle.properties\n" +
"echo \"signing.secretKeyRingFile=publish_key.gpg\" >> gradle.properties\n" +
"echo \"signing.password=$MAVEN_SIGNATURE_PASSWORD\" >> gradle.properties\n")
.directoryPrefix(".publish")
.build();

private GeneratedPublishScript() {}

public static RawGeneratedFile getGeneratedFile() {
return GENERATED_FILE;
}
}
2 changes: 1 addition & 1 deletion generators/java/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.6
0.8.7-rc0
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,15 @@ async function convertOutputMode({
registryUrl: generator.output.url ?? "https://s01.oss.sonatype.org/content/repositories/releases/",
username: generator.output.username ?? "",
password: generator.output.password ?? "",
coordinate: generator.output.coordinate
coordinate: generator.output.coordinate,
signature:
generator.output.signature != null
? {
keyId: generator.output.signature.keyId,
secretKey: generator.output.signature.secretKey,
password: generator.output.signature.password
}
: undefined
})
);
case "postman":
Expand Down Expand Up @@ -316,6 +324,14 @@ function getGithubPublishInfo(output: GeneratorOutputSchema): FernFiddle.GithubP
username: output.username,
password: output.password
}
: undefined,
signature:
output.signature != null
? {
keyId: output.signature.keyId,
password: output.signature.password,
secretKey: output.signature.secretKey
}
: undefined
});
case "postman":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ function getGithubPublishConfig(
signature:
value.signature != null
? {
keyIdEnvironmentVariable: EnvironmentVariable(value.signature?.keyId ?? ""),
passwordEnvironmentVariable: EnvironmentVariable(value.signature?.password ?? ""),
secretKeyEnvironmentVariable: EnvironmentVariable(value.signature?.secretKey ?? "")
keyIdEnvironmentVariable: EnvironmentVariable(value.signature.keyId ?? ""),
passwordEnvironmentVariable: EnvironmentVariable(value.signature.password ?? ""),
secretKeyEnvironmentVariable: EnvironmentVariable(value.signature.secretKey ?? "")
}
: undefined
}),
Expand Down Expand Up @@ -205,7 +205,8 @@ function newDummyPublishOutputConfig(
password: (outputMode as MavenOutput)?.password ?? "",
registryUrl: (outputMode as MavenOutput)?.registryUrl ?? "",
username: (outputMode as MavenOutput)?.username ?? "",
coordinate: (outputMode as MavenOutput)?.coordinate ?? ""
coordinate: (outputMode as MavenOutput)?.coordinate ?? "",
signature: (outputMode as MavenOutput)?.signature
},
npm: {
registryUrl: (outputMode as NpmOutput)?.registryUrl ?? "",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions seed/java-sdk/exhaustive/signed_publish/.publish/prepare.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions seed/java-sdk/exhaustive/signed_publish/build.gradle

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

0 comments on commit 79fb0c8

Please sign in to comment.