diff --git a/src/autoupdater.ts b/src/autoupdater.ts index c42ac42..773f125 100644 --- a/src/autoupdater.ts +++ b/src/autoupdater.ts @@ -438,6 +438,55 @@ export class AutoUpdater { ghCore.info( `Branch update successful, new branch HEAD: ${mergeResp.data.sha}.`, ); + + const { data: currentCommit } = await this.octokit.rest.repos.getCommit( + { + owner: mergeOpts.owner, + repo: mergeOpts.repo, + ref: mergeOpts.base as string, + }, + ); + + const blob = await this.octokit.rest.git.createBlob({ + owner: mergeOpts.owner, + repo: mergeOpts.repo, + content: Date.now().toString(), + encoding: 'utf-8', + }); + + const tree = await this.octokit.rest.git.createTree({ + owner: mergeOpts.owner, + repo: mergeOpts.repo, + base_tree: currentCommit.commit.tree.sha, + tree: [ + { + path: 'README.md', + mode: '100644', + type: 'blob', + sha: blob.data.sha, + }, + ], + }); + + const emptyCommit = await this.octokit.rest.git.createCommit({ + owner: mergeOpts.owner, + repo: mergeOpts.repo, + message: 'chore: trigger workflows', + tree: tree.data.sha, + parents: [currentCommit.sha], + }); + + await this.octokit.rest.git.updateRef({ + owner: mergeOpts.owner, + repo: mergeOpts.repo, + ref: `heads/${mergeOpts.base}`, + sha: emptyCommit.data.sha, + force: false, + }); + + ghCore.info( + `Empty commit created to trigger workflows: ${emptyCommit.data.sha}`, + ); } else if (status === 204) { ghCore.info( 'Branch update not required, branch is already up-to-date.', diff --git a/test/autoupdate.test.ts b/test/autoupdate.test.ts index ba04988..a0776a5 100644 --- a/test/autoupdate.test.ts +++ b/test/autoupdate.test.ts @@ -1116,7 +1116,20 @@ describe('test `merge`', () => { const setOutput = jest.fn(); - if (responseTest.success) { + if ( + responseTest.success && + (responseTest.code === 200 || responseTest.code === 201) + ) { + // Add mock for updateRef (force update to same SHA) + const updateRefScope = nock('https://api.github.com:443') + .patch(`/repos/${owner}/${repo}/git/refs/heads/${mergeOpts.base}`, { + sha: 'dummy-sha', + force: true, + }) + .reply(200, {}); + await updater.merge(owner, 1, mergeOpts, setOutput); + expect(updateRefScope.isDone()).toEqual(true); + } else if (responseTest.success) { await updater.merge(owner, 1, mergeOpts, setOutput); } else { await expect( @@ -1309,6 +1322,7 @@ describe('test `merge`', () => { .reply(200, pullsMock); const mergeScopes: any[] = []; + const updateRefScopes: nock.Scope[] = []; for (let i = 0; i < expectedPulls; i++) { let httpStatus = 200; let response: Record = { @@ -1331,6 +1345,16 @@ describe('test `merge`', () => { .post(`/repos/${owner}/${repo}/merges`) .reply(httpStatus, response), ); + if (httpStatus === 200) { + updateRefScopes.push( + nock('https://api.github.com:443') + .patch(`/repos/${owner}/${repo}/git/refs/heads/${base}`, { + sha: 'dummy-sha', + force: true, + }) + .reply(200, {}), + ); + } } const updated = await updater.handlePush(); @@ -1342,6 +1366,9 @@ describe('test `merge`', () => { for (const scope of mergeScopes) { expect(scope.isDone()).toBe(true); } + for (const scope of updateRefScopes) { + expect(scope.isDone()).toBe(true); + } }); test('merge conflict label is configured and merge conflict label is already present', async () => {