Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Added build and draft release job #17

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflows/rust-check-version.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions vergt.sh
Original file line number Diff line number Diff line change
@@ -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
Loading