Skip to content

Commit

Permalink
Fix ignore artifacts which contain no POM/BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
markushi committed May 22, 2024
1 parent 532b8d1 commit 2187204
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/targets/__tests__/maven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ describe('upload', () => {
.fn()
.mockResolvedValueOnce('artifact/download/path');
mvnTarget.isBomFile = jest.fn().mockResolvedValueOnce(false);
mvnTarget.getPomFileInDist = jest.fn().mockResolvedValueOnce('pom-default.xml');

await mvnTarget.upload('r3v1s10n');

Expand Down Expand Up @@ -420,6 +421,7 @@ describe('upload', () => {
.fn()
.mockResolvedValueOnce('artifact/download/path');
mvnTarget.isBomFile = jest.fn().mockResolvedValueOnce('path/to/bomfile');
mvnTarget.getPomFileInDist = jest.fn().mockResolvedValueOnce(undefined);

await mvnTarget.upload('r3v1s10n');

Expand All @@ -446,6 +448,32 @@ describe('upload', () => {
expect(cmdArgs[6]).toBe('--settings');
expect(cmdArgs[7]).toBe(DEFAULT_OPTION_VALUE);
});

test('should skip upload for artifacts without any POM/BOM', async () => {
// simple mock to always use the same temporary directory,
// instead of creating a new one
(withTempDir as jest.MockedFunction<typeof withTempDir>).mockImplementation(
async cb => {
return await cb(tmpDirName);
}
);

const mvnTarget = createMavenTarget();

mvnTarget.getArtifactsForRevision = jest
.fn()
.mockResolvedValueOnce([{ filename: 'mockArtifact.zip' }]);
mvnTarget.artifactProvider.downloadArtifact = jest
.fn()
.mockResolvedValueOnce('artifact/download/path');

mvnTarget.isBomFile = jest.fn().mockResolvedValueOnce(false);
mvnTarget.getPomFileInDist = jest.fn().mockResolvedValueOnce(undefined);

await mvnTarget.upload('r3v1s10n');

expect(retrySpawnProcess).toHaveBeenCalledTimes(0);
});
});

describe('closeAndReleaseRepository', () => {
Expand Down
26 changes: 24 additions & 2 deletions src/targets/maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,16 @@ export class MavenTarget extends BaseTarget {
*/
private async uploadDistribution(distDir: string): Promise<void> {
const bomFile = await this.getBomFileInDist(distDir);
const pomFile = await this.getPomFileInDist(distDir);

if (bomFile) {
this.logger.debug('Found BOM: ', bomFile);
await this.uploadBomDistribution(bomFile);
} else {
} else if (pomFile) {
this.logger.debug('Found POM: ', pomFile);
await this.uploadPomDistribution(distDir);
} else {
this.logger.warn(`No BOM/POM file found in: ${distDir}, skipping directory`);
}
}

Expand Down Expand Up @@ -341,7 +346,7 @@ export class MavenTarget extends BaseTarget {
} catch (error) {
this.logger.warn(
`Could not determine if path corresponds to a BOM file: ${pomFilepath}\n` +
'Error:\n',
'Error:\n',
error
);
return false;
Expand Down Expand Up @@ -475,6 +480,23 @@ export class MavenTarget extends BaseTarget {
};
}

/**
* Returns a file path to pom-default.xml if the file exists
* within the distribution directory.
*/
public async getPomFileInDist(distDir: string): Promise<string | undefined> {
const pomFilepath = join(distDir, 'pom-default.xml');
try {
const stat = await fsPromises.stat(pomFilepath);
if (stat.isFile()) {
return pomFilepath;
}
} catch (e) {
// ignored
}
return undefined;
}

private async uploadPomDistribution(distDir: string): Promise<void> {
if (this.mavenConfig.kmp !== false) {
await this.uploadKmpPomDistribution(distDir);
Expand Down

0 comments on commit 2187204

Please sign in to comment.