Skip to content

Commit

Permalink
feat(jsii): support publishing maven artifacts to github (projen#363)
Browse files Browse the repository at this point in the history
Fixes projen#355
* Add the envs necessary for releasing to github java artefact package https://github.com/aws/jsii-release#maven
(I will see where I have to provide more docu)
  • Loading branch information
mmuller88 authored Jan 17, 2021
1 parent c665e0a commit e11996c
Show file tree
Hide file tree
Showing 5 changed files with 534 additions and 475 deletions.
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -6864,6 +6864,8 @@ Name | Type | Description
**javaPackage**🔹 | <code>string</code> | <span></span>
**mavenArtifactId**🔹 | <code>string</code> | <span></span>
**mavenGroupId**🔹 | <code>string</code> | <span></span>
**mavenRepositoryUrl**?🔹 | <code>string</code> | Deployment repository when not deploying to Maven Central.<br/>__*Default*__: not set
**mavenServerId**?🔹 | <code>string</code> | Used in maven settings for credential lookup (e.g. use github when publishing to GitHub).<br/>__*Default*__: "ossrh" Defaults to Maven Central.



Expand Down
2 changes: 2 additions & 0 deletions docs/awscdk-construct.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ any number of jsii target languages.
javaPackage: 'com.acme.hello',
mavenArtifactId: 'hello-jsii',
mavenGroupId: 'com.acme.hello'
serverId: 'github',
repositoryUrl: 'https://maven.pkg.github.com/example/hello-jsii',
},
python: {
distName: 'acme.hello-jsii',
Expand Down
45 changes: 45 additions & 0 deletions src/__tests__/jsii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,48 @@ describe('author', () => {
});
});

describe('maven repository options', () => {
test('use maven central as repository', () => {
const project = new JsiiProject({
authorAddress: 'https://foo.bar',
authorUrl: 'https://foo.bar',
repositoryUrl: 'https://github.com/foo/bar.git',
author: 'My Name',
outdir: mkdtemp(),
name: 'testproject',
publishToMaven: {
javaPackage: 'com.github.eladb.watchful',
mavenGroupId: 'com.github.eladb',
mavenArtifactId: 'cdk-watchful',
},
});

const workflow = synthSnapshot(project)['.github/workflows/release.yml'];
expect(workflow).toContain('run: npx -p jsii-release jsii-release-maven');
expect(workflow).not.toContainEqual('MAVEN_SERVER_ID');
expect(workflow).not.toContainEqual('MAVEN_REPOSITORY_URL');
});

test('use github as repository', () => {
const project = new JsiiProject({
authorAddress: 'https://foo.bar',
authorUrl: 'https://foo.bar',
repositoryUrl: 'https://github.com/foo/bar.git',
author: 'My Name',
outdir: mkdtemp(),
name: 'testproject',
publishToMaven: {
javaPackage: 'com.github.eladb.watchful',
mavenGroupId: 'com.github.eladb',
mavenArtifactId: 'cdk-watchful',
mavenServerId: 'github',
mavenRepositoryUrl: 'https://maven.pkg.github.com/eladb',
},
});

const workflow = synthSnapshot(project)['.github/workflows/release.yml'];
expect(workflow).toContain('MAVEN_SERVER_ID: github');
expect(workflow).toContain('MAVEN_REPOSITORY_URL: https://maven.pkg.github.com/eladb');
});
});

18 changes: 16 additions & 2 deletions src/jsii-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ export interface JsiiJavaTarget {
readonly javaPackage: string;
readonly mavenGroupId: string;
readonly mavenArtifactId: string;
/**
* Used in maven settings for credential lookup (e.g. use github when publishing to GitHub).
*
* @default "ossrh" Defaults to Maven Central.
*/
readonly mavenServerId?: string;
/**
* Deployment repository when not deploying to Maven Central
*
* @default - not set
*/
readonly mavenRepositoryUrl?: string;
}

export interface JsiiPythonTarget {
Expand Down Expand Up @@ -211,7 +223,7 @@ export class JsiiProject extends TypeScriptProject {
},
};

this.publishToMaven();
this.publishToMaven(options.publishToMaven.mavenServerId, options.publishToMaven.mavenRepositoryUrl);
publishing = true;
}

Expand Down Expand Up @@ -329,7 +341,7 @@ export class JsiiProject extends TypeScriptProject {
});
}

private publishToMaven() {
private publishToMaven(serverId: string | undefined, repositoryUrl: string | undefined) {
if (!this.releaseWorkflow) {
return;
}
Expand All @@ -353,6 +365,8 @@ export class JsiiProject extends TypeScriptProject {
name: 'Release',
run: 'npx -p jsii-release jsii-release-maven',
env: {
MAVEN_SERVER_ID: serverId,
MAVEN_REPOSITORY_URL: repositoryUrl,
MAVEN_GPG_PRIVATE_KEY: '${{ secrets.MAVEN_GPG_PRIVATE_KEY }}',
MAVEN_GPG_PRIVATE_KEY_PASSPHRASE: '${{ secrets.MAVEN_GPG_PRIVATE_KEY_PASSPHRASE }}',
MAVEN_PASSWORD: '${{ secrets.MAVEN_PASSWORD }}',
Expand Down
Loading

0 comments on commit e11996c

Please sign in to comment.