Skip to content

Commit fb12b50

Browse files
authored
Merge pull request #128 from git-for-windows/fix-upload-snapshot-on-push
Fix `upload-snapshot` on `push`
2 parents 0415ab4 + 69d272c commit fb12b50

File tree

4 files changed

+29
-33
lines changed

4 files changed

+29
-33
lines changed

GitForWindowsHelper/cascading-runs.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ const handlePush = async (context, req) => {
339339
`The 'tag-git' run at ${latest.html_url} did not succeed (conclusion = ${latest.conclusion}).`
340340
)
341341

342+
const match = latest.output.summary.match(/^Tag Git (\S+) @([0-9a-f]+)$/)
343+
if (!match) throw new Error(`Unexpected summary '${latest.output.summary}' of tag-git run: ${latest.html_url}`)
344+
if (!match[2] === commit) throw new Error(`Unexpected revision ${match[2]} '${latest.output.summary}' of tag-git run: ${latest.html_url}`)
345+
const ver = match[1]
346+
347+
const match2 = latest.output.text.match(/^For details, see \[this run\]\(https:\/\/github.com\/([^/]+)\/([^/]+)\/actions\/runs\/(\d+)\)/)
348+
if (!match2) throw new Error(`Unexpected summary '${latest.output.summary}' of tag-git run: ${latest.html_url}`)
349+
const [, , , tagGitWorkflowRunId] = match2
350+
342351
// There is already a `tag-git` workflow run; Is there already an `upload-snapshot` run?
343352
const latestUploadSnapshotRun = (await listCheckRunsForCommit(
344353
context,
@@ -354,20 +363,15 @@ const handlePush = async (context, req) => {
354363
const tagGitCheckRunTitle = `Upload snapshot Git @${commit}`
355364
const tagGitCheckRunId = await queueCheckRun(
356365
context,
357-
await getToken(),
366+
await getToken(context, pushOwner, pushRepo),
358367
pushOwner,
359368
pushRepo,
360369
commit,
361-
'tag-git',
370+
'upload-snapshot',
362371
tagGitCheckRunTitle,
363372
tagGitCheckRunTitle
364373
)
365374

366-
const match = latest.output.summary.match(/^Tag Git (\S+) @([0-9a-f]+)$/)
367-
if (!match) throw new Error(`Unexpected summary '${latest.output.summary}' of tag-git run: ${latest.html_url}`)
368-
if (!match[2] === commit) throw new Error(`Unexpected revision ${match[2]} '${latest.output.summary}' of tag-git run: ${latest.html_url}`)
369-
const ver = match[1]
370-
371375
try {
372376
const workFlowRunIDs = {}
373377
for (const architecture of ['x86_64', 'i686', 'aarch64']) {
@@ -381,7 +385,7 @@ const handlePush = async (context, req) => {
381385
workflowName
382386
)
383387
const needle =
384-
`Build Git ${ver} artifacts from commit ${commit} (tag-git run #${latest.id})`
388+
`Build Git ${ver} artifacts from commit ${commit} (tag-git run #${tagGitWorkflowRunId})`
385389
const latest2 = runs
386390
.filter(run => run.output.summary === needle)
387391
.sort((a, b) => a.id - b.id)
@@ -409,7 +413,7 @@ const handlePush = async (context, req) => {
409413
const answer = await triggerWorkflowDispatch(
410414
context,
411415
gitForWindowsAutomationToken,
412-
pushRepo,
416+
pushOwner,
413417
'git-for-windows-automation',
414418
'upload-snapshot.yml',
415419
'main', {

GitForWindowsHelper/check-runs.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const queueCheckRun = async (context, token, owner, repo, ref, checkRunName, title, summary) => {
2+
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
3+
throw new Error(`Would have queued Check Run ${checkRunName} in ${owner}/${repo} with ref ${ref}`)
4+
}
25
const githubApiRequest = require('./github-api-request')
36
// is there an existing check-run we can re-use?
47
const { check_runs } = await githubApiRequest(
@@ -47,6 +50,9 @@ const queueCheckRun = async (context, token, owner, repo, ref, checkRunName, tit
4750
}
4851

4952
const updateCheckRun = async (context, token, owner, repo, checkRunId, parameters) => {
53+
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
54+
throw new Error(`Would have updated Check Run ${checkRunId} in ${owner}/${repo} with parameters ${JSON.stringify(parameters)}`)
55+
}
5056
const githubApiRequest = require('./github-api-request')
5157

5258
await githubApiRequest(
@@ -59,6 +65,9 @@ const updateCheckRun = async (context, token, owner, repo, checkRunId, parameter
5965
}
6066

6167
const cancelWorkflowRun = async (context, token, owner, repo, workflowRunId) => {
68+
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
69+
throw new Error(`Would have canceled workflow run ${workflowRunId} in ${owner}/${repo}`)
70+
}
6271
const githubApiRequest = require('./github-api-request')
6372

6473
const answer = await githubApiRequest(

GitForWindowsHelper/finalize-g4w-release.js

+2-17
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,5 @@ module.exports = async (context, req) => {
5858
force: false // require fast-forward
5959
})
6060

61-
// trigger "upload artifacts" workflow
62-
const { handlePush } = require('./cascading-runs')
63-
const uploadSnapshotAnswer = await handlePush(context, {
64-
body: {
65-
repository: {
66-
owner: {
67-
login: owner,
68-
},
69-
name: repo,
70-
},
71-
ref: 'refs/heads/main',
72-
after: sha,
73-
}
74-
})
75-
76-
return `Took care of pushing the \`main\` branch to close PR ${prNumber}\n${uploadSnapshotAnswer}`
77-
}
61+
return `Took care of pushing the \`main\` branch to close PR ${prNumber}`
62+
}

__tests__/index.test.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,10 @@ let mockListCheckRunsForCommit = jest.fn((_context, _token, _owner, _repo, rev,
465465
conclusion: 'success',
466466
status: 'completed',
467467
output: {
468-
summary: 'Tag Git already-tagged @88811'
468+
summary: 'Tag Git already-tagged @88811',
469+
text: 'For details, see [this run](https://github.com/x/y/actions/runs/123).\nTagged already-tagged\nDone!.'
469470
},
470-
id: 123
471+
id: 123456789
471472
}]
472473
if (checkRunName.startsWith('git-artifacts')) {
473474
const id = {
@@ -943,14 +944,11 @@ test('a completed `release-git` run updates the `main` branch in git-for-windows
943944
try {
944945
expect(await index(context, context.req)).toBeUndefined()
945946
expect(context.res).toEqual({
946-
body: [
947-
'Took care of pushing the `main` branch to close PR 765',
948-
`The 'tag-git' workflow run was started at dispatched-workflow-tag-git.yml`,
949-
].join('\n'),
947+
body: `Took care of pushing the \`main\` branch to close PR 765`,
950948
headers: undefined,
951949
status: undefined
952950
})
953-
expect(mockGitHubApiRequest).toHaveBeenCalledTimes(7)
951+
expect(mockGitHubApiRequest).toHaveBeenCalledTimes(4)
954952
expect(mockGitHubApiRequest.mock.calls[3].slice(1)).toEqual([
955953
'installation-access-token',
956954
'PATCH',

0 commit comments

Comments
 (0)