From 83ccd79dff00130dd261cb39fc9d5bdba6c2df0a Mon Sep 17 00:00:00 2001 From: marherb <1014287974@qq.com> Date: Sun, 5 May 2024 00:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20ci(workflow):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=88=A4=E6=96=ADnpm=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E8=80=8C=E9=9D=9E=E4=B8=8E=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6aca511..58ebc2f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,8 +11,6 @@ jobs: steps: - name: Check out repository uses: actions/checkout@v4 - with: - fetch-depth: 2 - name: Use Node.js uses: actions/setup-node@v4 @@ -24,13 +22,14 @@ jobs: - name: Check package.json version change id: check_version run: | - VERSION_IN_GIT=$(git diff HEAD~ -- package.json | grep -oP '(?<="version": ")[^"]*' || echo "not_found") + PACKAGE_NAME=$(node -p "require('./package.json').name") CURRENT_VERSION=$(node -p "require('./package.json').version") - if [ "$VERSION_IN_GIT" == "$CURRENT_VERSION" ] || [ "$VERSION_IN_GIT" == "not_found" ]; then - echo "Version has not changed or unable to find previous version info." + NPM_VERSION=$(npm view $PACKAGE_NAME version || echo "0.0.0") + if [ "$(printf '%s\n' "$CURRENT_VERSION" "$NPM_VERSION" | sort -V | tail -n1)" != "$CURRENT_VERSION" ] || [ "$NPM_VERSION" == "0.0.0" ]; then + echo "Current version is less than or equal to npm version, or package has not been published to npm yet." echo "version_changed=false" >> $GITHUB_ENV else - echo "Version has changed." + echo "Current version is greater than npm version." echo "version_changed=true" >> $GITHUB_ENV fi