• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: CI
2
3on:
4  push:
5    branches:
6    - master
7    - "v0.1.x"
8  pull_request: {}
9
10env:
11  # Disable incremental compilation.
12  #
13  # Incremental compilation is useful as part of an edit-build-test-edit cycle,
14  # as it lets the compiler avoid recompiling code that hasn't changed. However,
15  # on CI, we're not making small edits; we're almost always building the entire
16  # project from scratch. Thus, incremental compilation on CI actually
17  # introduces *additional* overhead to support making future builds
18  # faster...but no future builds will ever occur in any given CI environment.
19  #
20  # See https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
21  # for details.
22  CARGO_INCREMENTAL: 0
23  # Allow more retries for network requests in cargo (downloading crates) and
24  # rustup (installing toolchains). This should help to reduce flaky CI failures
25  # from transient network timeouts or other issues.
26  CARGO_NET_RETRY: 10
27  RUSTUP_MAX_RETRIES: 10
28  # Don't emit giant backtraces in the CI logs.
29  RUST_BACKTRACE: short
30  MSRV: 1.49.0
31  # TODO: remove this once tracing's MSRV is bumped.
32  APPENDER_MSRV: 1.53.0
33
34jobs:
35  ### check jobs ###
36
37  check:
38    # Run `cargo check` first to ensure that the pushed code at least compiles.
39    name: cargo check
40    runs-on: ubuntu-latest
41    steps:
42    - uses: actions/checkout@v3
43    - uses: actions-rs/toolchain@v1
44      with:
45        toolchain: stable
46        profile: minimal
47        override: true
48    - name: Check
49      uses: actions-rs/cargo@v1
50      with:
51        command: check
52        args: --all --tests --benches
53
54  style:
55    # Check style.
56    name: cargo fmt
57    needs: check
58    runs-on: ubuntu-latest
59    steps:
60    - uses: actions/checkout@v3
61    - uses: actions-rs/toolchain@v1
62      with:
63        toolchain: stable
64        components: rustfmt
65        profile: minimal
66        override: true
67    - name: rustfmt
68      uses: actions-rs/cargo@v1
69      with:
70        command: fmt
71        args: --all -- --check
72
73  warnings:
74    # Check for any warnings. This is informational and thus is allowed to fail.
75    runs-on: ubuntu-latest
76    needs: check
77    steps:
78    - uses: actions/checkout@v3
79    - uses: actions-rs/toolchain@v1
80      with:
81        toolchain: stable
82        components: clippy
83        profile: minimal
84    - name: Clippy
85      uses: actions-rs/clippy-check@v1
86      with:
87        token: ${{ secrets.GITHUB_TOKEN }}
88        args: --all --examples --tests --benches -- -D warnings
89
90  minimal-versions:
91    # Check for minimal-versions errors where a dependency is too
92    # underconstrained to build on the minimal supported version of all
93    # dependencies in the dependency graph.
94    name: cargo check (-Zminimal-versions)
95    needs: check
96    runs-on: ubuntu-latest
97    steps:
98      - uses: actions/checkout@v3
99      - uses: actions-rs/toolchain@v1
100        with:
101          toolchain: nightly
102          profile: minimal
103          override: true
104      - name: install cargo-hack
105        uses: taiki-e/install-action@cargo-hack
106      - name: "check --all-features -Z minimal-versions"
107        run: |
108          # Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
109          # from determining minimal versions based on dev-dependencies.
110          cargo hack --remove-dev-deps --workspace
111          # Update Cargo.lock to minimal version dependencies.
112          cargo update -Z minimal-versions
113          cargo hack check \
114            --package tracing \
115            --package tracing-core \
116            --package tracing-subscriber \
117            --all-features --ignore-private
118
119  cargo-hack:
120    needs: check
121    name: cargo check (feature combinations)
122    runs-on: ubuntu-latest
123    strategy:
124      matrix:
125        # cargo hack --feature-powerset will have a significant permutation
126        # number, we can't just use --all as it increases the runtime
127        # further than what we would like to
128        subcrate:
129        - tracing-attributes
130        - tracing-core
131        - tracing-futures
132        - tracing-log
133        - tracing-macros
134        - tracing-serde
135        - tracing-tower
136        - tracing-opentelemetry
137        - tracing
138        - tracing-subscriber
139    steps:
140    - uses: actions/checkout@v3
141    - uses: actions-rs/toolchain@v1
142      with:
143        toolchain: stable
144        profile: minimal
145        override: true
146
147    - name: install cargo-hack
148      uses: taiki-e/install-action@cargo-hack
149    - name: cargo hack check
150      working-directory: ${{ matrix.subcrate }}
151      # tracing and tracing-subscriber have too many features to be checked by
152      # cargo-hack --feature-powerset with all features in the powerset, so
153      # exclude some
154      run: |
155        CARGO_HACK=(cargo hack check --feature-powerset --no-dev-deps)
156        case "${{ matrix.subcrate }}" in
157          tracing)
158            EXCLUDE_FEATURES=(
159              max_level_off max_level_error max_level_warn max_level_info
160              max_level_debug max_level_trace release_max_level_off
161              release_max_level_error release_max_level_warn
162              release_max_level_info release_max_level_debug
163              release_max_level_trace
164            )
165            ${CARGO_HACK[@]} --exclude-features "${EXCLUDE_FEATURES[*]}"
166            ;;
167          tracing-subscriber)
168            INCLUDE_FEATURES=(fmt ansi json registry env-filter)
169            ${CARGO_HACK[@]} --include-features "${INCLUDE_FEATURES[*]}"
170            ;;
171          *)
172            ${CARGO_HACK[@]}
173            ;;
174        esac
175      shell: bash
176
177  check-msrv:
178    # Run `cargo check` on our minimum supported Rust version (1.49.0).
179    name: "cargo check (MSRV on ubuntu-latest)"
180    needs: check
181    runs-on: ubuntu-latest
182    steps:
183    - uses: actions/checkout@v3
184    - name: "install Rust ${{ env.MSRV }}"
185      uses: actions-rs/toolchain@v1
186      with:
187        toolchain: ${{ env.MSRV }}
188        profile: minimal
189    - name: "install Rust nightly"
190      uses: actions-rs/toolchain@v1
191      with:
192        toolchain: nightly
193        profile: minimal
194    - name: Select minimal versions
195      uses: actions-rs/cargo@v1
196      with:
197        command: update
198        args: -Z minimal-versions
199        toolchain: nightly
200    - name: Check
201      uses: actions-rs/cargo@v1
202      with:
203        command: check
204        # skip the following crates:
205        # - tracing-appender, as it has its own MSRV.
206        #   TODO(eliza): remove this when appender is on the same MSRV as
207        #   everything else
208        # - the examples, as they are not published & we don't care about
209        #   MSRV support for them.
210        # - tracing-futures, as it depends on ancient tokio versions.
211        #   TODO(eliza): remove this when the ancient tokio deps are dropped
212        args: >-
213          --workspace --all-features --locked
214          --exclude=tracing-appender
215          --exclude=tracing-examples
216          --exclude=tracing-futures
217          --exclude=tracing-opentelemetry
218        toolchain: ${{ env.MSRV }}
219
220  # TODO: remove this once tracing's MSRV is bumped.
221  check-msrv-appender:
222    # Run `cargo check` on our minimum supported Rust version (1.53.0).
223    name: "cargo check (tracing-appender MSRV)"
224    needs: check
225    runs-on: ubuntu-latest
226    steps:
227    - uses: actions/checkout@v3
228    - name: "install Rust ${{ env.APPENDER_MSRV }}"
229      uses: actions-rs/toolchain@v1
230      with:
231        toolchain: ${{ env.APPENDER_MSRV }}
232        profile: minimal
233    - name: "install Rust nightly"
234      uses: actions-rs/toolchain@v1
235      with:
236        toolchain: nightly
237        profile: minimal
238    - name: Select minimal versions
239      uses: actions-rs/cargo@v1
240      with:
241        command: update
242        args: -Z minimal-versions
243        toolchain: nightly
244    - name: Check
245      uses: actions-rs/cargo@v1
246      with:
247        command: check
248        args: --all-features --locked -p tracing-appender
249        toolchain: ${{ env.APPENDER_MSRV }}
250
251  ### test jobs #############################################################
252
253  test:
254    # Test against stable Rust across macOS, Windows, and Linux, and against
255    # beta and nightly rust on Ubuntu.
256    name: "cargo test (${{ matrix.rust }} on ${{ matrix.os }})"
257    needs: check
258    strategy:
259      matrix:
260        # test all Rust versions on ubuntu-latest
261        os: [ubuntu-latest]
262        rust: [stable, beta, nightly]
263        # test stable Rust on Windows and MacOS as well
264        include:
265          - rust: stable
266            os: windows-latest
267          - rust: stable
268            os: macos-latest
269      fail-fast: false
270    runs-on: ${{ matrix.os }}
271    steps:
272    - uses: actions/checkout@v3
273    - uses: actions-rs/toolchain@v1
274      with:
275        toolchain: ${{ matrix.rust }}
276        profile: minimal
277        override: true
278    - name: install cargo-nextest
279      uses: taiki-e/install-action@nextest
280    - name: Run tests
281      run: cargo nextest run --profile ci --workspace
282    # TODO(eliza): punt on this for now because the generated JUnit report is
283    # missing some fields that this action needs to give good output.
284    # - name: Publish Test Report
285    #   uses: mikepenz/action-junit-report@v3
286    #   if: always() # always run even if the previous step fails
287    #   with:
288    #     report_paths: 'target/nextest/ci/junit.xml'
289    #     check_name: "cargo test (Rust ${{ matrix.rust }} on ${{ matrix.os }})"
290    #     check_title_template: "{{SUITE_NAME}}::{{TEST_NAME}}"
291    - name: Run doctests
292      run: cargo test --doc --workspace
293
294  test-build-wasm:
295    name: build tests (wasm)
296    needs: check
297    runs-on: ubuntu-latest
298    strategy:
299      matrix:
300        # TODO(securityinsanity): slowly add wasm32 test runner to each crate, and move to seperate actions that run tests.
301        subcrate:
302        - tracing-appender
303        - tracing-attributes
304        - tracing-core
305        - tracing-error
306        - tracing-flame
307        - tracing-journald
308        - tracing-log
309        - tracing-macros
310        - tracing-opentelemetry
311        - tracing-serde
312        - tracing-subscriber
313        - tracing-tower
314      fail-fast: false
315    steps:
316    - uses: actions/checkout@v3
317    - uses: actions-rs/toolchain@v1
318      with:
319        target: wasm32-unknown-unknown
320        toolchain: stable
321        override: true
322    - name: build all tests
323      uses: actions-rs/cargo@v1
324      with:
325        command: test
326        args: --no-run -p ${{ matrix.subcrate }}
327
328  test-wasm:
329    name: cargo test (wasm)
330    needs: check
331    runs-on: ubuntu-latest
332    strategy:
333      matrix:
334        subcrate:
335        - tracing
336    steps:
337    - uses: actions/checkout@v3
338    - uses: actions-rs/toolchain@v1
339      with:
340        target: wasm32-unknown-unknown
341        toolchain: stable
342        override: true
343    - name: install test runner for wasm
344      uses: taiki-e/install-action@wasm-pack
345    - name: run wasm tests
346      run: cd ${{ matrix.subcrate }} && wasm-pack test --node
347
348  test-features-stable:
349    # Feature flag tests that run on stable Rust.
350    # TODO(david): once tracing's MSRV goes up to Rust 1.51, we should be able to switch to
351    # using cargo's V2 feature resolver (https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions)
352    # and avoid cd'ing into each crate's directory.
353    name: cargo test (feature-specific)
354    needs: check
355    runs-on: ubuntu-latest
356    steps:
357    - uses: actions/checkout@v3
358    - uses: actions-rs/toolchain@v1
359      with:
360        toolchain: stable
361        profile: minimal
362        override: true
363    - name: "Test log support"
364      run: cargo test
365      working-directory: "tracing/test-log-support"
366    - name: "Test static max level"
367      run: cargo test
368      working-directory: "tracing/test_static_max_level_features"
369    - name: "Test static max level (release)"
370      run: cargo test --release
371      working-directory: "tracing/test_static_max_level_features"
372    - name: "Test tracing-core no-std support"
373      run: cargo test --no-default-features
374      working-directory: tracing-core
375    - name: "Test tracing no-std support"
376      run: cargo test --lib --no-default-features
377      working-directory: tracing
378      # this skips running doctests under the `--no-default-features` flag,
379      # as rustdoc isn't aware of cargo's feature flags.
380    - name: "Test tracing-subscriber no-std support"
381      run: cargo test --lib --tests --no-default-features
382      working-directory: tracing-subscriber
383    - name: "Test tracing-subscriber with liballoc only"
384      run: cargo test --lib --tests --no-default-features --features "alloc"
385      working-directory: tracing-subscriber
386    - name: "Test tracing-subscriber with no default features"
387      run: cargo test --lib --tests --no-default-features --features "std"
388      working-directory: tracing-subscriber
389
390  # all required checks except for the main test run (which we only require
391  # specific matrix combinations from)
392  all_required:
393    name: "all systems go!"
394    runs-on: ubuntu-latest
395    needs:
396      - style
397      - minimal-versions
398      - cargo-hack
399      - check-msrv
400      - check-msrv-appender
401      - test-build-wasm
402      - test-wasm
403      - test-features-stable
404    steps:
405      - run: exit 0
406