From ba6e35884b7e14d991618b9648b9d49fff1b4733 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 1 Jul 2020 12:02:58 -0700 Subject: [PATCH] fix: skip Java releases if snapshot is specified, but does not match repo state (#481) --- src/releasers/java-bom.ts | 13 +++++++++- src/releasers/java-yoshi.ts | 13 +++++++++- test/releasers/java-bom.ts | 50 ++++++++++++++++++++++++++++++++++-- test/releasers/java-yoshi.ts | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 4 deletions(-) diff --git a/src/releasers/java-bom.ts b/src/releasers/java-bom.ts index 83d189f58..b70df50e9 100644 --- a/src/releasers/java-bom.ts +++ b/src/releasers/java-bom.ts @@ -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) { diff --git a/src/releasers/java-yoshi.ts b/src/releasers/java-yoshi.ts index 57c148c73..022fcafcc 100644 --- a/src/releasers/java-yoshi.ts +++ b/src/releasers/java-yoshi.ts @@ -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) { diff --git a/test/releasers/java-bom.ts b/test/releasers/java-bom.ts index 6c741fa35..cbaac235a 100644 --- a/test/releasers/java-bom.ts +++ b/test/releasers/java-bom.ts @@ -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(); diff --git a/test/releasers/java-yoshi.ts b/test/releasers/java-yoshi.ts index 35d29e818..fdb27a840 100644 --- a/test/releasers/java-yoshi.ts +++ b/test/releasers/java-yoshi.ts @@ -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(); + }); });