Skip to content

Commit

Permalink
🐎 ci(workflow): 修改为判断npm版本号,而非与之前的对比
Browse files Browse the repository at this point in the history
  • Loading branch information
marherb committed May 4, 2024
1 parent 0c75726 commit 83ccd79
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 83ccd79

Please sign in to comment.