Skip to content

Commit

Permalink
ci: init (#21)
Browse files Browse the repository at this point in the history
* init ci

* add components to nightly channel

* bump h2 to 0.4.4
  • Loading branch information
yihau authored Apr 4, 2024
1 parent 50cbde2 commit c77e61b
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 96 deletions.
10 changes: 10 additions & 0 deletions .github/scripts/cargo-audit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

repo_root=$(git rev-parse --show-toplevel)

# shellcheck disable=SC1091
source "$repo_root/.github/scripts/rust-version.sh" stable >/dev/null

cargo +"$rust_stable" audit
11 changes: 11 additions & 0 deletions .github/scripts/cargo-clippy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

repo_root=$(git rev-parse --show-toplevel)

# shellcheck disable=SC1091
source "$repo_root/.github/scripts/rust-version.sh" nightly >/dev/null

rustup component add clippy --toolchain="$rust_nightly"
cargo +"$rust_nightly" clippy
11 changes: 11 additions & 0 deletions .github/scripts/cargo-fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

repo_root=$(git rev-parse --show-toplevel)

# shellcheck disable=SC1091
source "$repo_root/.github/scripts/rust-version.sh" nightly >/dev/null

rustup component add rustfmt --toolchain="$rust_nightly"
cargo +"$rust_nightly" fmt --all
10 changes: 10 additions & 0 deletions .github/scripts/cargo-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

repo_root=$(git rev-parse --show-toplevel)

# shellcheck disable=SC1091
source "$repo_root/.github/scripts/rust-version.sh" stable >/dev/null

cargo +"$rust_stable" test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# source this file
#!/usr/bin/env bash

readCargoVariable() {
declare variable="$1"
Expand Down
68 changes: 68 additions & 0 deletions .github/scripts/rust-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

# This file maintains the rust versions for use by CI.
#
# Obtain the environment variables without any automatic toolchain updating:
# $ source <path>/rust-version.sh
#
# Obtain the environment variables updating both stable and nightly, only stable, or
# only nightly:
# $ source <path>/rust-version.sh all
# $ source <path>/rust-version.sh stable
# $ source <path>/rust-version.sh nightly

# Then to build with either stable or nightly:
# $ cargo +"$rust_stable" build
# $ cargo +"$rust_nightly" build

repo_root=$(git rev-parse --show-toplevel)

# stable version
if [[ -n $RUST_STABLE_VERSION ]]; then
stable_version="$RUST_STABLE_VERSION"
else
# shellcheck disable=SC1090,SC1091
source "$repo_root/.github/scripts/read-cargo-variable.sh"
stable_version=$(readCargoVariable channel "$repo_root/rust-toolchain.toml")
fi

# nightly version
if [[ -n $RUST_NIGHTLY_VERSION ]]; then
nightly_version="$RUST_NIGHTLY_VERSION"
else
nightly_version=2024-01-05
fi

export rust_stable="$stable_version"
export rust_nightly=nightly-"$nightly_version"

if [ $# -ne 1 ]; then
echo "Usage: $0 [all|stable|nightly]"
exit 1
fi

case $1 in
all)
toolchains=("$rust_stable" "$rust_nightly")
;;
stable)
toolchains=("$rust_stable")
;;
nightly)
toolchains=("$rust_nightly")
;;
*)
echo "Usage: $0 [all|stable|nightly]"
exit 1
;;
esac

for toolchain in "${toolchains[@]}"; do
if ! cargo +"$toolchain" -V >/dev/null; then
echo "$0: installing $toolchain"
rustup install "$toolchain"
cargo +"$toolchain" -V
else
echo "$0: $toolchain has already installed."
fi
done
26 changes: 26 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Audit

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- .github/**
- "**/Cargo.toml"
- "**/Cargo.lock"
schedule:
- cron: "0 4 * * *"

jobs:
main:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Audit"
run: |
.github/scripts/cargo-audit.sh
27 changes: 27 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rust
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
main:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Fmt"
run: |
.github/scripts/cargo-fmt.sh
- name: "Clippy"
run: |
.github/scripts/cargo-clippy.sh
- name: "Test"
run: |
.github/scripts/cargo-test.sh
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 0 additions & 70 deletions ci/rust-version.sh

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/cargo-fmt.sh

This file was deleted.

0 comments on commit c77e61b

Please sign in to comment.