-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tweak-auto-release
- Loading branch information
Showing
16 changed files
with
289 additions
and
113 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 |
---|---|---|
@@ -1,12 +1,49 @@ | ||
import { execaCommand } from 'execa'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { getSlug } from './git'; | ||
import { getCommit, getSlug, hasPreviousCommit } from './git'; | ||
|
||
vi.mock('execa'); | ||
|
||
const command = vi.mocked(execaCommand); | ||
|
||
describe('getCommit', () => { | ||
it('parses log output', async () => { | ||
command.mockImplementation( | ||
() => | ||
Promise.resolve({ | ||
all: `19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a ## 1696588814 ## [email protected] ## Gert Hengeveld`, | ||
}) as any | ||
); | ||
expect(await getCommit()).toEqual({ | ||
commit: '19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a', | ||
committedAt: 1696588814 * 1000, | ||
committerEmail: '[email protected]', | ||
committerName: 'Gert Hengeveld', | ||
}); | ||
}); | ||
|
||
it('ignores gpg signature information', async () => { | ||
command.mockImplementation( | ||
() => | ||
Promise.resolve({ | ||
all: ` | ||
gpg: Signature made Fri Oct 6 12:40:14 2023 CEST | ||
gpg: using RSA key 4AEE18F83AFDEB23 | ||
gpg: Can't check signature: No public key | ||
19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a ## 1696588814 ## [email protected] ## Gert Hengeveld | ||
`.trim(), | ||
}) as any | ||
); | ||
expect(await getCommit()).toEqual({ | ||
commit: '19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a', | ||
committedAt: 1696588814 * 1000, | ||
committerEmail: '[email protected]', | ||
committerName: 'Gert Hengeveld', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getSlug', () => { | ||
it('returns the slug portion of the git url', async () => { | ||
command.mockImplementation( | ||
|
@@ -25,3 +62,32 @@ describe('getSlug', () => { | |
expect(await getSlug()).toBe('foo/bar.baz'); | ||
}); | ||
}); | ||
|
||
describe('hasPreviousCommit', () => { | ||
it('returns true if a commit is found', async () => { | ||
command.mockImplementation( | ||
() => Promise.resolve({ all: `19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a` }) as any | ||
); | ||
expect(await hasPreviousCommit()).toEqual(true); | ||
}); | ||
|
||
it('returns false if no commit is found', async () => { | ||
command.mockImplementation(() => Promise.resolve({ all: `` }) as any); | ||
expect(await hasPreviousCommit()).toEqual(false); | ||
}); | ||
|
||
it('ignores gpg signature information', async () => { | ||
command.mockImplementation( | ||
() => | ||
Promise.resolve({ | ||
all: ` | ||
gpg: Signature made Fri Oct 6 12:40:14 2023 CEST | ||
gpg: using RSA key 4AEE18F83AFDEB23 | ||
gpg: Can't check signature: No public key | ||
19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a | ||
`.trim(), | ||
}) as any | ||
); | ||
expect(await hasPreviousCommit()).toEqual(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import { parseNr, getCliCommand, parseNa } from '@antfu/ni'; | ||
import { execa } from 'execa'; | ||
|
||
// 'npm' | 'pnpm' | 'yarn' | 'bun' | ||
export const getPackageManagerName = async () => { | ||
return getCliCommand(parseNa, [], { programmatic: true }) as any; | ||
return getCliCommand(parseNa, [], { programmatic: true }); | ||
}; | ||
|
||
// e.g. `npm run build-storybook` | ||
export const getPackageManagerRunCommand = async (args: string[]) => { | ||
return getCliCommand(parseNr, args, { programmatic: true }); | ||
}; | ||
|
||
// e.g. `8.19.2` | ||
export const getPackageManagerVersion = async (packageManager: string) => { | ||
const { stdout } = await execa(packageManager || (await getPackageManagerName()), ['--version']); | ||
const [output] = (stdout.toString() as string).trim().split('\n', 1); | ||
return output.trim().replace(/^v/, ''); | ||
}; |
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
Oops, something went wrong.