From afec5a93877162289e4cc09d622733545015f745 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Thu, 25 Jun 2026 15:17:29 +0000 Subject: [PATCH] =?UTF-8?q?fix(action=20image):=20=E5=AE=89=E8=A3=9D=20git?= =?UTF-8?q?=20=E4=BE=9B=E5=89=8D=E7=BD=AE=E9=81=A0=E7=AB=AF=E9=A9=97?= =?UTF-8?q?=E8=AD=89=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++-- app/git.js | 5 ++++- app/git.test.js | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index caf6bce..e894c60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:latest # 安裝必要的工具 -RUN apk add --no-cache --no-check-certificate bash nodejs npm +RUN apk add --no-cache --no-check-certificate bash git nodejs npm COPY ./app /app RUN cd /app && npm install @@ -9,4 +9,4 @@ RUN cd /app && npm install COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/app/git.js b/app/git.js index 9189531..f201ad9 100644 --- a/app/git.js +++ b/app/git.js @@ -13,7 +13,10 @@ function makeRunner(spawn) { const opts = { cwd, encoding: 'utf8' }; if (env) opts.env = env; const result = spawn('git', args, opts); - if (result.error) throw result.error; + if (result.error) { + if (result.error.code === 'ENOENT') throw new Error('找不到 git 指令,請確認 action image 已安裝 git'); + throw result.error; + } if (result.status !== 0) throw new Error((result.stderr || result.stdout || '').trim()); return (result.stdout || '').trim(); }; diff --git a/app/git.test.js b/app/git.test.js index efc15a2..4503465 100644 --- a/app/git.test.js +++ b/app/git.test.js @@ -300,6 +300,15 @@ describe('verifyRemoteAccess', () => { assert.match(result.error, /could not read Username/); }); + it('reports a clear failure when git is not installed', () => { + const enoent = new Error('spawnSync git ENOENT'); + enoent.code = 'ENOENT'; + const spawn = () => ({ status: null, stdout: '', stderr: '', error: enoent }); + const result = verifyRemoteAccess(workspace, spawn); + assert.equal(result.ok, false); + assert.match(result.error, /找不到 git 指令/); + }); + it('cleans up the askpass script after running', () => { verifyRemoteAccess(workspace, () => ({ status: 0, stdout: '', stderr: '', error: null })); const leftover = fs.readdirSync(workspace).filter(f => f.endsWith('.git-askpass.sh'));