From 90a06d6ba9543371ab4df8eeca0be07ca6054959 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 25 Jan 2024 11:46:48 -0700 Subject: [PATCH] feat: enhance error handling for non-git directories (#1885) Co-authored-by: GitHub Action --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ dist/index.js | Bin 2200718 -> 2200844 bytes dist/index.js.map | Bin 2577591 -> 2577733 bytes src/main.ts | 3 +-- src/utils.ts | 6 ++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b39fa0c1..d284b033 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -550,6 +550,39 @@ jobs: shell: bash + test-non-existing-repository: + name: Test changed-files with non existing repository + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'push' && needs.build.outputs.files_changed != 'true' + permissions: + pull-requests: read + steps: + - name: Checkout into dir1 + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + submodules: true + fetch-depth: 0 + path: dir1 + + - name: Download build assets + uses: actions/download-artifact@v3 + with: + name: build-assets + path: dir1/dist + + - name: Run changed-files with non existing repository + id: changed-files + continue-on-error: true + uses: ./dir1 + + - name: Verify failed + if: steps.changed-files.outcome != 'failure' + run: | + echo "Expected: (failure) got ${{ steps.changed-files.outcome }}" + exit 1 + test-submodules: name: Test changed-files with submodule runs-on: ubuntu-latest diff --git a/dist/index.js b/dist/index.js index 93e57dcc85d0847f6772ee379c7916cd0bda29a6..a5ea478c94dd5a9a910f2cf3d427a0f46e81d18e 100644 GIT binary patch delta 367 zcmZ9`JxfAS7zc2Uw|9HH`O=G}k5Z_MG&Bi<7R@aU5e>?{Cp}2#%DG1+BxtfFTF)v% zM9q;yLmwgf5;X)y-=Kfk)bQhhhll_3zq#+S>xVA8d}M>7`Ff7q=JwsPw{(qDRcKPY z;rT*)>YRk6(YD1UH7dH6H`^r^wsI%Z9F*8m0Q0WIjzhH9REkSY9G9AePbu?SWHFX{ z+GQ{0ggB*)uU)UHb6SbBOqP;`0;RQT@^qFu=Iw(;_773O`O9g0sxD-eT%ou#>f)31 z5G{S-a;p5Rny1Z<({?Y)#@F2nl`H9@N)A*CbSB)(6k-sE1Ux|!QjmrWWFZH6D8Mrm;RQ-icJ%|>-Tncl C^I}v0 diff --git a/dist/index.js.map b/dist/index.js.map index 5b5bcb0cf11b1508aad1ae58519863e2ace00f9d..8b9a990a86ccd2a5044aebed32e3883a001b58b1 100644 GIT binary patch delta 469 zcmZ9{JugF17zglNbx$cpy|kt1(<*HZ#j3GjVDS zeI9MbzOB1HwR&^0^D>aW3Zyk?0~fS|ZU@p#52|9>9a=sy^Et^$9&$Pmk}O^{OG28~ zISHfndd3YZ=H%f##i|w4Iu^#kvaopG>8ho&Swp>Sv2B-Acr$FrPfKOX;)W!SNlBta z*=Ve)HsAE1Udu*PyK3&JBdmH~nXWFrb=|(nu#dg4*r!BE7R<6tNlTn2k`!53pt!Wk zJf5Vg@~tudQU*Emt@W)eRQLX`A-cO5+y^ CE3Gg9 delta 346 zcmXxcze@sf9L90(^858p%dTIhW%WHXuc3~Hnxr9UX)3Tm+DtDwlsmYNB0>lvgor|f zKGQ*KL0~kTOEd}5U*X&o{RKS@4X-!P^z@$sDSQm1?oO_~$LRZ5j)%sV{HDG>%?+=)1)?2llM%~ zsJm-K)(u}A*-lk7+)BA2%$n^B+Y!0*Q`f88PHo%vtcve?XH8N4pC(-ud5H!^en7ev z&CozmIKBTcHKcw1aY%Q!JW9_uJVEX?&$QA#4pC4*g&4$P7)BrgqoBbUjKc&>!W1N7 f8d8vk8JLB??>U%<1rVS^78W4~OJTZ~UkQEz0Cabo diff --git a/src/main.ts b/src/main.ts index 4ce10716..df41b930 100644 --- a/src/main.ts +++ b/src/main.ts @@ -264,9 +264,8 @@ export async function run(): Promise { }) } else { if (!hasGitDirectory) { - core.info(`Running on a ${github.context.eventName} event...`) throw new Error( - `Can't find local .git in ${workingDirectory} directory. Please run actions/checkout before this action (Make sure the 'path' input is correct). If you intend to use Github's REST API note that only pull_request* events are supported.` + `Unable to locate the git repository in the given path: ${workingDirectory}.\n Please run actions/checkout before this action (Make sure the 'path' input is correct).\n If you intend to use Github's REST API note that only pull_request* events are supported. Current event is "${github.context.eventName}".` ) } diff --git a/src/utils.ts b/src/utils.ts index e7721448..f1672d70 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -680,6 +680,12 @@ export const isInsideWorkTree = async ({ } ) + if (stdout.trim() !== 'true') { + core.debug( + `The current working directory is not inside a git repository: ${cwd}` + ) + } + return stdout.trim() === 'true' }