]> git.lizzy.rs Git - rust.git/blob - .github/workflows/clippy.yml
Add Clippy Test to GHA
[rust.git] / .github / workflows / clippy.yml
1 name: Clippy Test
2
3 on:
4   push:
5     # Ignore bors branches, since they are covered by `clippy_bors.yml`
6     branches-ignore: [auto, try]
7     # Don't run Clippy tests, when only textfiles were modified
8     paths-ignore:
9     - 'COPYRIGHT'
10     - 'LICENSE-*'
11     - '**.md'
12     - '**.txt'
13   pull_request:
14     # Don't run Clippy tests, when only textfiles were modified
15     paths-ignore:
16     - 'COPYRIGHT'
17     - 'LICENSE-*'
18     - '**.md'
19     - '**.txt'
20
21 env:
22   RUST_BACKTRACE: 1
23   CARGO_TARGET_DIR: '${{ github.workspace }}/target'
24   GHA_CI: 1
25
26 jobs:
27   base:
28     runs-on: ubuntu-latest
29
30     steps:
31     - name: rust-toolchain
32       uses: actions-rs/toolchain@v1.0.3
33       with:
34         toolchain: nightly
35         target: x86_64-unknown-linux-gnu
36         profile: minimal
37     - name: Cache cargo dir
38       uses: actions/cache@v1
39       with:
40         path: ~/.cargo
41         key: ${{ runner.os }}-x86_64-unknown-linux-gnu
42     - name: Checkout
43       uses: actions/checkout@v2.0.0
44     - name: Master Toolchain Setup
45       run: bash setup-toolchain.sh
46
47     - name: Set LD_LIBRARY_PATH (Linux)
48       run: |
49         SYSROOT=$(rustc --print sysroot)
50         echo "::set-env name=LD_LIBRARY_PATH::${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}"
51     - name: Build
52       run: cargo build --features deny-warnings
53     - name: Test
54       run: cargo test --features deny-warnings
55     - name: Test clippy_lints
56       run: cargo test --features deny-warnings
57       working-directory: clippy_lints
58     - name: Test rustc_tools_util
59       run: cargo test --features deny-warnings
60       working-directory: rustc_tools_util
61     - name: Test clippy_dev
62       run: cargo test --features deny-warnings
63       working-directory: clippy_dev
64     - name: Test cargo-clippy
65       run: ../target/debug/cargo-clippy
66       working-directory: clippy_workspace_tests
67     - name: Test clippy-driver
68       run: |
69         (
70           set -ex
71           # Check sysroot handling
72           sysroot=$(./target/debug/clippy-driver --print sysroot)
73           test "$sysroot" = "$(rustc --print sysroot)"
74
75           desired_sysroot=/tmp
76           sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
77           test "$sysroot" = $desired_sysroot
78
79           sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot)
80           test "$sysroot" = $desired_sysroot
81
82           # Make sure this isn't set - clippy-driver should cope without it
83           unset CARGO_MANIFEST_DIR
84
85           # Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
86           # FIXME: How to match the clippy invocation in compile-test.rs?
87           ./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr && exit 1
88           sed -e 's,tests/ui,$DIR,' -e '/= help/d' cstring.stderr > normalized.stderr
89           diff normalized.stderr tests/ui/cstring.stderr
90
91           # TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
92         )
93
94     - name: Run cargo-cache --autoclean
95       run: |
96         cargo install cargo-cache --debug
97         find ~/.cargo/bin ! -type d -exec strip {} \;
98         cargo cache --autoclean