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

feat: a flag to skip CI #443

Merged
merged 3 commits into from
May 20, 2020
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
20 changes: 20 additions & 0 deletions __snapshots__/java-yoshi.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,23 @@ public final class GoogleUtils {
private GoogleUtils() {}
}
`

exports['CHANGELOG-message'] = `
created CHANGELOG.md [ci skip]
`

exports['README-message'] = `
updated README.md [ci skip]
`

exports['GoogleUtils-message'] = `
updated google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java [ci skip]
`

exports['versions-message'] = `
updated versions.txt [ci skip]
`

exports['pom-message'] = `
updated pom.xml
`
8 changes: 8 additions & 0 deletions __snapshots__/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ exports['labels-simple'] = {
'autorelease: pending'
]
}

exports['CHANGELOG-simple-message'] = `
created CHANGELOG.md [ci skip]
`

exports['version-txt-simple-message'] = `
updated version.txt
`
24 changes: 22 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,24 @@ export class GitHub {
}

async updateFiles(updates: Update[], branch: string, refName: string) {
// does the user care about skipping CI at all?
const skipCiEverSet = updates.some(
upd => typeof upd.skipCi !== 'undefined'
);
if (skipCiEverSet) {
// if skipCi was set for some of the updates, disable CI for others
updates.forEach(upd => {
if (typeof upd.skipCi === 'undefined') {
upd.skipCi = true;
}
});
}
if (!skipCiEverSet && updates.length > 0) {
// if skipCi was not set for any of the files, disable CI for all files except the last one
updates.forEach(upd => (upd.skipCi = true));
updates[updates.length - 1].skipCi = false;
}

for (let i = 0; i < updates.length; i++) {
const update = updates[i];
let content;
Expand Down Expand Up @@ -770,7 +788,8 @@ export class GitHub {
owner: this.owner,
repo: this.repo,
path: update.path,
message: `updated ${update.path} [ci skip]`,
message:
`updated ${update.path}` + (update.skipCi ? ' [ci skip]' : ''),
content: Buffer.from(updatedContent, 'utf8').toString('base64'),
sha: content.data.sha,
branch,
Expand All @@ -785,7 +804,8 @@ export class GitHub {
owner: this.owner,
repo: this.repo,
path: update.path,
message: `created ${update.path} [ci skip]`,
message:
`created ${update.path}` + (update.skipCi ? ' [ci skip]' : ''),
content: Buffer.from(updatedContent, 'utf8').toString('base64'),
branch,
}
Expand Down
1 change: 1 addition & 0 deletions src/releasers/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class Simple extends ReleasePR {
version: candidate.version,
packageName: this.packageName,
contents,
skipCi: false,
})
);

Expand Down
2 changes: 2 additions & 0 deletions src/updaters/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export class Changelog implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = true;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string | undefined): string {
Expand Down
2 changes: 2 additions & 0 deletions src/updaters/java/google-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export class GoogleUtils implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}
updateContent(content: string): string {
return content.replace(
Expand Down
4 changes: 4 additions & 0 deletions src/updaters/java/java_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ export class JavaUpdate implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.versions = new Map<string, string>();
this.version = 'unused';
this.packageName = 'unused';
this.skipCi = options.skipCi;
if (options.versions) {
this.versions = options.versions;
} else if (options.version) {
Expand All @@ -43,6 +46,7 @@ export class JavaUpdate implements Update {
this.packageName = options.packageName;
}
}

updateContent(content: string): string {
const newLines: string[] = [];
let blockPackageName: string | null = null;
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ export class PackageJson implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
const parsed = JSON.parse(content);
checkpoint(
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/php-client-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class PHPClientVersion implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
Expand All @@ -32,7 +33,9 @@ export class PHPClientVersion implements Update {
this.version = options.version;
this.packageName = options.packageName;
this.contents = options.contents;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
return content.replace(
/const VERSION = '[0-9]+\.[0-9]+\.[0-9]+'/,
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/php-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class PHPManifest implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
Expand All @@ -37,7 +38,9 @@ export class PHPManifest implements Update {
this.version = options.version;
this.versions = options.versions;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
if (!this.versions || this.versions.size === 0) {
checkpoint(
Expand Down
2 changes: 2 additions & 0 deletions src/updaters/python/setup-cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export class SetupCfg implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}
updateContent(content: string): string {
return content.replace(
Expand Down
2 changes: 2 additions & 0 deletions src/updaters/python/setup-py.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export class SetupPy implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}
updateContent(content: string): string {
return content.replace(
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/root-composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class RootComposer implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
Expand All @@ -32,7 +33,9 @@ export class RootComposer implements Update {
this.version = options.version;
this.versions = options.versions;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
if (!this.versions || this.versions.size === 0) {
checkpoint(
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/samples-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ export class SamplesPackageJson implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
const parsed = JSON.parse(content);
if (!parsed.dependencies || !parsed.dependencies[this.packageName]) {
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/terraform/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ export class ReadMe implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
const minorVersion = this.version.split('.').slice(0, 2).join('.');
return content.replace(
Expand Down
2 changes: 2 additions & 0 deletions src/updaters/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface UpdateOptions {
version: string;
versions?: VersionsMap;
contents?: GitHubFileContents;
skipCi?: boolean;
}

export interface Update {
Expand All @@ -33,5 +34,6 @@ export interface Update {
version: string;
versions?: VersionsMap;
contents?: GitHubFileContents;
skipCi?: boolean;
updateContent(content: string | undefined): string;
}
3 changes: 3 additions & 0 deletions src/updaters/version-rb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ export class VersionRB implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(content: string): string {
return content.replace(
/"[0-9]+\.[0-9]+\.[0-9](-\w+)?"/,
Expand Down
2 changes: 2 additions & 0 deletions src/updaters/version-txt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export class VersionTxt implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
this.skipCi = options.skipCi;
}

updateContent(): string {
Expand Down
3 changes: 3 additions & 0 deletions src/updaters/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Version implements Update {
packageName: string;
create: boolean;
contents?: GitHubFileContents;
skipCi?: boolean;

constructor(options: UpdateOptions) {
this.create = false;
Expand All @@ -31,7 +32,9 @@ export class Version implements Update {
this.version = options.version;
this.packageName = options.packageName;
this.contents = options.contents;
this.skipCi = options.skipCi;
}

updateContent(): string {
return `${this.version}`;
}
Expand Down
5 changes: 5 additions & 0 deletions test/releasers/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('JavaYoshi', () => {
.put(
'/repos/googleapis/java-trace/contents/CHANGELOG.md',
(req: {[key: string]: string}) => {
snapshot('CHANGELOG-message', req.message);
snapshot(
'CHANGELOG',
Buffer.from(req.content, 'base64')
Expand All @@ -115,6 +116,7 @@ describe('JavaYoshi', () => {
.put(
'/repos/googleapis/java-trace/contents/README.md',
(req: {[key: string]: string}) => {
snapshot('README-message', req.message);
snapshot(
'README',
Buffer.from(req.content, 'base64').toString('utf8')
Expand All @@ -134,6 +136,7 @@ describe('JavaYoshi', () => {
.put(
'/repos/googleapis/java-trace/contents/versions.txt',
(req: {[key: string]: string}) => {
snapshot('versions-message', req.message);
snapshot(
'versions',
Buffer.from(req.content, 'base64').toString('utf8')
Expand All @@ -153,6 +156,7 @@ describe('JavaYoshi', () => {
.put(
'/repos/googleapis/java-trace/contents/pom.xml',
(req: {[key: string]: string}) => {
snapshot('pom-message', req.message);
snapshot('pom', Buffer.from(req.content, 'base64').toString('utf8'));
return true;
}
Expand All @@ -169,6 +173,7 @@ describe('JavaYoshi', () => {
.put(
'/repos/googleapis/java-trace/contents/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java',
(req: {[key: string]: string}) => {
snapshot('GoogleUtils-message', req.message);
snapshot(
'GoogleUtils',
Buffer.from(req.content, 'base64').toString('utf8')
Expand Down
Loading