diff --git a/.github/workflows/rust-cargo-build.yml b/.github/workflows/rust-cargo-build.yml new file mode 100644 index 0000000..0f5f5f6 --- /dev/null +++ b/.github/workflows/rust-cargo-build.yml @@ -0,0 +1,48 @@ +name: Rust cargo build and draft release + +on: + push: + branches: + - main + +jobs: + cargo-build: + 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 --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 \ 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..aad5a7b --- /dev/null +++ b/.github/workflows/rust-check-version.yml @@ -0,0 +1,71 @@ +name: Rust check version + +on: + pull_request: + types: + - opened + - edited + - synchronize + 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 + + diff --git a/Cargo.lock b/Cargo.lock index 8de0bfd..32c077b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,54 @@ dependencies = [ "winapi", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.80" @@ -772,6 +820,12 @@ dependencies = [ "inout", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "common-path" version = "1.0.0" @@ -1238,17 +1292,27 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + [[package]] name = "env_logger" -version = "0.10.2" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d" dependencies = [ + "anstream", + "anstyle", + "env_filter", "humantime", - "is-terminal", "log", - "regex", - "termcolor", ] [[package]] @@ -2013,17 +2077,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "itertools" version = "0.10.5" @@ -4779,6 +4832,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "valuable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e419c59..badd1ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ members = ["kalatori-ah"] tokio = { version = "1", features = ["full"] } tokio-util = { version = "0.7", features = ["full"] } anyhow = "1" -env_logger = "0.10" +env_logger = "0.11" log = "0.4" subxt = { version = "0.34", features = ["substrate-compat"] } axum = "0.7" 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