Skip to content

Commit

Permalink
fix: skip Java releases if snapshot is specified, but does not match …
Browse files Browse the repository at this point in the history
…repo state (#481)
  • Loading branch information
chingor13 authored Jul 1, 2020
1 parent be5ea39 commit ba6e358
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/releasers/java-bom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ export class JavaBom extends ReleasePR {
const currentVersions = VersionsManifest.parseVersions(
versionsManifestContent.parsedContent
);
this.snapshot = VersionsManifest.needsSnapshot(

const snapshotNeeded = VersionsManifest.needsSnapshot(
versionsManifestContent.parsedContent
);
if (this.snapshot === undefined) {
this.snapshot = snapshotNeeded;
} else if (this.snapshot !== snapshotNeeded) {
checkpoint(
'release asked for a snapshot, but no snapshot is needed',
CheckpointType.Failure
);
return;
}

if (this.snapshot) {
this.labels = ['type: process'];
if (this.snapshot) {
Expand Down
13 changes: 12 additions & 1 deletion src/releasers/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ export class JavaYoshi extends ReleasePR {
const currentVersions = VersionsManifest.parseVersions(
versionsManifestContent.parsedContent
);
this.snapshot = VersionsManifest.needsSnapshot(

const snapshotNeeded = VersionsManifest.needsSnapshot(
versionsManifestContent.parsedContent
);
if (this.snapshot === undefined) {
this.snapshot = snapshotNeeded;
} else if (this.snapshot !== snapshotNeeded) {
checkpoint(
'release asked for a snapshot, but no snapshot is needed',
CheckpointType.Failure
);
return;
}

if (this.snapshot) {
this.labels = ['type: process'];
if (this.snapshot) {
Expand Down
50 changes: 48 additions & 2 deletions test/releasers/java-bom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,54 @@ describe('JavaBom', () => {
// not actually used by this type of repo.
packageName: 'java-cloud-bom',
apiUrl: 'https://api.github.com',
// we will detect that a snapshot is needed, and still perform a
// snapshot release:
snapshot: true,
});
await releasePR.run();
req.done();
});
it('ignores a snapshot release if no snapshot needed', async () => {
const versionsContent = readFileSync(
resolve(fixturesPath, 'versions.txt'),
'utf8'
);
const req = nock('https://api.github.com')
.get('/repos/googleapis/java-cloud-bom/pulls?state=closed&per_page=100')
.reply(200, undefined)
.get('/repos/googleapis/java-cloud-bom/contents/versions.txt')
.reply(200, {
content: Buffer.from(versionsContent, 'utf8').toString('base64'),
sha: 'abc123',
});
const releasePR = new JavaBom({
repoUrl: 'googleapis/java-cloud-bom',
releaseType: 'java-bom',
// not actually used by this type of repo.
packageName: 'java-cloud-bom',
apiUrl: 'https://api.github.com',
snapshot: true,
});
await releasePR.run();
req.done();
});
it('ignores an explicit release if no snapshot needed', async () => {
const versionsContent = readFileSync(
resolve(fixturesPath, 'released-versions.txt'),
'utf8'
);
const req = nock('https://api.github.com')
.get('/repos/googleapis/java-cloud-bom/pulls?state=closed&per_page=100')
.reply(200, undefined)
.get('/repos/googleapis/java-cloud-bom/contents/versions.txt')
.reply(200, {
content: Buffer.from(versionsContent, 'utf8').toString('base64'),
sha: 'abc123',
});
const releasePR = new JavaBom({
repoUrl: 'googleapis/java-cloud-bom',
releaseType: 'java-bom',
// not actually used by this type of repo.
packageName: 'java-cloud-bom',
apiUrl: 'https://api.github.com',
snapshot: false,
});
await releasePR.run();
Expand Down
48 changes: 48 additions & 0 deletions test/releasers/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,52 @@ describe('JavaYoshi', () => {
await releasePR.run();
req.done();
});
it('ignores a snapshot release if no snapshot needed', async () => {
const versionsContent = readFileSync(
resolve(fixturesPath, 'versions.txt'),
'utf8'
);
const req = nock('https://api.github.com')
.get('/repos/googleapis/java-trace/pulls?state=closed&per_page=100')
.reply(200, undefined)
.get('/repos/googleapis/java-trace/contents/versions.txt')
.reply(200, {
content: Buffer.from(versionsContent, 'utf8').toString('base64'),
sha: 'abc123',
});
const releasePR = new JavaYoshi({
repoUrl: 'googleapis/java-trace',
releaseType: 'java-yoshi',
// not actually used by this type of repo.
packageName: 'java-trace',
apiUrl: 'https://api.github.com',
snapshot: true,
});
await releasePR.run();
req.done();
});
it('ignores an explicit release if a snapshot needed', async () => {
const versionsContent = readFileSync(
resolve(fixturesPath, 'released-versions.txt'),
'utf8'
);
const req = nock('https://api.github.com')
.get('/repos/googleapis/java-trace/pulls?state=closed&per_page=100')
.reply(200, undefined)
.get('/repos/googleapis/java-trace/contents/versions.txt')
.reply(200, {
content: Buffer.from(versionsContent, 'utf8').toString('base64'),
sha: 'abc123',
});
const releasePR = new JavaYoshi({
repoUrl: 'googleapis/java-trace',
releaseType: 'java-yoshi',
// not actually used by this type of repo.
packageName: 'java-trace',
apiUrl: 'https://api.github.com',
snapshot: false,
});
await releasePR.run();
req.done();
});
});

0 comments on commit ba6e358

Please sign in to comment.