From ca17c4913005e83a52c7ef8326d7cef0b0318b16 Mon Sep 17 00:00:00 2001 From: Nyoxis Date: Tue, 5 Mar 2024 04:57:32 +0200 Subject: [PATCH 1/3] CI: Added build and draft release job --- .github/workflows/rust-cargo-build.yml | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/rust-cargo-build.yml diff --git a/.github/workflows/rust-cargo-build.yml b/.github/workflows/rust-cargo-build.yml new file mode 100644 index 0000000..c2bb3d5 --- /dev/null +++ b/.github/workflows/rust-cargo-build.yml @@ -0,0 +1,49 @@ +name: Rust cargo build + +on: + push: + branches: + - main + - stable + +jobs: + check: + name: Cargo build + 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 --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 From 22ef5fe1d63a867d76932e43c1b7524ce86d40e8 Mon Sep 17 00:00:00 2001 From: Nyoxis Date: Wed, 6 Mar 2024 04:13:44 +0200 Subject: [PATCH 2/3] ci: Added build and draft release job Added package version bump check --- .github/workflows/rust-cargo-build.yml | 49 ---------- .github/workflows/rust-check-version.yml | 112 +++++++++++++++++++++++ vergt.sh | 34 +++++++ 3 files changed, 146 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/rust-cargo-build.yml 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 deleted file mode 100644 index c2bb3d5..0000000 --- a/.github/workflows/rust-cargo-build.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Rust cargo build - -on: - push: - branches: - - main - - stable - -jobs: - check: - name: Cargo build - 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 --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..046d795 --- /dev/null +++ b/.github/workflows/rust-check-version.yml @@ -0,0 +1,112 @@ +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: 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 }} + + 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/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 From ec7734db0f00fb0dffbab3c886bf9b64d73c2f4c Mon Sep 17 00:00:00 2001 From: Nyoxis Date: Wed, 6 Mar 2024 21:37:40 +0200 Subject: [PATCH 3/3] ci: Added build and draft release job Added package version bump check --- .github/workflows/rust-check-version.yml | 6 +---- is_version_greater.sh | 31 +++++++++++++++++++++ vergt.sh | 34 ------------------------ 3 files changed, 32 insertions(+), 39 deletions(-) create mode 100755 is_version_greater.sh delete mode 100755 vergt.sh diff --git a/.github/workflows/rust-check-version.yml b/.github/workflows/rust-check-version.yml index 046d795..c1f6041 100644 --- a/.github/workflows/rust-check-version.yml +++ b/.github/workflows/rust-check-version.yml @@ -63,11 +63,7 @@ jobs: )" >> $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 }} + run: ./is_version_greater.sh $VERSION $BEFORE_VERSION cargo-build: name: Cargo build 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 diff --git a/vergt.sh b/vergt.sh deleted file mode 100755 index 31ad55b..0000000 --- a/vergt.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/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