Skip to content

Commit

Permalink
feat(ci): try github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fastfailures committed Jan 29, 2025
1 parent 8a48619 commit 9f74432
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/ci-tools/audit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

cargo install --locked cargo-audit

cargo audit --color always
7 changes: 7 additions & 0 deletions .github/ci-tools/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

rustup component add rustfmt

cargo fmt -- --check
26 changes: 26 additions & 0 deletions .github/ci-tools/get_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Dependencies: jq

set -eo pipefail

# Print version of given workspace package.
get_version() {
if [[ -z $1 ]]; then
echo >&2 "name argument is mandatory"
exit 1
fi
local name="$1"
version=$(cargo metadata --format-version 1 --no-deps | jq '.packages[] | select(.name == "'"$name"'") | {version}' | jq --exit-status -r .version)
if [[ ! $version =~ ^[0-9] ]]; then
echo >&2 "invalid version for ${name}: ${version}"
exit 1
fi
echo "$version"
}

main() {
get_version "$1"
}

main "$@"
7 changes: 7 additions & 0 deletions .github/ci-tools/outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

cargo install --locked cargo-outdated

cargo outdated --root-deps-only --exit-code 1
14 changes: 14 additions & 0 deletions .github/ci-tools/semver
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

CI_TOOLS_DIR="$(dirname "${BASH_SOURCE[0]}")"
BASELINE_GIT_REF_FILE="${CI_TOOLS_DIR}/../../.semver-baseline"

apt-get update
apt-get install -y --no-install-recommends cmake
cargo install --locked cargo-semver-checks

baseline="$(cat "${BASELINE_GIT_REF_FILE}")"
echo "Baseline Git rev: ${baseline}"
env SQLX_OFFLINE="true" cargo semver-checks --baseline-rev "$baseline"
51 changes: 51 additions & 0 deletions .github/ci-tools/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -euo pipefail

export CI="true" # https://insta.rs/docs/quickstart/#continuous-integration

sysinfo() {
echo "System information:"
uname -a
rustc --version
cargo --version
echo "CARGO_HOME=${CARGO_HOME}"
echo ".cargo/config.toml content:"
echo "---"
cat "${CARGO_HOME}/config.toml"
echo "---"
echo "Environment variables:"
printenv | sort
}

install_test_deps() {
echo "Initialising test dependencies"
apt-get update -yq
apt-get install -yq --no-install-recommends wireguard-tools
}

lint() {
echo "Linting"
rustup component add clippy
cargo clippy --all-features --color always -- --deny warnings --forbid unsafe_code
}

tests() {
echo "Testing"
install_test_deps
cargo test --color=always -- --color=always # <https://github.com/rust-lang/cargo/issues/11581#issuecomment-1382870899>
cargo test --color=always -- --color=always --ignored # slow tests
}

build() {
cargo build --color always
}

main() {
sysinfo
build
lint
tests
}

main "$@"
37 changes: 37 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: GitHub Actions Demo
on: [push]
# env:
# CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" # necessary for dependency caching

# default:
# cache:
# key: "$CI_JOB_NAME" # not using Cargo.lock as key file: it changes too often
# paths: [ .cargo/ ]
# unprotect: true # publish job is "protected" because it runs only on main
defaults:
run:
working-directory: ./.github/ci-tools

jobs:
format:
runs-on: rust-1.82
# NOTE: Rust compiler versions are backward compatible, but updated clippy
# can block a previously working job, pinning version to grant more reproducibility
steps:
- name: Check formatting
run: ./format
# cache: []

semver:
runs-on: rust-1.82
if: github.ref == 'refs/heads/master' # only on `master` branch
steps:
- name: Check semver
run: ./semver

test:
runs-on: rust-1.82
steps:
- name: Run tests
run: ./test
# not splitting lint (clippy) and test in two jobs to avoid wasting environment preparation time

0 comments on commit 9f74432

Please sign in to comment.