From fa0950476f656aad5aad4682367408d784c43506 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Fri, 13 Aug 2021 11:34:19 +0900 Subject: [PATCH] test: add test for detached head failure mode --- __test__/create-or-update-branch.int.test.ts | 22 ++++++++++++++++++++ __test__/integration-tests.sh | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/__test__/create-or-update-branch.int.test.ts b/__test__/create-or-update-branch.int.test.ts index 523bbe9..ef8ac68 100644 --- a/__test__/create-or-update-branch.int.test.ts +++ b/__test__/create-or-update-branch.int.test.ts @@ -1740,4 +1740,26 @@ describe('create-or-update-branch tests', () => { ]) ).toBeTruthy() }) + + // This failure mode is a limitation of the action. Controlling your own commits cannot be used in detached HEAD state. + // https://github.com/peter-evans/create-pull-request/issues/902 + it('tests failure to create with commits on the working base (during the workflow) in detached HEAD state (WBNR)', async () => { + // Checkout the HEAD commit SHA + const headSha = await git.revParse('HEAD') + await git.checkout(headSha) + + // Create commits on the working base + const commits = await createCommits(git) + const commitMessage = uuidv4() + const result = await createOrUpdateBranch( + git, + commitMessage, + BASE, + BRANCH, + REMOTE_NAME, + false + ) + // The action cannot successfully create the branch + expect(result.action).toEqual('none') + }) }) diff --git a/__test__/integration-tests.sh b/__test__/integration-tests.sh index 43f5ae5..f91eae1 100755 --- a/__test__/integration-tests.sh +++ b/__test__/integration-tests.sh @@ -16,7 +16,7 @@ COPY __test__/entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] EOF - docker build -t $IMAGE . + docker build --no-cache -t $IMAGE . rm Dockerfile fi