Skip to content

Commit 64f5f36

Browse files
committed
Add github actions
1 parent c5490c0 commit 64f5f36

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

.github/workflows/ci.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Cargo Build & Test
2+
3+
on:
4+
push:
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
9+
jobs:
10+
build_and_test:
11+
name: Rust project - latest
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
toolchain:
16+
- stable
17+
- beta
18+
- nightly
19+
steps:
20+
- uses: actions/checkout@v3
21+
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
22+
- run: cargo build --verbose
23+
- run: cargo test --verbose

.github/workflows/clippy.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on: push
2+
name: Clippy check
3+
jobs:
4+
clippy_check:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v1
8+
- uses: actions-rs/toolchain@v1
9+
with:
10+
toolchain: nightly
11+
components: clippy
12+
override: true
13+
- uses: actions-rs/clippy-check@v1
14+
with:
15+
token: ${{ secrets.GITHUB_TOKEN }}
16+
args: --all-features

.github/workflows/version.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- master
5+
6+
# This runs on PRs so error can be seen before merging
7+
name: Version check
8+
9+
jobs:
10+
all:
11+
runs-on: ubuntu-latest
12+
13+
name: Version check
14+
15+
env:
16+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Check version format and availability
24+
run: ./scripts/version_check.sh

scripts/version_check.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
# Usage:
4+
# check_version.sh
5+
#
6+
# Reads version from Cargo.toml and checks it against tags
7+
#
8+
# Credit to @richfitz for this from the dust package:
9+
# https://github.com/mrc-ide/dust/blob/master/scripts/version_check
10+
VERSION=${1:-$(grep '^version' Cargo.toml | sed 's/.*= *//' | sed 's/"//g')}
11+
TAG="v${VERSION}"
12+
13+
echo "Proposed version number '$VERSION'"
14+
15+
if echo "$VERSION" | grep -Eq "[0-9]+[.][0-9]+[.][0-9]+"; then
16+
echo "[OK] Version number in correct format"
17+
else
18+
echo "[ERROR] Invalid format version number '$VERSION' must be in format 'x.y.z'"
19+
exit 1
20+
fi
21+
22+
EXIT_CODE=0
23+
24+
echo "Updating remote git data"
25+
git fetch --quiet
26+
27+
BRANCH_DEFAULT=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
28+
LAST_TAG=$(git describe --tags --abbrev=0 "origin/${BRANCH_DEFAULT}")
29+
30+
echo "Last tag was $LAST_TAG"
31+
32+
if git rev-parse "$TAG" >/dev/null 2>&1; then
33+
echo "[ERROR] Tag $TAG already exists - update version number in Cargo.toml"
34+
exit 1
35+
else
36+
echo "[OK] Version number not yet present as git tag"
37+
fi
38+
39+
MAJOR=$(echo $VERSION | cut -d. -f1)
40+
MINOR=$(echo $VERSION | cut -d. -f2)
41+
PATCH=$(echo $VERSION | cut -d. -f3)
42+
43+
LAST_VERSION=$(echo "$LAST_TAG" | sed 's/^v//')
44+
LAST_MAJOR=$(echo $LAST_VERSION | cut -d. -f1)
45+
LAST_MINOR=$(echo $LAST_VERSION | cut -d. -f2)
46+
LAST_PATCH=$(echo $LAST_VERSION | cut -d. -f3)
47+
48+
if (( $MAJOR > $LAST_MAJOR )); then
49+
echo "[OK] Increasing MAJOR version"
50+
exit $EXIT_CODE
51+
elif (( $MINOR > $LAST_MINOR )); then
52+
echo "[OK] Increasing MINOR version"
53+
exit $EXIT_CODE
54+
elif (( $PATCH > $LAST_PATCH )); then
55+
echo "[OK] Increasing PATCH version"
56+
exit $EXIT_CODE
57+
else
58+
echo "[ERROR] Version number has not increased relative to $LAST_VERSION"
59+
exit 1
60+
fi

0 commit comments

Comments
 (0)