Skip to content

Commit 4791027

Browse files
committed
feat(ci): try github actions
1 parent fc7b43a commit 4791027

File tree

7 files changed

+149
-0
lines changed

7 files changed

+149
-0
lines changed

.github/ci-tools/audit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
cargo install --locked cargo-audit
6+
7+
cargo audit --color always

.github/ci-tools/format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
rustup component add rustfmt
6+
7+
cargo fmt -- --check

.github/ci-tools/get_version

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# Dependencies: jq
4+
5+
set -eo pipefail
6+
7+
# Print version of given workspace package.
8+
get_version() {
9+
if [[ -z $1 ]]; then
10+
echo >&2 "name argument is mandatory"
11+
exit 1
12+
fi
13+
local name="$1"
14+
version=$(cargo metadata --format-version 1 --no-deps | jq '.packages[] | select(.name == "'"$name"'") | {version}' | jq --exit-status -r .version)
15+
if [[ ! $version =~ ^[0-9] ]]; then
16+
echo >&2 "invalid version for ${name}: ${version}"
17+
exit 1
18+
fi
19+
echo "$version"
20+
}
21+
22+
main() {
23+
get_version "$1"
24+
}
25+
26+
main "$@"

.github/ci-tools/outdated

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
cargo install --locked cargo-outdated
6+
7+
cargo outdated --root-deps-only --exit-code 1

.github/ci-tools/semver

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
CI_TOOLS_DIR="$(dirname "${BASH_SOURCE[0]}")"
6+
BASELINE_GIT_REF_FILE="${CI_TOOLS_DIR}/../../.semver-baseline"
7+
8+
apt-get update
9+
apt-get install -y --no-install-recommends cmake
10+
cargo install --locked cargo-semver-checks
11+
12+
baseline="$(cat "${BASELINE_GIT_REF_FILE}")"
13+
echo "Baseline Git rev: ${baseline}"
14+
env SQLX_OFFLINE="true" cargo semver-checks --baseline-rev "$baseline"

.github/ci-tools/test

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
export CI="true" # https://insta.rs/docs/quickstart/#continuous-integration
6+
7+
sysinfo() {
8+
echo "System information:"
9+
uname -a
10+
rustc --version
11+
cargo --version
12+
echo "CARGO_HOME=${CARGO_HOME}"
13+
echo ".cargo/config.toml content:"
14+
echo "---"
15+
cat "${CARGO_HOME}/config.toml"
16+
echo "---"
17+
echo "Environment variables:"
18+
printenv | sort
19+
}
20+
21+
install_test_deps() {
22+
echo "Initialising test dependencies"
23+
apt-get update -yq
24+
apt-get install -yq --no-install-recommends wireguard-tools
25+
}
26+
27+
lint() {
28+
echo "Linting"
29+
rustup component add clippy
30+
cargo clippy --all-features --color always -- --deny warnings --forbid unsafe_code
31+
}
32+
33+
tests() {
34+
echo "Testing"
35+
install_test_deps
36+
cargo test --color=always -- --color=always # <https://github.com/rust-lang/cargo/issues/11581#issuecomment-1382870899>
37+
cargo test --color=always -- --color=always --ignored # slow tests
38+
}
39+
40+
build() {
41+
cargo build --color always
42+
}
43+
44+
main() {
45+
sysinfo
46+
build
47+
lint
48+
tests
49+
}
50+
51+
main "$@"

.github/workflows/checks.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: GitHub Actions Demo
2+
on: [push]
3+
# env:
4+
# CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" # necessary for dependency caching
5+
6+
# default:
7+
# cache:
8+
# key: "$CI_JOB_NAME" # not using Cargo.lock as key file: it changes too often
9+
# paths: [ .cargo/ ]
10+
# unprotect: true # publish job is "protected" because it runs only on main
11+
defaults:
12+
run:
13+
working-directory: ./.github/ci-tools
14+
15+
jobs:
16+
format:
17+
runs-on: rust-1.82
18+
# NOTE: Rust compiler versions are backward compatible, but updated clippy
19+
# can block a previously working job, pinning version to grant more reproducibility
20+
steps:
21+
- name: Check formatting
22+
run: ./format
23+
# cache: []
24+
25+
semver:
26+
runs-on: rust-1.82
27+
if: github.ref == 'refs/heads/master' # only on `master` branch
28+
steps:
29+
- name: Check semver
30+
run: ./semver
31+
32+
test:
33+
runs-on: rust-1.82
34+
steps:
35+
- name: Run tests
36+
run: ./test
37+
# not splitting lint (clippy) and test in two jobs to avoid wasting environment preparation time

0 commit comments

Comments
 (0)