From 1e98110785d82b98f1ea9d4951cdb64cc84cae19 Mon Sep 17 00:00:00 2001 From: LiangYongzhuo Date: Mon, 4 Sep 2023 11:26:21 +0800 Subject: [PATCH] fix: resolve the bug of new package version not exist (#12) --- dist/index.js | 17 ++++++++++++++--- package.json | 2 +- src/index.js | 17 ++++++++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4c90116..c63af68 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15666,9 +15666,20 @@ async function run() { const currentVersionURL = `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/${baseSHA}${workingDirectory}version`; core.info(`current version url: ${currentVersionURL}`); - let { data: currentVersion } = await axios.get(currentVersionURL, { - headers, - }); + let { data: currentVersion } = await axios + .get(currentVersionURL, { + headers, + }) + .catch((error) => { + // if status code 404, old version file is not exist, setup version to 0.0.0 + if (error.response && error.response.status === 404) { + return { + data: '0.0.0', + }; + } + throw error; + }); + currentVersion = currentVersion.toString().trim(); const nextVersionURL = `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/${headSHA}${workingDirectory}version`; diff --git a/package.json b/package.json index ae6fd8a..ecf4cf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "action-version-check", - "version": "0.0.3", + "version": "0.0.4", "description": "Check if the current version is compliant with the specification", "main": "index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 0ecf210..26f0e45 100644 --- a/src/index.js +++ b/src/index.js @@ -69,9 +69,20 @@ async function run() { const currentVersionURL = `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/${baseSHA}${workingDirectory}version`; core.info(`current version url: ${currentVersionURL}`); - let { data: currentVersion } = await axios.get(currentVersionURL, { - headers, - }); + let { data: currentVersion } = await axios + .get(currentVersionURL, { + headers, + }) + .catch((error) => { + // if status code 404, old version file is not exist, setup version to 0.0.0 + if (error.response && error.response.status === 404) { + return { + data: '0.0.0', + }; + } + throw error; + }); + currentVersion = currentVersion.toString().trim(); const nextVersionURL = `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/${headSHA}${workingDirectory}version`;