diff --git a/GitForWindowsHelper/cascading-runs.js b/GitForWindowsHelper/cascading-runs.js index 35118b1..8c0f311 100644 --- a/GitForWindowsHelper/cascading-runs.js +++ b/GitForWindowsHelper/cascading-runs.js @@ -339,6 +339,15 @@ const handlePush = async (context, req) => { `The 'tag-git' run at ${latest.html_url} did not succeed (conclusion = ${latest.conclusion}).` ) + const match = latest.output.summary.match(/^Tag Git (\S+) @([0-9a-f]+)$/) + if (!match) throw new Error(`Unexpected summary '${latest.output.summary}' of tag-git run: ${latest.html_url}`) + if (!match[2] === commit) throw new Error(`Unexpected revision ${match[2]} '${latest.output.summary}' of tag-git run: ${latest.html_url}`) + const ver = match[1] + + const match2 = latest.output.text.match(/^For details, see \[this run\]\(https:\/\/github.com\/([^/]+)\/([^/]+)\/actions\/runs\/(\d+)\)/) + if (!match2) throw new Error(`Unexpected summary '${latest.output.summary}' of tag-git run: ${latest.html_url}`) + const [, , , tagGitWorkflowRunId] = match2 + // There is already a `tag-git` workflow run; Is there already an `upload-snapshot` run? const latestUploadSnapshotRun = (await listCheckRunsForCommit( context, @@ -354,20 +363,15 @@ const handlePush = async (context, req) => { const tagGitCheckRunTitle = `Upload snapshot Git @${commit}` const tagGitCheckRunId = await queueCheckRun( context, - await getToken(), + await getToken(context, pushOwner, pushRepo), pushOwner, pushRepo, commit, - 'tag-git', + 'upload-snapshot', tagGitCheckRunTitle, tagGitCheckRunTitle ) - const match = latest.output.summary.match(/^Tag Git (\S+) @([0-9a-f]+)$/) - if (!match) throw new Error(`Unexpected summary '${latest.output.summary}' of tag-git run: ${latest.html_url}`) - if (!match[2] === commit) throw new Error(`Unexpected revision ${match[2]} '${latest.output.summary}' of tag-git run: ${latest.html_url}`) - const ver = match[1] - try { const workFlowRunIDs = {} for (const architecture of ['x86_64', 'i686', 'aarch64']) { @@ -381,7 +385,7 @@ const handlePush = async (context, req) => { workflowName ) const needle = - `Build Git ${ver} artifacts from commit ${commit} (tag-git run #${latest.id})` + `Build Git ${ver} artifacts from commit ${commit} (tag-git run #${tagGitWorkflowRunId})` const latest2 = runs .filter(run => run.output.summary === needle) .sort((a, b) => a.id - b.id) @@ -409,7 +413,7 @@ const handlePush = async (context, req) => { const answer = await triggerWorkflowDispatch( context, gitForWindowsAutomationToken, - pushRepo, + pushOwner, 'git-for-windows-automation', 'upload-snapshot.yml', 'main', { diff --git a/GitForWindowsHelper/check-runs.js b/GitForWindowsHelper/check-runs.js index be1fd21..5909c9f 100644 --- a/GitForWindowsHelper/check-runs.js +++ b/GitForWindowsHelper/check-runs.js @@ -1,4 +1,7 @@ const queueCheckRun = async (context, token, owner, repo, ref, checkRunName, title, summary) => { + if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) { + throw new Error(`Would have queued Check Run ${checkRunName} in ${owner}/${repo} with ref ${ref}`) + } const githubApiRequest = require('./github-api-request') // is there an existing check-run we can re-use? const { check_runs } = await githubApiRequest( @@ -47,6 +50,9 @@ const queueCheckRun = async (context, token, owner, repo, ref, checkRunName, tit } const updateCheckRun = async (context, token, owner, repo, checkRunId, parameters) => { + if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) { + throw new Error(`Would have updated Check Run ${checkRunId} in ${owner}/${repo} with parameters ${JSON.stringify(parameters)}`) + } const githubApiRequest = require('./github-api-request') await githubApiRequest( @@ -59,6 +65,9 @@ const updateCheckRun = async (context, token, owner, repo, checkRunId, parameter } const cancelWorkflowRun = async (context, token, owner, repo, workflowRunId) => { + if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) { + throw new Error(`Would have canceled workflow run ${workflowRunId} in ${owner}/${repo}`) + } const githubApiRequest = require('./github-api-request') const answer = await githubApiRequest( diff --git a/GitForWindowsHelper/finalize-g4w-release.js b/GitForWindowsHelper/finalize-g4w-release.js index 354a7b5..d2442aa 100644 --- a/GitForWindowsHelper/finalize-g4w-release.js +++ b/GitForWindowsHelper/finalize-g4w-release.js @@ -58,20 +58,5 @@ module.exports = async (context, req) => { force: false // require fast-forward }) - // 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}` -} \ No newline at end of file + return `Took care of pushing the \`main\` branch to close PR ${prNumber}` +} diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 07f7b39..8a98096 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -465,9 +465,10 @@ let mockListCheckRunsForCommit = jest.fn((_context, _token, _owner, _repo, rev, conclusion: 'success', status: 'completed', output: { - summary: 'Tag Git already-tagged @88811' + summary: 'Tag Git already-tagged @88811', + text: 'For details, see [this run](https://github.com/x/y/actions/runs/123).\nTagged already-tagged\nDone!.' }, - id: 123 + id: 123456789 }] if (checkRunName.startsWith('git-artifacts')) { const id = { @@ -943,14 +944,11 @@ 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', - `The 'tag-git' workflow run was started at dispatched-workflow-tag-git.yml`, - ].join('\n'), + body: `Took care of pushing the \`main\` branch to close PR 765`, headers: undefined, status: undefined }) - expect(mockGitHubApiRequest).toHaveBeenCalledTimes(7) + expect(mockGitHubApiRequest).toHaveBeenCalledTimes(4) expect(mockGitHubApiRequest.mock.calls[3].slice(1)).toEqual([ 'installation-access-token', 'PATCH',