在 Github 个操作中比较包版本

Compare Package Versions in Github Actions

我想将我当前部署的版本与我 'package.json' 中提到的版本进行比较。如果 json 中的版本号高于当前版本(在我推送的标签(发布)中提到),我想使用 GitHub 操作部署它。

我无法比较 Github Actions yaml 文件中的两个 numbers/Integers。

目前我正在这样做:

- name: Clean Versions
  run: |
        echo "TAG_VERSION=$(echo ${{env.TAG}} | tr -dc '0-9')" >> $GITHUB_ENV
        echo "PACKAGE_VERSION=$(echo ${{env.PACKAGE}} | tr -dc '0-9')" >> $GITHUB_ENV

- name: Compare Versions
  run: |
    if [ $(( ${{env.TAG_VERSION}} )) >> $(( ${{env.PACKAGE_VERSION}} )) ]; then
        echo "PUSH=true" >> "$GITHUB_ENV"

    elif [ ${{env.TAG_VERSION}} == ${{env.PACKAGE_VERSION_NUMBER}} ]; then
        echo "PUSH=false" >> "$GITHUB_ENV"

    else
        echo "PUSH=false" >> "$GITHUB_ENV"
    fi 

它没有提供我想要的结果:

第一眼看起来不错,但提供:

PUSH: true

有没有一种很好的本机方法来比较 if 条件中的那些版本号?

我也试过这样转换数字,但输出相同:

- name: Clean Versions
  run: |
        echo "TAG_VERSION=$(echo ${{env.TAG}} | tr -dc '0-9')" >> $GITHUB_ENV
        echo "PACKAGE_VERSION=$(echo ${{env.PACKAGE}} | tr -dc '0-9')" >> $GITHUB_ENV

- name: Get Numbers
  run: |
    echo "TAG_NUMBER=$echo$((${{env.TAG_VERSION}} - 0 ))" >> $GITHUB_ENV
    echo "PACKAGE_NUMBER=$echo$((${{env.PACKAGE_VERSION}} - 0 ))" >> $GITHUB_ENV

- name: Compare Versions
  run: |
    if [ ${{env.TAG_NUMBER}} >>  ${{env.PACKAGE_NUMBER}} ]; then
        echo "PUSH=true" >> "$GITHUB_ENV"

    elif [ ${{env.TAG_NUMBER}} == ${{env.PACKAGE_NUMBER}} ]; then
        echo "PUSH=false" >> "$GITHUB_ENV"

    else
        echo "PUSH=false" >> "$GITHUB_ENV"
    fi     

输出:

刚刚将 if 括号从“[ ... ]”更改为“(( ... ))”并且效果完美:

- name: Clean Versions
  run: |
        echo "TAG_VERSION=$(echo ${{env.TAG}} | tr -dc '0-9')" >> $GITHUB_ENV
        echo "PACKAGE_VERSION=$(echo ${{env.PACKAGE}} | tr -dc '0-9')" >> $GITHUB_ENV

- name: 
  run: |
    echo "TAG_NUMBER=$echo$((${{env.TAG_VERSION}} - 0 ))" >> $GITHUB_ENV
    echo "PACKAGE_NUMBER=$echo$((${{env.PACKAGE_VERSION}} - 0 ))" >> $GITHUB_ENV

- name: Compare Versions
  run: |
    if (( ${{env.PACKAGE_NUMBER}} > ${{env.TAG_NUMBER}} )); then
        echo "PUSH=true" >> "$GITHUB_ENV"

    elif (( ${{env.PACKAGE_NUMBER}} = ${{env.TAG_NUMBER}} )); then
        echo "PUSH=false" >> "$GITHUB_ENV"

    else
        echo "PUSH=false" >> "$GITHUB_ENV"
    fi