From 8f2a80e6566350cdce68e7f8fb8a01149b00e969 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 | 68 ++++++++++++++++++++++++ ver1gt.sh | 33 ++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rust-check-version.yml create mode 100755 ver1gt.sh diff --git a/.github/workflows/rust-cargo-build.yml b/.github/workflows/rust-cargo-build.yml index c2bb3d5..d8f7696 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: Check 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..c5542bc --- /dev/null +++ b/.github/workflows/rust-check-version.yml @@ -0,0 +1,68 @@ +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 before + 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 + 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 + 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 version and fail + run: exit 1 + if: $( ./ver1gt.sh $env.VERSION $env.BEFORE_VERSION ) diff --git a/ver1gt.sh b/ver1gt.sh new file mode 100755 index 0000000..29f6d99 --- /dev/null +++ b/ver1gt.sh @@ -0,0 +1,33 @@ +#!/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 true + exit + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + # if ver1 less than ver 2 in most major differing field + echo false + exit + fi +done +exit \ No newline at end of file