-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically moves tags for major, minor and prerelease revision. * `1.2.3` moves tag `v1.2` * `1.2.3` moves tag `v1` if there is no `v1.3.0` * `1.2.3-alpha.4` moves tag `v1.2.3-alpha`
- Loading branch information
1 parent
f3c7f85
commit 245e2d7
Showing
11 changed files
with
195 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { spawn } from './spawn' | ||
|
||
export async function gitConfig(env: {[k: string]: string | undefined}): Promise<void> { | ||
const name = env.GITHUB_ACTOR || 'github-actions[bot]' | ||
|
||
const email = env.GITHUB_ACTOR | ||
? `${env.GITHUB_ACTOR}@users.noreply.github.com` | ||
: '41898282+github-actions[bot]@users.noreply.github.com' | ||
|
||
await spawn('git', ['config', '--global', 'user.name', name]) | ||
await spawn('git', ['config', '--global', 'user.email', email]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { spawn } from './spawn' | ||
|
||
export async function updateTags( | ||
ref: string, | ||
versionString: string, | ||
version: { | ||
major: string, | ||
minor: string, | ||
patch: string, | ||
revision: string | undefined, | ||
revisionType: string | undefined, | ||
}, | ||
tagPrefix = '', | ||
): Promise<string[]> { | ||
const tags: string[] = [] | ||
|
||
if (!version.revision) { | ||
const minorTag = `${tagPrefix}${version.major}.${version.minor}` | ||
tags.push(minorTag) | ||
|
||
const nextMinor = `${tagPrefix}${version.major}.${Number(version.minor) + 1}.0` | ||
const hasNextMinor = await spawn('git', ['ls-remote', 'origin', `refs/tags/${nextMinor}`]) | ||
if (!hasNextMinor) { | ||
const majorTag = `${tagPrefix}${version.major}` | ||
tags.push(majorTag) | ||
} | ||
} else if (version.revisionType) { | ||
const revisionTag = `${tagPrefix}${version.major}.${version.minor}.${version.patch}-${version.revisionType}` | ||
tags.push(revisionTag) | ||
} | ||
|
||
if (tags.length) { | ||
for (const tag of tags) { | ||
await spawn('git', ['tag', '-fam', versionString, tag, ref]) | ||
} | ||
await spawn('git', ['push', '-f', 'origin', | ||
...tags.map(t => `refs/tags/${t}:refs/tags/${t}`), | ||
]) | ||
} | ||
|
||
return tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { gitConfig } from '../../src/util/gitConfig' | ||
|
||
let spawnMock: (...a: unknown[]) => Promise<string> | ||
jest.mock('../../src/util/spawn', () => ({ | ||
spawn: (...a: unknown[]) => spawnMock(...a), | ||
})) | ||
|
||
test('set github actor', async () => { | ||
spawnMock = jest.fn() | ||
|
||
await gitConfig({GITHUB_ACTOR: 'foo'}) | ||
|
||
expect(spawnMock).toHaveBeenNthCalledWith(1, 'git', ['config', '--global', 'user.name', 'foo']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(2, 'git', ['config', '--global', 'user.email', '[email protected]']) | ||
expect(spawnMock).toHaveBeenCalledTimes(2) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { updateTags } from '../../src/util/updateTags' | ||
|
||
let spawnMock: (...a: unknown[]) => Promise<string> | ||
jest.mock('../../src/util/spawn', () => ({ | ||
spawn: (...a: unknown[]) => spawnMock(...a), | ||
})) | ||
|
||
test('set tags', async () => { | ||
spawnMock = jest.fn() | ||
|
||
await updateTags('abc', '1.2.3', {major: '1', minor: '2', patch: '3', revision: undefined, revisionType: undefined}, 'version') | ||
|
||
expect(spawnMock).toHaveBeenNthCalledWith(1, 'git', ['ls-remote', 'origin', 'refs/tags/version1.3.0']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(2, 'git', ['tag', '-fam', '1.2.3', 'version1.2', 'abc']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(3, 'git', ['tag', '-fam', '1.2.3', 'version1', 'abc']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(4, 'git', ['push', '-f', 'origin', 'refs/tags/version1.2:refs/tags/version1.2', 'refs/tags/version1:refs/tags/version1']) | ||
expect(spawnMock).toHaveBeenCalledTimes(4) | ||
}) | ||
|
||
test('omit major on maintenance release', async () => { | ||
spawnMock = jest.fn().mockReturnValueOnce(Promise.resolve('abcdef\trefs/tags/v1.3.0')) | ||
|
||
await updateTags('abc', '1.2.3', {major: '1', minor: '2', patch: '3', revision: undefined, revisionType: undefined}, 'v') | ||
|
||
expect(spawnMock).toHaveBeenNthCalledWith(1, 'git', ['ls-remote', 'origin', 'refs/tags/v1.3.0']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(2, 'git', ['tag', '-fam', '1.2.3', 'v1.2', 'abc']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(3, 'git', ['push', '-f', 'origin', 'refs/tags/v1.2:refs/tags/v1.2']) | ||
expect(spawnMock).toHaveBeenCalledTimes(3) | ||
}) | ||
|
||
test('set tag for prerelease', async () => { | ||
spawnMock = jest.fn().mockReturnValueOnce(Promise.resolve('abcdef\trefs/tags/v1.3.0')) | ||
|
||
await updateTags('abc', '1.2.3-foo.1', {major: '1', minor: '2', patch: '3', revision: 'foo.1', revisionType: 'foo'}, 'v') | ||
|
||
expect(spawnMock).toHaveBeenNthCalledWith(1, 'git', ['tag', '-fam', '1.2.3-foo.1', 'v1.2.3-foo', 'abc']) | ||
expect(spawnMock).toHaveBeenNthCalledWith(2, 'git', ['push', '-f', 'origin', 'refs/tags/v1.2.3-foo:refs/tags/v1.2.3-foo']) | ||
expect(spawnMock).toHaveBeenCalledTimes(2) | ||
}) | ||
|
||
|