Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(maven): move importGPGKey function call from constructor to publish #553

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/targets/__tests__/maven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,16 @@ describe('Maven target configuration', () => {
expect(typeof mvnTarget.config.kmp.appleDistDirRegex).toBe('string');
});

test('import GPG private key if one is present in the environment', () => {
test('import GPG private key if one is present in the environment', async () => {
setTargetSecretsInEnv();
process.env.GPG_PRIVATE_KEY = DEFAULT_OPTION_VALUE;
createMavenTarget(getFullTargetConfig());
const callOrder: string[] = [];
const mvnTarget = createMavenTarget(getFullTargetConfig());
mvnTarget.upload = jest.fn(async () => void callOrder.push('upload'));
mvnTarget.closeAndReleaseRepository = jest.fn(
async () => void callOrder.push('closeAndReleaseRepository')
);
await mvnTarget.publish('1.0.0', 'r3v1s10n');
expect(importGPGKey).toHaveBeenCalledWith(DEFAULT_OPTION_VALUE);
});
});
Expand Down
7 changes: 3 additions & 4 deletions src/targets/maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export class MavenTarget extends BaseTarget {
) {
super(config, artifactProvider);
this.mavenConfig = this.getMavenConfig();

if (process.env.GPG_PRIVATE_KEY) {
importGPGKey(process.env.GPG_PRIVATE_KEY);
}
}

/**
Expand Down Expand Up @@ -236,6 +232,9 @@ export class MavenTarget extends BaseTarget {
* @param revision Git commit SHA to be published.
*/
public async publish(_version: string, revison: string): Promise<void> {
if (process.env.GPG_PRIVATE_KEY) {
await importGPGKey(process.env.GPG_PRIVATE_KEY);
}
await this.upload(revison);
await this.closeAndReleaseRepository();
}
Expand Down
Loading