diff --git a/.github/workflows/rust-check-version.yml b/.github/workflows/rust-check-version.yml new file mode 100644 index 0000000..c1f6041 --- /dev/null +++ b/.github/workflows/rust-check-version.yml @@ -0,0 +1,108 @@ +name: Rust check version and build + +on: + pull_request: + push: + branches: + - main + +jobs: + version: + name: Check version + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.12.1 + with: + access_token: ${{ github.token }} + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1.0.7 + with: + profile: minimal + toolchain: stable + override: true + + - name: Checkout base + uses: actions/checkout@v4.1.1 + if: github.event_name == 'pull_request' + with: + ref: ${{ github.event.pull_request.base.ref }} + fetch-depth: 50 + submodules: 'recursive' + + - name: Checkout before push + uses: actions/checkout@v4.1.1 + if: github.event_name != 'pull_request' + with: + ref: ${{ github.event.before }} + fetch-depth: 50 + submodules: 'recursive' + + - name: Get package version before or base + run: > + echo "BEFORE_VERSION=$( + cargo metadata --format-version=1 --no-deps | + jq -r '.packages[] | select(.name == "kalatori") | .version' + )" >> $GITHUB_ENV + + - name: Checkout sources + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 50 + submodules: 'recursive' + + - name: Get package version + run: > + echo "VERSION=$( + cargo metadata --format-version=1 --no-deps | + jq -r '.packages[] | select(.name == "kalatori") | .version' + )" >> $GITHUB_ENV + + - name: Check which version is greater + run: ./is_version_greater.sh $VERSION $BEFORE_VERSION + + cargo-build: + name: Cargo build + needs: version + if: github.event_name == 'push' + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.12.1 + with: + access_token: ${{ github.token }} + + - name: Checkout sources + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 50 + submodules: 'recursive' + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1.0.7 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 + + - name: cargo build + run: cargo build --release + + - name: Get package version + run: > + echo "VERSION=$( + cargo metadata --format-version=1 --no-deps | + jq -r '.packages[] | select(.name == "kalatori") | .version' + )" >> $GITHUB_ENV + - name: Draft release binary + run: gh release create -d $VERSION ./target/release/kalatori --generate-notes diff --git a/is_version_greater.sh b/is_version_greater.sh new file mode 100755 index 0000000..c0f2f02 --- /dev/null +++ b/is_version_greater.sh @@ -0,0 +1,31 @@ +#!/bin/bash +IFS=. +version=($1) +before_version=($2) +# starting from minor of version if version shorter before_version +# fill absent fields in version with zeros +for ((i=${#version[@]}; i<${#before_version[@]}; i++)) +do + version[i]=0 +done +# starting from major of version +for ((i=0; i<${#version[@]}; i++)) +do + if [[ -z ${before_version[i]} ]] + then + # if before_version shorter version then + # fill absent fields in before_version with zeros + ver2[i]=0 + fi + if ((10#${version[i]} > 10#${before_version[i]})) + then + # if version greater than before_version in most major differing field + exit 0 + fi + if ((10#${version[i]} < 10#${before_version[i]})) + then + # if version is not greater in most major differing field + exit 1 + fi +done +exit 1 \ No newline at end of file