Skip to content

Commit

Permalink
feat: implement generic java strategy (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored and bcoe committed Aug 19, 2019
1 parent ac05dc6 commit 53b62b8
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 21 deletions.
8 changes: 8 additions & 0 deletions __snapshots__/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,11 @@ exports['GitHub commitsSinceSha returns commits immediately before sha 1'] = [
]
}
]

exports['GitHub findFilesByfilename returns files matching the requested pattern 1'] = [
"appengine/pom.xml",
"bom/pom.xml",
"credentials/pom.xml",
"oauth2_http/pom.xml",
"pom.xml"
]
5 changes: 5 additions & 0 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { JavaAuthYoshi } from '../releasers/java-auth-yoshi';
import { Node } from '../releasers/node';
import { PHPYoshi } from '../releasers/php-yoshi';
import { RubyYoshi } from '../releasers/ruby-yoshi';
import { JavaYoshi } from '../releasers/java-yoshi';

const yargs = require('yargs');

Expand Down Expand Up @@ -85,8 +86,12 @@ const argv = yargs
rp = new PHPYoshi(argv);
break;
case ReleaseType.JavaAuthYoshi:
// TODO: coerce this to the generic Java release
rp = new JavaAuthYoshi(argv);
break;
case ReleaseType.JavaYoshi:
rp = new JavaYoshi(argv);
break;
case ReleaseType.RubyYoshi:
rp = new RubyYoshi(argv);
break;
Expand Down
19 changes: 19 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ interface GitHubPR {
labels: string[];
}

interface FileSearchResponse {
items: FileSearchResponseFile[];
}

interface FileSearchResponseFile {
path: string;
}

let probotMode = false;

export class GitHub {
Expand Down Expand Up @@ -876,6 +884,17 @@ export class GitHub {
);
}
}

async findFilesByFilename(filename: string): Promise<string[]> {
const response: Octokit.Response<
FileSearchResponse
> = await this.octokit.search.code({
q: `filename:${filename}+repo:${this.repo}`,
});
return response.data.items.map(file => {
return file.path;
});
}
}

class AuthError extends Error {
Expand Down
1 change: 1 addition & 0 deletions src/release-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum ReleaseType {
Node = 'node',
PHPYoshi = 'php-yoshi',
JavaAuthYoshi = 'java-auth-yoshi',
JavaYoshi = 'java-yoshi',
RubyYoshi = 'ruby-yoshi',
}

Expand Down
10 changes: 5 additions & 5 deletions src/releasers/java-auth-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { Commit } from '../graphql-to-commits';
// Generic
import { Changelog } from '../updaters/changelog';
// Java
import { PomXML } from '../updaters/pom-xml';
import { PomXML } from '../updaters/java/pom-xml';
// Yoshi Java Auth Library
import { JavaAuthVersions } from '../updaters/java-auth-versions';
import { JavaAuthReadme } from '../updaters/java-auth-readme';
import { VersionsManifest } from '../updaters/java/versions-manifest';
import { Readme } from '../updaters/java/readme';

export class JavaAuthYoshi extends ReleasePR {
protected async _run() {
Expand Down Expand Up @@ -96,7 +96,7 @@ export class JavaAuthYoshi extends ReleasePR {
);

updates.push(
new JavaAuthReadme({
new Readme({
path: 'README.md',
changelogEntry,
version: candidate.version,
Expand All @@ -106,7 +106,7 @@ export class JavaAuthYoshi extends ReleasePR {
}

updates.push(
new JavaAuthVersions({
new VersionsManifest({
path: 'versions.txt',
changelogEntry,
version: candidate.version,
Expand Down
135 changes: 135 additions & 0 deletions src/releasers/java-yoshi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ReleasePR, ReleaseCandidate } from '../release-pr';

import { ConventionalCommits } from '../conventional-commits';
import { GitHubTag } from '../github';
import { checkpoint, CheckpointType } from '../util/checkpoint';
import { Update } from '../updaters/update';
import { Commit } from '../graphql-to-commits';

// Generic
import { Changelog } from '../updaters/changelog';
// Java
import { PomXML } from '../updaters/java/pom-xml';
import { VersionsManifest } from '../updaters/java/versions-manifest';
import { Readme } from '../updaters/java/readme';

export class JavaYoshi extends ReleasePR {
protected async _run() {
const latestTag: GitHubTag | undefined = await this.gh.latestTag();
const commits: Commit[] = this.snapshot
? [
{
sha: 'abc123',
message: 'fix: ',
files: [],
},
]
: await this.commits(latestTag ? latestTag.sha : undefined, 100, true);
let prSHA = commits[0].sha;

const cc = new ConventionalCommits({
commits,
githubRepoUrl: this.repoUrl,
bumpMinorPreMajor: this.bumpMinorPreMajor,
});
const candidate: ReleaseCandidate = await this.coerceReleaseCandidate(
cc,
latestTag
);
let changelogEntry: string = await cc.generateChangelogEntry({
version: candidate.version,
currentTag: `v${candidate.version}`,
previousTag: candidate.previousTag,
});

// snapshot entries are special:
// 1. they don't update the README or CHANGELOG.
// 2. they always update a patch with the -SNAPSHOT suffix.
// 3. they're haunted.
if (this.snapshot) {
prSHA = latestTag!.sha;
candidate.version = `${candidate.version}-SNAPSHOT`;
changelogEntry =
'### Updating meta-information for bleeding-edge SNAPSHOT release.';
}

// don't create a release candidate until user facing changes
// (fix, feat, BREAKING CHANGE) have been made; a CHANGELOG that's
// one line is a good indicator that there were no interesting commits.
if (this.changelogEmpty(changelogEntry) && !this.snapshot) {
checkpoint(
`no user facing commits found since ${
latestTag ? latestTag.sha : 'beginning of time'
}`,
CheckpointType.Failure
);
return;
}

const updates: Update[] = [];

if (!this.snapshot) {
updates.push(
new Changelog({
path: 'CHANGELOG.md',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);

updates.push(
new Readme({
path: 'README.md',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);
}

updates.push(
new VersionsManifest({
path: 'versions.txt',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);

const pomFiles = await this.gh.findFilesByFilename('pom.xml');
pomFiles.forEach(path => {
updates.push(
new PomXML({
path,
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);
});

await this.openPR(
prSHA,
`${changelogEntry}\n---\n`,
updates,
candidate.version
);
}
}
4 changes: 2 additions & 2 deletions src/updaters/pom-xml.ts → src/updaters/java/pom-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { Update, UpdateOptions } from './update';
import { GitHubFileContents } from '../github';
import { Update, UpdateOptions } from '../update';
import { GitHubFileContents } from '../../github';

export class PomXML implements Update {
path: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import { checkpoint, CheckpointType } from '../util/checkpoint';
import { Update, UpdateOptions } from './update';
import { GitHubFileContents } from '../github';
import { Update, UpdateOptions } from '../update';
import { GitHubFileContents } from '../../github';

export class JavaAuthReadme implements Update {
export class Readme implements Update {
path: string;
changelogEntry: string;
version: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import { checkpoint, CheckpointType } from '../util/checkpoint';
import { Update, UpdateOptions } from './update';
import { GitHubFileContents } from '../github';
import { Update, UpdateOptions } from '../update';
import { GitHubFileContents } from '../../github';

export class JavaAuthVersions implements Update {
export class VersionsManifest implements Update {
path: string;
changelogEntry: string;
version: string;
Expand Down
Loading

0 comments on commit 53b62b8

Please sign in to comment.