Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman committed Jul 13, 2020
2 parents 7bf4fa4 + a0b3ff1 commit dc82371
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,35 @@ export async function checkout(ref: string): Promise<void> {
export async function createTag(name: string, annotation: string): Promise<void> {
let tagArgs = ['tag', name];
if (annotation.length) {
// If we're pushing an annotation, `user.name` and `user.email` must be configured.
await ensureUserIsConfigured();

tagArgs.push('-m', annotation);
}

await execa('git', tagArgs);
await execa('git', ['push', '--tags']);
}

export async function ensureUserIsConfigured(): Promise<void> {
if (!(await hasConfig('user.name'))) {
await setConfig('user.name', 'github-actions');
}

if (!(await hasConfig('user.email'))) {
await setConfig('user.email', 'github-actions@user.noreply.github.com');
}
}

export async function hasConfig(name: string): Promise<boolean> {
try {
await execa('git', ['config', name]);
return true;
} catch {
return false;
}
}

export async function setConfig(name: string, value: string): Promise<void> {
await execa('git', ['config', name, value]);
}

0 comments on commit dc82371

Please sign in to comment.