Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions GitForWindowsHelper/cascading-runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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']) {
Expand All @@ -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)
Expand Down Expand Up @@ -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', {
Expand Down
9 changes: 9 additions & 0 deletions GitForWindowsHelper/check-runs.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
19 changes: 2 additions & 17 deletions GitForWindowsHelper/finalize-g4w-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
return `Took care of pushing the \`main\` branch to close PR ${prNumber}`
}
12 changes: 5 additions & 7 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
Expand Down