Skip to content

Commit

Permalink
ci: Added build and draft release job
Browse files Browse the repository at this point in the history
Added package version bump check
  • Loading branch information
Nyoxis committed Mar 6, 2024
1 parent ca17c49 commit a4880d7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust-cargo-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
- stable

jobs:
check:
cargo-build:
needs: Check version
name: Cargo build
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -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
68 changes: 68 additions & 0 deletions .github/workflows/rust-check-version.yml
Original file line number Diff line number Diff line change
@@ -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 }}
33 changes: 33 additions & 0 deletions ver1gt.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a4880d7

Please sign in to comment.