11import path from "node:path" ;
22import * as core from "@actions/core" ;
3+ import * as github from "@actions/github" ;
34import type { Changeset } from "@changesets/types" ;
45import { writeChangeset } from "@changesets/write" ;
5- import { createFixture } from "fs-fixture" ;
66import { exec } from "tinyexec" ;
77import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
88import { GitHub } from "./github.ts" ;
99import { runPublish , runVersion } from "./run.ts" ;
10+ import { gitdir } from "./test-utils.ts" ;
1011
1112vi . mock ( "@actions/github" , ( ) => ( {
1213 context : {
@@ -44,7 +45,7 @@ let mockedGraphql = vi.fn();
4445const nodeModulesDir = path . join ( import . meta. dirname , ".." , "node_modules" ) ;
4546
4647function createSimpleProjectFixture ( ) {
47- return createFixture ( {
48+ return gitdir ( {
4849 node_modules : ( api ) => api . symlink ( nodeModulesDir ) ,
4950 ".changeset/config.json" : JSON . stringify ( { } ) ,
5051 "packages/pkg-a/package.json" : JSON . stringify ( {
@@ -69,7 +70,7 @@ function createSimpleProjectFixture() {
6970}
7071
7172function createIgnoredPackageFixture ( ) {
72- return createFixture ( {
73+ return gitdir ( {
7374 node_modules : ( api ) => api . symlink ( nodeModulesDir ) ,
7475 ".changeset/config.json" : JSON . stringify ( {
7576 ignore : [ "changesets-dev-ignored-package-pkg-a" ] ,
@@ -106,15 +107,20 @@ const createGithub = (cwd: string) =>
106107 pushWithGitCli : false ,
107108 } ) ;
108109
109- async function initializeGitRepository ( cwd : string ) {
110- await exec ( "git" , [ "init " ] , {
110+ async function updateGithubContext ( cwd : string ) {
111+ const head = await exec ( "git" , [ "rev-parse" , "HEAD "] , {
111112 nodeOptions : { cwd } ,
112- throwOnError : true ,
113113 } ) ;
114+ github . context . sha = head . stdout . trim ( ) ;
115+ }
116+
117+ function resetGithubContext ( ) {
118+ github . context . sha = "xeac7" ;
114119}
115120
116121beforeEach ( ( ) => {
117122 vi . clearAllMocks ( ) ;
123+ resetGithubContext ( ) ;
118124} ) ;
119125
120126afterEach ( ( ) => {
@@ -125,7 +131,7 @@ describe("publish", () => {
125131 it ( "warns when a custom publish script does not create the output file" , async ( ) => {
126132 await using fixture = await createSimpleProjectFixture ( ) ;
127133 const cwd = fixture . path ;
128- await initializeGitRepository ( cwd ) ;
134+ await updateGithubContext ( cwd ) ;
129135 vi . stubEnv ( "RUNNER_TEMP" , cwd ) ;
130136
131137 const result = await runPublish ( {
@@ -145,7 +151,7 @@ describe("publish", () => {
145151 } ) ;
146152
147153 it ( "throws when the built-in publish command does not create the output file" , async ( ) => {
148- await using fixture = await createFixture ( {
154+ await using fixture = await gitdir ( {
149155 "node_modules/@changesets/cli/package.json" : JSON . stringify ( {
150156 name : "@changesets/cli" ,
151157 type : "module" ,
@@ -158,7 +164,7 @@ describe("publish", () => {
158164 "package-lock.json" : "" ,
159165 } ) ;
160166 const cwd = fixture . path ;
161- await initializeGitRepository ( cwd ) ;
167+ await updateGithubContext ( cwd ) ;
162168 vi . stubEnv ( "RUNNER_TEMP" , cwd ) ;
163169
164170 await expect (
@@ -176,6 +182,7 @@ describe("version", () => {
176182 it ( "creates simple PR" , async ( ) => {
177183 await using fixture = await createSimpleProjectFixture ( ) ;
178184 const cwd = fixture . path ;
185+ await updateGithubContext ( cwd ) ;
179186
180187 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( { data : [ ] } ) ) ;
181188
@@ -213,6 +220,7 @@ describe("version", () => {
213220 it ( 'creates a draft PR when prDraft is "create"' , async ( ) => {
214221 await using fixture = await createSimpleProjectFixture ( ) ;
215222 const cwd = fixture . path ;
223+ await updateGithubContext ( cwd ) ;
216224
217225 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( { data : [ ] } ) ) ;
218226
@@ -247,6 +255,7 @@ describe("version", () => {
247255 it ( "only includes bumped packages in the PR body" , async ( ) => {
248256 await using fixture = await createSimpleProjectFixture ( ) ;
249257 const cwd = fixture . path ;
258+ await updateGithubContext ( cwd ) ;
250259
251260 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( { data : [ ] } ) ) ;
252261
@@ -280,6 +289,7 @@ describe("version", () => {
280289 it ( "doesn't include ignored package that got a dependency update in the PR body" , async ( ) => {
281290 await using fixture = await createIgnoredPackageFixture ( ) ;
282291 const cwd = fixture . path ;
292+ await updateGithubContext ( cwd ) ;
283293
284294 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( { data : [ ] } ) ) ;
285295
@@ -313,6 +323,7 @@ describe("version", () => {
313323 it ( "does not include changelog entries if full message exceeds size limit" , async ( ) => {
314324 await using fixture = await createSimpleProjectFixture ( ) ;
315325 const cwd = fixture . path ;
326+ await updateGithubContext ( cwd ) ;
316327
317328 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( { data : [ ] } ) ) ;
318329
@@ -370,6 +381,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
370381 it ( "does not include any release information if a message with simplified release info exceeds size limit" , async ( ) => {
371382 await using fixture = await createSimpleProjectFixture ( ) ;
372383 const cwd = fixture . path ;
384+ await updateGithubContext ( cwd ) ;
373385
374386 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( { data : [ ] } ) ) ;
375387
@@ -427,6 +439,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
427439 it ( 'updates an existing PR via GraphQL without converting it to draft when prDraft is "create"' , async ( ) => {
428440 await using fixture = await createSimpleProjectFixture ( ) ;
429441 const cwd = fixture . path ;
442+ await updateGithubContext ( cwd ) ;
430443
431444 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( {
432445 data : [ { number : 123 , node_id : "PR_kwDOA" } ] ,
@@ -459,6 +472,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
459472 it ( 'updates an existing PR via GraphQL and converts it to draft when prDraft is "always"' , async ( ) => {
460473 await using fixture = await createSimpleProjectFixture ( ) ;
461474 const cwd = fixture . path ;
475+ await updateGithubContext ( cwd ) ;
462476
463477 mockedGithubMethods . pulls . list . mockImplementationOnce ( ( ) => ( {
464478 data : [ { number : 123 , node_id : "PR_kwDOA" } ] ,
0 commit comments