Skip to content

Commit

Permalink
Merge pull request #124 from git-for-windows/fix-snapshot-uploading-o…
Browse files Browse the repository at this point in the history
…f-full-releases

Fix the snapshot uploading of official Git for Windows versions
  • Loading branch information
dscho authored Feb 14, 2025
2 parents adc1a0e + c2b466e commit 35cd252
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 5 additions & 4 deletions GitForWindowsHelper/cascading-runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ const cascadingRuns = async (context, req) => {

// Next, check that the commit is on the `main` branch
const gitToken = await getToken(context, checkRunOwner, checkRunRepo)
const { behind_by } = await githubApiRequest(
const { ahead_by, behind_by } = await githubApiRequest(
context,
gitToken,
'GET',
`/repos/${checkRunOwner}/${checkRunRepo}/compare/HEAD...${commit}`,
// `/repos/dscho/git/compare/HEAD...${commit}`,
)
if (behind_by > 0) {
return `Ignoring ${name} check-run because its corresponding commit ${commit} is not on the main branch`
if (ahead_by > 0) {
return `Ignoring ${name} check-run because its corresponding commit ${commit} is not on the main branch (ahead by ${ahead_by}, behind by ${behind_by})`
}

const workFlowRunIDs = {}
Expand Down Expand Up @@ -245,7 +246,7 @@ const cascadingRuns = async (context, req) => {
}
)

return `The 'upload-snapshot' workflow run was started at ${answer.html_url}`
return `The 'upload-snapshot' workflow run was started at ${answer.html_url} (ahead by ${ahead_by}, behind by ${behind_by})`
}
return `Not a cascading run: ${name}; Doing nothing.`
}
Expand Down
17 changes: 16 additions & 1 deletion GitForWindowsHelper/finalize-g4w-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,20 @@ module.exports = async (context, req) => {
force: false // require fast-forward
})

return `Took care of pushing the \`main\` branch to close PR ${prNumber}`
// trigger "upload artifacts" workflow
const { handlePush } = require('./cascading-runs')
const uploadSnapshotAnswer = await handlePush(context, {
body: {
repository: {
owner: {
login: owner,
},
name: repo,
},
ref: 'refs/heads/main',
after: sha,
}
})

return `Took care of pushing the \`main\` branch to close PR ${prNumber}\n${uploadSnapshotAnswer}`
}
11 changes: 7 additions & 4 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ The \`git-artifacts-aarch64\` workflow run [was started](dispatched-workflow-git
}
if (method === 'GET' && requestPath ===
'/repos/git-for-windows/git/compare/HEAD...0c796d3013a57e8cc894c152f0200107226e5dd1') {
return { behind_by: 0 }
return { ahead_by: 0, behind_by: 99 }
}
throw new Error(`Unhandled ${method}-${requestPath}-${JSON.stringify(payload)}`)
})
Expand Down Expand Up @@ -943,11 +943,14 @@ test('a completed `release-git` run updates the `main` branch in git-for-windows
try {
expect(await index(context, context.req)).toBeUndefined()
expect(context.res).toEqual({
body: `Took care of pushing the \`main\` branch to close PR 765`,
body: [
'Took care of pushing the `main` branch to close PR 765',
`The 'tag-git' workflow run was started at dispatched-workflow-tag-git.yml`,
].join('\n'),
headers: undefined,
status: undefined
})
expect(mockGitHubApiRequest).toHaveBeenCalledTimes(4)
expect(mockGitHubApiRequest).toHaveBeenCalledTimes(7)
expect(mockGitHubApiRequest.mock.calls[3].slice(1)).toEqual([
'installation-access-token',
'PATCH',
Expand Down Expand Up @@ -994,7 +997,7 @@ test('the third completed `git-artifacts-<arch>` check-run triggers an `upload-s
try {
expect(await index(context, context.req)).toBeUndefined()
expect(context.res).toEqual({
body: `The 'upload-snapshot' workflow run was started at dispatched-workflow-upload-snapshot.yml`,
body: `The 'upload-snapshot' workflow run was started at dispatched-workflow-upload-snapshot.yml (ahead by 0, behind by 99)`,
headers: undefined,
status: undefined
})
Expand Down

0 comments on commit 35cd252

Please sign in to comment.