diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml index fdbd527..deb78b2 100644 --- a/.github/workflows/npm-release.yml +++ b/.github/workflows/npm-release.yml @@ -5,7 +5,7 @@ on: branches: [ main ] jobs: - build: + Build: runs-on: ubuntu-latest strategy: matrix: @@ -45,7 +45,7 @@ jobs: RemoveOldRelease: runs-on: ubuntu-latest - needs: build + needs: Build steps: - name: install github-cli run: | @@ -57,13 +57,44 @@ jobs: && sudo apt install gh -y - name: CheckOut - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set APP_VERSION env run: | - sudo chmod a+x git_push.sh \ - && pre_del_tag=$(./git_push.sh -get_pre_del_tag_name) \ - && echo APP_OLD_VERSION=v${pre_del_tag} >> ${GITHUB_ENV} + APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) \ + + function get_pre_del_tag { + local v_str=$1 + baseStr=$(echo $v_str | cut -d'.' -f1) + base=${baseStr//v/} + major=$(echo $v_str | cut -d'.' -f2) + minor=$(echo $v_str | cut -d'.' -f3) + + if ((minor>0)); then + minor=$((minor-1)) + else + minor=999 + if ((major>0)); then + major=$((major-1)) + else + major=999 + if ((base>0)); then + base=$((base-1)) + else + echo "Error: Version cannot be decremented." + exit 1 + fi + fi + fi + + pre_v_no="v${base}.${major}.${minor}" + echo $pre_v_no + } + + APP_OLD_VERSION=$(get_pre_del_tag $(get_pre_del_tag $APP_VERSION)) + + echo "Old version to remove: ${APP_OLD_VERSION}" + echo APP_OLD_VERSION=${APP_OLD_VERSION} >> ${GITHUB_ENV} - name: Remove Old Release run: | diff --git a/git_tag.sh b/git_tag.sh index 4692ecb..8086412 100755 --- a/git_tag.sh +++ b/git_tag.sh @@ -11,21 +11,21 @@ CURRENT_VERSION=$(jq -r '.version' $VersionFile) NEXT_VERSION="" -OSTYPE="Unknown" +OS_TYPE="Unknown" GetOSType() { uNames=`uname -s` osName=${uNames: 0: 4} if [ "$osName" == "Darw" ] # Darwin then - OSTYPE="Darwin" + OS_TYPE="Darwin" elif [ "$osName" == "Linu" ] # Linux then - OSTYPE="Linux" + OS_TYPE="Linux" elif [ "$osName" == "MING" ] # MINGW, windows, git-bash then - OSTYPE="Windows" + OS_TYPE="Windows" else - OSTYPE="Unknown" + OS_TYPE="Unknown" fi } GetOSType @@ -101,30 +101,9 @@ function git_handle_ready() { local netx_version_no=${NEXT_VERSION//v/} - # 检查dos2unix是否存在,如果不存在,尝试安装 - case "$(uname -s)" in - Linux) - if [[ -f "/etc/debian_version" ]]; then - sudo apt-get update - sudo apt-get install -y dos2unix - elif [[ -f "/etc/redhat-release" ]]; then - sudo yum install -y dos2unix - else - echo "Unknown Linux distribution. Please install dos2unix manually." - fi - ;; - - Darwin) # macOS - brew install dos2unix - ;; - *) - echo "Unsupported OS. Please install dos2unix manually." - ;; - esac - jq ".version = \"${netx_version_no}\"" $VersionFile > temp.json - if command -v dos2unix &> /dev/null; then + if [[ $OS_TYPE == "Darwin" ]]; then dos2unix temp.json fi diff --git a/package-lock.json b/package-lock.json index 299a474..bb81388 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cloudflare-r2-upload", - "version": "1.0.13", + "version": "1.0.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cloudflare-r2-upload", - "version": "1.0.13", + "version": "1.0.14", "license": "MIT", "dependencies": { "@actions/core": "^1", diff --git a/package.json b/package.json index 01a8114..e9ee150 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "@aws-sdk/client-s3": "^3" }, "name": "cloudflare-r2-upload", - "version": "1.0.13", + "version": "1.0.14", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"