Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
refactor: improve test coverage and checkout command
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Negin-Ulster committed Mar 9, 2023
1 parent e6965ce commit 20c7344
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
17 changes: 14 additions & 3 deletions e2e-tests/tests/issues/issue-601.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ describe('Issue #601', () => {
if (error2) console.error(error2)
expect(error2).toBeUndefined()

// At this point we expected change 2 followed by change 1 in the changelog
let remoteChangelog = (
await exec('git cat-file blob origin/main:packages/pkg-1/CHANGELOG.md')
).stdout
expect(remoteChangelog).toMatch(/change 2.*change 1/s)

// Switch back to change_3 which is now "out of sync" with main
await exec('git checkout main')
await exec('git reset --hard change_3')

// If we attempt to publish, we'll have a conflict with the CHANGELOG.md file
// since our change_3 will only have change 1 and change 3 and will be missing change 2.
// We'll validate this:
let remoteChangelog = (
remoteChangelog = (
await exec('git cat-file blob origin/main:packages/pkg-1/CHANGELOG.md')
).stdout
expect(remoteChangelog).toEqual(expect.stringContaining('change 1'))
Expand All @@ -85,9 +91,14 @@ describe('Issue #601', () => {
remoteChangelog = (
await exec('git cat-file blob origin/main:packages/pkg-1/CHANGELOG.md')
).stdout
expect(remoteChangelog).toEqual(
expect.stringMatching('change 1.*change 2.*change 3'),
expect(remoteChangelog).toMatch(/change 3.*change 2.*change 1/s)
expect((await (await exec('git describe --abbrev=0')).stdout).trim()).toBe(
'pkg-1@0.3.0',
)

// NOTE: the hard reset we do disassociates the git tag with the HEAD of main.
// This causes the change_3 monodeploy run to include changes 2 and 3. This is
// just a quirk of the test scenario.
},
}),
)
Expand Down
4 changes: 3 additions & 1 deletion packages/changelog/src/prependChangelogFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const prependChangelogFile = async ({
try {
await gitCheckout({ files: [changelogGlob] }, { cwd: config.cwd, context })
} catch {
logging.debug('Force refreshing changelogs failed.', { report: context.report })
logging.debug('Force refreshing changelogs failed. Ignoring.', {
report: context.report,
})
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/git/src/gitCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export const gitCheckout = async (
{ files }: { files: string[] },
{ cwd, context }: { cwd: string; context?: YarnContext },
): Promise<void> => {
const { stdout: branch } = await git('rev-parse --abbrev-ref --symbolic-full-name @{u}', {
const { stdout: branch } = await git('rev-parse --abbrev-ref --symbolic-full-name @\\{u\\}', {
cwd,
context,
})
await git(`checkout ${branch.trim()} -- ${files.map((f) => `"${f}"`).join(' ')}`, {
cwd,
context,
})
await git(`checkout ${branch.trim()} -- ${files.join(' ')}`, { cwd, context })
}

export const gitResolveSha = async (
Expand Down
18 changes: 9 additions & 9 deletions packages/publish/src/commitPublishChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ export const createPublishCommit = async ({
}
}

if (config.git.tag && gitTags?.size) {
// Tag commit
await createReleaseGitTags({
config,
context,
gitTags,
})
}

if (config.git.push && config.autoCommit) {
await gitPull({
cwd: config.cwd,
Expand All @@ -66,6 +57,15 @@ export const createPublishCommit = async ({
})
}

if (config.git.tag && gitTags?.size) {
// Tag commit
await createReleaseGitTags({
config,
context,
gitTags,
})
}

return { headSha: await gitResolveSha('HEAD', { cwd: config.cwd, context }) }
}

Expand Down

0 comments on commit 20c7344

Please sign in to comment.