CI: split test.yaml to test.yaml and lints.yaml
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>pull/322/head
parent
5ff4e8ae68
commit
0a617410ec
|
@ -0,0 +1,119 @@
|
|||
# SPDX-License-Identifier: EUPL-1.2
|
||||
name: Run cargo lints
|
||||
|
||||
env:
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
|
||||
RUSTFLAGS: "-D warnings -W unreachable-pub -W rust-2021-compatibility"
|
||||
RUSTUP_MAX_RETRIES: 10
|
||||
RUST_BACKTRACE: short
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
paths:
|
||||
- '.gitea/**'
|
||||
- 'melib/src/**'
|
||||
- 'melib/Cargo.toml'
|
||||
- 'meli/src/**'
|
||||
- 'meli/Cargo.toml'
|
||||
- 'Cargo.toml'
|
||||
- 'Cargo.lock'
|
||||
push:
|
||||
paths:
|
||||
- '.gitea/**'
|
||||
- 'melib/src/**'
|
||||
- 'melib/Cargo.toml'
|
||||
- 'meli/src/**'
|
||||
- 'meli/Cargo.toml'
|
||||
- 'Cargo.toml'
|
||||
- 'Cargo.lock'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Lint on ${{ matrix.build }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
build: [linux-amd64, ]
|
||||
include:
|
||||
- build: linux-amd64
|
||||
os: ubuntu-latest
|
||||
rust: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@v2
|
||||
- id: os-deps
|
||||
name: install OS dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y libdbus-1-dev pkg-config mandoc libssl-dev
|
||||
#- id: cache-rustup
|
||||
# name: Cache Rust toolchain
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: ~/.rustup
|
||||
# key: toolchain-${{ matrix.os }}-${{ matrix.rust }}
|
||||
#- if: ${{ steps.cache-rustup.outputs.cache-hit != 'true' }}
|
||||
- id: rustup-setup
|
||||
name: Install Rustup and toolchains
|
||||
shell: bash
|
||||
run: |
|
||||
if ! command -v rustup &>/dev/null; then
|
||||
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location --silent --show-error --fail "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
|
||||
source "${HOME}/.cargo/env"
|
||||
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
|
||||
rustup toolchain install --profile minimal --component clippy,rustfmt ${{ matrix.rust }} --target ${{ matrix.target }}
|
||||
fi
|
||||
- name: Configure cargo data directory
|
||||
# After this point, all cargo registry and crate data is stored in
|
||||
# $GITHUB_WORKSPACE/.cargo_home. This allows us to cache only the files
|
||||
# that are needed during the build process. Additionally, this works
|
||||
# around a bug in the 'cache' action that causes directories outside of
|
||||
# the workspace dir to be saved/restored incorrectly.
|
||||
run: echo "CARGO_HOME=$(pwd)/.cargo_home" >> $GITHUB_ENV
|
||||
#- id: cache-cargo
|
||||
# name: Cache cargo configuration and installations
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
# with:
|
||||
# path: ${{ env.CARGO_HOME }}
|
||||
# key: cargo-${{ matrix.os }}-${{ matrix.rust }}
|
||||
#- if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} && matrix.target
|
||||
- name: Setup Rust target
|
||||
run: |
|
||||
mkdir -p "${{ env.CARGO_HOME }}"
|
||||
cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
|
||||
[build]
|
||||
target = "${{ matrix.target }}"
|
||||
EOF
|
||||
- if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} && matrix.target
|
||||
name: Add lint dependencies
|
||||
run: |
|
||||
cargo install --quiet --version 1.0.9 --target "${{ matrix.target }}" cargo-sort
|
||||
RUSTFLAGS="" cargo install --locked --target "${{ matrix.target }}" --git https://github.com/dcchut/cargo-derivefmt --rev 2ff93de7fb418180458dd1ba27e5655607c23ab6 --bin cargo-derivefmt
|
||||
- name: rustfmt
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo fmt --check --all
|
||||
- name: clippy
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo clippy --no-deps --all-features --all --tests --examples --benches --bins
|
||||
- name: cargo-derivefmt melib
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo derivefmt --manifest-path ./melib/Cargo.toml
|
||||
- name: cargo-derivefmt meli
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo derivefmt --manifest-path ./meli/Cargo.toml
|
||||
- name: cargo-derivefmt fuzz
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo derivefmt --manifest-path ./fuzz/Cargo.toml
|
||||
- name: cargo-derivefmt tools
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo derivefmt --manifest-path ./tools/Cargo.toml
|
|
@ -1,4 +1,5 @@
|
|||
name: Tests
|
||||
# SPDX-License-Identifier: EUPL-1.2
|
||||
name: Run Tests
|
||||
|
||||
env:
|
||||
CARGO_INCREMENTAL: 0
|
||||
|
@ -48,7 +49,7 @@ jobs:
|
|||
name: install OS dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y libdbus-1-dev pkg-config mandoc libssl-dev
|
||||
apt-get install -y libdbus-1-dev pkg-config mandoc libssl-dev make
|
||||
#- id: cache-rustup
|
||||
# name: Cache Rust toolchain
|
||||
# uses: https://github.com/actions/cache@v3
|
||||
|
@ -56,14 +57,16 @@ jobs:
|
|||
# path: ~/.rustup
|
||||
# key: toolchain-${{ matrix.os }}-${{ matrix.rust }}
|
||||
#- if: ${{ steps.cache-rustup.outputs.cache-hit != 'true' }}
|
||||
- name: Install Rust ${{ matrix.rust }}
|
||||
uses: https://github.com/actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
components: clippy, rustfmt
|
||||
target: ${{ matrix.target }}
|
||||
override: true
|
||||
- id: rustup-setup
|
||||
name: Install rustup and toolchains
|
||||
shell: bash
|
||||
run: |
|
||||
if ! command -v rustup &>/dev/null; then
|
||||
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location --silent --show-error --fail "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
|
||||
source "${HOME}/.cargo/env"
|
||||
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
|
||||
rustup toolchain install --profile minimal ${{ matrix.rust }} --target ${{ matrix.target }}
|
||||
fi
|
||||
- name: Configure cargo data directory
|
||||
# After this point, all cargo registry and crate data is stored in
|
||||
# $GITHUB_WORKSPACE/.cargo_home. This allows us to cache only the files
|
||||
|
@ -86,9 +89,8 @@ jobs:
|
|||
target = "${{ matrix.target }}"
|
||||
EOF
|
||||
- if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} && matrix.target
|
||||
name: Add lint dependencies
|
||||
name: Add test dependencies
|
||||
run: |
|
||||
cargo install --quiet --version 1.0.9 --target "${{ matrix.target }}" cargo-sort
|
||||
cargo install --quiet --version 0.9.54 --target "${{ matrix.target }}" cargo-nextest
|
||||
- name: cargo-check
|
||||
run: |
|
||||
|
@ -101,15 +103,7 @@ jobs:
|
|||
run: |
|
||||
cargo nextest run --all --no-fail-fast --all-features --future-incompat-report -E 'not (test(smtp::test::test_smtp))'
|
||||
#cargo test --all --no-fail-fast --all-features -- --nocapture --quiet
|
||||
- name: cargo-sort
|
||||
- name: rustdoc build
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo sort --check
|
||||
- name: rustfmt
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo fmt --check --all
|
||||
- name: clippy
|
||||
if: success() || failure()
|
||||
run: |
|
||||
cargo clippy --no-deps --all-features --all --tests --examples --benches --bins
|
||||
make build-rustdoc
|
||||
|
|
|
@ -1,113 +1,51 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
# Copyright 2016 Google Inc. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||
# This file may not be copied, modified, or distributed except according to those terms.
|
||||
IFS=$'\n'
|
||||
|
||||
#
|
||||
# Pre-commit hook for the tarpc repository. To use this hook, copy it to .git/hooks in your
|
||||
# repository root.
|
||||
#
|
||||
# This precommit checks the following:
|
||||
# 1. All filenames are ascii
|
||||
# 2. There is no bad whitespace
|
||||
# 3. rustfmt is installed
|
||||
# 4. rustfmt is a noop on files that are in the index
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# - TARPC_SKIP_RUSTFMT, default = 0
|
||||
#
|
||||
# Set this to 1 to skip running rustfmt
|
||||
#
|
||||
# Note that these options are most useful for testing the hooks themselves. Use git commit
|
||||
# --no-verify to skip the pre-commit hook altogether.
|
||||
files_without_header=()
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
PREFIX="${GREEN}[PRECOMMIT]${NC}"
|
||||
FAILURE="${RED}FAILED${NC}"
|
||||
WARNING="${RED}[WARNING]${NC}"
|
||||
SKIPPED="${YELLOW}SKIPPED${NC}"
|
||||
SUCCESS="${GREEN}ok${NC}"
|
||||
|
||||
if git rev-parse --verify HEAD &>/dev/null
|
||||
newly_added_files=($(git diff --name-only --diff-filter=A --cached))
|
||||
#newly_added_files=($(git ls-files))
|
||||
if [ -n "${newly_added_files[0]}" ]
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
# Check for Copyright statement
|
||||
for newly_added_file in ${newly_added_files}; do
|
||||
files_without_header+=($(grep -L -e "This file is part of meli" -e "This file is part of melib" -e "SPDX-License-Identifier" "${newly_added_file}"))
|
||||
done
|
||||
|
||||
if [ -n "${files_without_header[0]}" ]
|
||||
then
|
||||
echo "License preamble not found in the following newly added files:"
|
||||
for file in "${files_without_header[@]}"
|
||||
do
|
||||
:
|
||||
echo " - ${file}";
|
||||
done
|
||||
exit 1;
|
||||
else
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
##Debug:
|
||||
#files_without_header+=($(git diff --name-only -S"debug!"))
|
||||
#echo ${files_without_header}
|
||||
|
||||
#if [ -n "${files_without_header}" ]
|
||||
#then
|
||||
# (echo "debug! macro added in the following files:";
|
||||
# echo "";
|
||||
# for file in "${files_without_header[@]}"
|
||||
# do
|
||||
# :
|
||||
# tput bold
|
||||
# echo " - ${file}";
|
||||
# echo "";
|
||||
# tput sgr0;
|
||||
# FORCE_COLOR=true git -c color.status=always diff --color=always -S"debug!" "${file}";
|
||||
# done) | less -R
|
||||
# exit 1;
|
||||
#else
|
||||
# exit 0;
|
||||
#fi
|
||||
fi
|
||||
|
||||
FAILED=0
|
||||
|
||||
printf "${PREFIX} Checking that all filenames are ascii ... "
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
FAILED=1
|
||||
printf "${FAILURE}\n"
|
||||
else
|
||||
printf "${SUCCESS}\n"
|
||||
fi
|
||||
|
||||
printf "${PREFIX} Checking for bad whitespace ... "
|
||||
git diff-index --check --cached $against -- &>/dev/null
|
||||
if [ "$?" != 0 ]; then
|
||||
FAILED=1
|
||||
printf "${FAILURE}\n"
|
||||
else
|
||||
printf "${SUCCESS}\n"
|
||||
fi
|
||||
|
||||
printf "${PREFIX} Checking for shasum ... "
|
||||
command -v shasum &>/dev/null
|
||||
if [ $? == 0 ]; then
|
||||
printf "${SUCCESS}\n"
|
||||
else
|
||||
printf "${FAILURE}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "${PREFIX} Running clippy ... "
|
||||
command -v cargo +nightly clippy &>/dev/null
|
||||
if [ $? == 0 ]; then
|
||||
printf "${SUCCESS}\n"
|
||||
else
|
||||
printf "${FAILURE}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Just check that running rustfmt doesn't do anything to the file. I do this instead of
|
||||
# modifying the file because I don't want to mess with the developer's index, which may
|
||||
# not only contain discrete files.
|
||||
printf "${PREFIX} Checking formatting ... "
|
||||
FMTRESULT=0
|
||||
diff=""
|
||||
for file in $(git diff --name-only --cached);
|
||||
do
|
||||
if [ ${file: -3} == ".rs" ]; then
|
||||
diff="$diff$(rustfmt $file)"
|
||||
fi
|
||||
done
|
||||
if grep --quiet "^Diff at line" <<< "$diff"; then
|
||||
FMTRESULT=1
|
||||
fi
|
||||
|
||||
if [ "${TARPC_SKIP_RUSTFMT}" == 1 ]; then
|
||||
printf "${SKIPPED}\n"$?
|
||||
elif [ ${FMTRESULT} != 0 ]; then
|
||||
FAILED=1
|
||||
printf "${FAILURE}\n"
|
||||
echo "$diff" | sed 's/Using rustfmt config file.*$/d/'
|
||||
else
|
||||
printf "${SUCCESS}\n"
|
||||
fi
|
||||
|
||||
exit ${FAILED}
|
||||
|
|
|
@ -19,6 +19,5 @@
|
|||
|
||||
set -euxo pipefail
|
||||
|
||||
echo "Testing if debug profile builds..."
|
||||
cargo check --all-features
|
||||
cargo test --all-features --workspace
|
||||
make check
|
||||
make lint
|
||||
|
|
Loading…
Reference in New Issue