]> git.lizzy.rs Git - rust.git/blob - .github/workflows/ci.yml
Auto merge of #2479 - saethlin:tag-gc, r=oli-obk
[rust.git] / .github / workflows / ci.yml
1 name: CI
2
3 on:
4   push:
5     # Run in PRs and for bors, but not on master.
6     branches:
7       - 'auto'
8       - 'try'
9   pull_request:
10     branches:
11       - 'master'
12   schedule:
13     - cron: '5 15 * * *' # At 15:05 UTC every day.
14
15 jobs:
16   build:
17     runs-on: ${{ matrix.os }}
18     env:
19       RUST_BACKTRACE: 1
20       HOST_TARGET: ${{ matrix.host_target }}
21     strategy:
22       matrix:
23         build: [linux64, macos, win32]
24         include:
25           - build: linux64
26             os: ubuntu-latest
27             host_target: x86_64-unknown-linux-gnu
28           - build: macos
29             os: macos-latest
30             host_target: x86_64-apple-darwin
31           - build: win32
32             os: windows-latest
33             host_target: i686-pc-windows-msvc
34     steps:
35       - uses: actions/checkout@v3
36
37       - name: Set the tag GC interval to 1 on linux
38         if: runner.os == 'macOS'
39         run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV
40
41       # We install gnu-tar because BSD tar is buggy on macOS builders of GHA.
42       # See <https://github.com/actions/cache/issues/403>.
43       - name: Install GNU tar
44         if: runner.os == 'macOS'
45         run: |
46           brew install gnu-tar
47           echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
48
49       # Cache the global cargo directory, but NOT the local `target` directory which
50       # we cannot reuse anyway when the nightly changes (and it grows quite large
51       # over time).
52       - name: Add cache for cargo
53         id: cache
54         uses: actions/cache@v3
55         with:
56           path: |
57             # Taken from <https://doc.rust-lang.org/nightly/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci>.
58             ~/.cargo/bin
59             ~/.cargo/registry/index
60             ~/.cargo/registry/cache
61             ~/.cargo/git/db
62             # contains package information of crates installed via `cargo install`.
63             ~/.cargo/.crates.toml
64             ~/.cargo/.crates2.json
65           key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', 'cargo-miri/src/version.rs') }}
66           restore-keys: ${{ runner.os }}-cargo
67
68       - name: Install rustup-toolchain-install-master and xargo
69         if: ${{ steps.cache.outputs.cache-hit == 'false' }}
70         shell: bash
71         run: |
72           cargo install rustup-toolchain-install-master
73           cargo install xargo
74
75       - name: Install "master" toolchain
76         shell: bash
77         run: |
78           if [[ ${{ github.event_name }} == 'schedule' ]]; then
79             ./rustup-toolchain HEAD --host ${{ matrix.host_target }}
80           else
81             ./rustup-toolchain "" --host ${{ matrix.host_target }}
82           fi
83
84       - name: Show Rust version
85         run: |
86           rustup show
87           rustc -Vv
88           cargo -V
89
90       - name: Test
91         run: bash ./ci.sh
92
93   style:
94     name: style checks
95     runs-on: ubuntu-latest
96     steps:
97       - uses: actions/checkout@v3
98       - name: Install required toolchain
99         # We need a toolchain that can actually build Miri, just a nightly won't do.
100         run: |
101           cargo install rustup-toolchain-install-master # TODO: cache this?
102           ./rustup-toolchain "" -c clippy
103       - name: rustfmt
104         run: ./miri fmt --check
105       - name: clippy
106         run: ./miri clippy -- -D warnings
107       - name: rustdoc
108         run: RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items
109
110   # These jobs doesn't actually test anything, but they're only used to tell
111   # bors the build completed, as there is no practical way to detect when a
112   # workflow is successful listening to webhooks only.
113   #
114   # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
115   # (`fmt` is deliberately not listed, we want bors to ignore it.)
116   end-success:
117     name: bors build finished
118     runs-on: ubuntu-latest
119     needs: [build, style]
120     if: github.event.pusher.name == 'bors' && success()
121     steps:
122       - name: mark the job as a success
123         run: exit 0
124   end-failure:
125     name: bors build finished
126     runs-on: ubuntu-latest
127     needs: [build, style]
128     if: github.event.pusher.name == 'bors' && (failure() || cancelled())
129     steps:
130       - name: mark the job as a failure
131         run: exit 1
132
133   # Send a Zulip notification when a cron job fails
134   cron-fail-notify:
135     name: cronjob failure notification
136     runs-on: ubuntu-latest
137     needs: [build, style]
138     if: github.event_name == 'schedule' && (failure() || cancelled())
139     steps:
140       - name: Install zulip-send
141         run: pip3 install zulip
142       - name: Send Zulip notification
143         shell: bash
144         env:
145           ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }}
146           ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }}
147         run: |
148           ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri, $(date -u +%Y-%m))" \
149             --message 'Dear @*T-miri*,
150
151           It would appear that the Miri cron job build failed. Would you mind investigating this issue?
152
153           Thanks in advance!
154           Sincerely,
155           The Miri Cronjobs Bot' \
156             --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com