From 2f0ab46185bc2c6a0fb4af861353d2e2df19c136 Mon Sep 17 00:00:00 2001 From: Nyoxis Date: Wed, 6 Mar 2024 04:13:44 +0200 Subject: [PATCH] ci: Added build and draft release job Added package version bump check --- .github/workflows/rust-cargo-build.yml | 4 +- .github/workflows/rust-check-version.yml | 71 ++++++++++++++++++++++++ vergt.sh | 34 ++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rust-check-version.yml create mode 100755 vergt.sh diff --git a/.github/workflows/rust-cargo-build.yml b/.github/workflows/rust-cargo-build.yml index c2bb3d5..ecd83cc 100644 --- a/.github/workflows/rust-cargo-build.yml +++ b/.github/workflows/rust-cargo-build.yml @@ -7,7 +7,8 @@ on: - stable jobs: - check: + cargo-build: + needs: version name: Cargo build runs-on: ubuntu-latest env: @@ -44,6 +45,5 @@ jobs: cargo metadata --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 \ No newline at end of file diff --git a/.github/workflows/rust-check-version.yml b/.github/workflows/rust-check-version.yml new file mode 100644 index 0000000..dab5084 --- /dev/null +++ b/.github/workflows/rust-check-version.yml @@ -0,0 +1,71 @@ +name: Rust check version + +on: + pull_request: + push: + branches: + - main + - stable + +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 --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 --no-deps | + jq -r '.packages[] | select(.name == "kalatori") | .version' + )" >> $GITHUB_ENV + + - name: Check which version is greater + run: echo "GREATER_VER=$(./vergt.sh $VERSION $BEFORE_VERSION)" >> $GITHUB_ENV + + - name: Fail if current version is not greater + run: exit 1 + if: ${{ env.GREATER_VER != 1 }} diff --git a/vergt.sh b/vergt.sh new file mode 100755 index 0000000..31ad55b --- /dev/null +++ b/vergt.sh @@ -0,0 +1,34 @@ +#!/bin/bash +IFS=. +ver1=($1) +ver2=($2) +# starting from minor of ver1 if ver1 shorter ver2 +# fill absent fields in ver1 with zeros +for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) +do + ver1[i]=0 +done +# starting from major of ver1 +for ((i=0; i<${#ver1[@]}; i++)) +do + if [[ -z ${ver2[i]} ]] + then + # if ver2 shorter ver1 then + # fill absent fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + # if ver1 greater than ver2 in most major differing field + echo 1 + exit + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + # if ver2 greater than ver1 in most major differing field + echo 2 + exit + fi +done +echo 0 +exit \ No newline at end of file