Pārlūkot izejas kodu

Add more tests to gitlab-ci.yml

onyinyang 1 gadu atpakaļ
vecāks
revīzija
2c0a0ec15a
2 mainītis faili ar 102 papildinājumiem un 3 dzēšanām
  1. 43 3
      .gitlab-ci.yml
  2. 59 0
      maint/rust-maint-common/via-cargo-install-in-ci

+ 43 - 3
.gitlab-ci.yml

@@ -1,12 +1,52 @@
 image: "rust:latest"
 
-test:cargo:
+variables:
+  # move cargo data into the project directory so it can be cached
+  CARGO_HOME: ${CI_PROJECT_DIR}/.cargo
+  # treat compiler warnings as errors (in clippy, when running tests, etc.)
+  RUSTFLAGS: -Dwarnings
+
+default:
+  # cancel the job if a newer pipeline starts for the same MR or branch
+  interruptible: true
+  cache:
+    # use the git branch or tag as cache key, so the cache will be
+    # shared among CI runs for the same branch or tag
+    key: ${CI_COMMIT_REF_SLUG}
+    # we cache .cargo/ and target/, which effectively enables
+    # incremental builds across different executions of the CI
+    # for the same branch or the same merge request
+    paths:
+      - .cargo
+      - target
+
+cargo:fmt:
   script:
     - rustc --version && cargo --version  # Print version info for debugging
-    - cargo test --workspace --verbose
+    - rustup component add rustfmt
+    - cargo fmt --check
+
+cargo:audit:
+  # This can start to fail even when our code doesn't change.
+  # Usually the new advisory is not a huge concern.
+  # Run it last, separately, so if we think we may want to merge anyway,
+  # all the other tests will have been run.
+  script:
+    - ./maint/rust-maint-common/via-cargo-install-in-ci cargo-audit
+    - cargo audit -D warnings
+  cache:
+    paths:
+      - cache
+
+cargo:clippy:
+  script:
+    - rustup component add clippy
+    - cargo clippy --all-features --workspace -- -D warnings
+
 
 test:lox-unit:
+    # this job is only run if clippy passes
    script:
-     - cargo test --features bridgeauth
+     - cargo test --workspace --verbose
    artifacts:
      when: always

+ 59 - 0
maint/rust-maint-common/via-cargo-install-in-ci

@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+#
+# Usage:
+#   maint/via-cargo-install-in-ci PACKAGE [CARGO ARGS..]
+#
+# Installs PACKAGE with `cargo install --locked`.
+#
+# You should consider whether to specify `--version`:
+# without that, you're no longer hermetic;
+# instead, you'll pic up upstream updates to that cargo package.
+#
+# Reuses a previously-built binary if it's found in the cache.
+# The directory `cache/` should be cached by .gitlab-ci.yml:
+#
+#  some-job:
+#    script:
+#      - maint/via-cargo-install-in-ci cargo-audit
+#    cache:
+#      paths:
+#        - cache
+#
+# If the file `maint/via-cargo-install-in-ci.cache-id` exists,
+# its contents are used as part of the cache key,
+# so that the cache is invalidated (and all packages rebuilt)
+# when that id changes.
+#
+# (The cache key also includes all of the arguments,
+# including the package name.)
+
+set -euo pipefail
+
+badusage () { echo >&2 "$0: bad usage: $1"; exit 8; }
+
+id_file=maint/via-cargo-install-in-ci.cache-id
+
+case "$1" in
+    -*) badusage 'first argument must be command (package)' ;;
+esac
+
+cache="$*"
+cmd="$1"; shift
+
+case "${1-}" in
+    [^-]*) badusage 'subsequent arguments must be options to cargo install' ;;
+esac
+
+if [ -e "$id_file" ]; then
+    read -r <"$id_file" extra_id
+    cache+="  id=$extra_id"
+fi
+
+cache="${cache// /,}"
+cache="cache/$cache"
+
+if cp -v "$cache" "$CARGO_HOME"/bin/"$cmd"; then exit 0; fi
+
+mkdir -p cache
+cargo install --locked "$@" "$cmd"
+cp -v "$CARGO_HOME/bin/$cmd" "$cache"