Skip to content

Commit

Permalink
feat: Add support links
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Apr 16, 2024
1 parent cc2d318 commit e487206
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 98 deletions.
181 changes: 90 additions & 91 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ on:
pull_request:
push:
branches:
- master
- master

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
CLICOLOR: 1

Expand All @@ -19,7 +18,7 @@ jobs:
permissions:
contents: none
name: CI
needs: [test, msrv, docs, rustfmt, clippy]
needs: [ test, msrv, docs, rustfmt, clippy ]
runs-on: ubuntu-latest
steps:
- name: Done
Expand All @@ -28,115 +27,115 @@ jobs:
name: Test
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
rust: ["stable"]
os: [ "ubuntu-latest", "windows-latest", "macos-latest" ]
rust: [ "stable" ]
continue-on-error: ${{ matrix.rust != 'stable' }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- name: Build Debug
run: cargo test --no-run
- name: Test Debug
run: cargo test
- name: Build Release
run: cargo test --no-run --release
- name: Test Release
run: cargo test --release
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- name: Build Debug
run: cargo test --no-run
- name: Test Debug
run: cargo test --workspace
- name: Build Release
run: cargo test --no-run --release --workspace
- name: Test Release
run: cargo test --release --workspace
msrv:
name: "Check MSRV: 1.72"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.72" # MSRV
- uses: Swatinem/rust-cache@v2
- name: Default features
run: cargo check --workspace --all-targets
- name: No-default features
run: cargo check --workspace --all-targets --no-default-features
- name: Release
run: cargo check --workspace --all-targets --release
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.72" # MSRV
- uses: Swatinem/rust-cache@v2
- name: Default features
run: cargo check --workspace --all-targets
- name: No-default features
run: cargo check --workspace --all-targets --no-default-features
- name: Release
run: cargo check --workspace --all-targets --release
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: "Is lockfile updated?"
run: cargo fetch --locked
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: "Is lockfile updated?"
run: cargo fetch --locked
docs:
name: Docs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --workspace --no-deps --document-private-items
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --workspace --no-deps --document-private-items
rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
# Not MSRV because its harder to jump between versions and people are
# more likely to have stable
toolchain: stable
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
# Not MSRV because its harder to jump between versions and people are
# more likely to have stable
toolchain: stable
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
clippy:
name: clippy
runs-on: ubuntu-latest
permissions:
security-events: write # to upload sarif results
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.72" # MSRV
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Install SARIF tools
run: cargo install clippy-sarif --version 0.3.4 --locked # Held back due to msrv
- name: Install SARIF tools
run: cargo install sarif-fmt --version 0.3.4 --locked # Held back due to msrv
- name: Check
run: >
cargo clippy --workspace --all-targets --message-format=json -- -D warnings --allow deprecated
| clippy-sarif
| tee clippy-results.sarif
| sarif-fmt
continue-on-error: true
- name: Upload
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: clippy-results.sarif
wait-for-processing: true
- name: Report status
run: cargo clippy --workspace --all-targets -- -D warnings --allow deprecated
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.72" # MSRV
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Install SARIF tools
run: cargo install clippy-sarif --version 0.3.4 --locked # Held back due to msrv
- name: Install SARIF tools
run: cargo install sarif-fmt --version 0.3.4 --locked # Held back due to msrv
- name: Check
run: >
cargo clippy --workspace --all-targets --message-format=json -- -D warnings --allow deprecated
| clippy-sarif
| tee clippy-results.sarif
| sarif-fmt
continue-on-error: true
- name: Upload
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: clippy-results.sarif
wait-for-processing: true
- name: Report status
run: cargo clippy --workspace --all-targets -- -D warnings --allow deprecated
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "stable"
18 changes: 15 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct Metadata {
pub authors: Cow<'static, str>,
/// The URL of the crate's website
pub homepage: Cow<'static, str>,
/// The support information
pub supports: Cow<'static, str>,
}

/// Initialize [`Metadata`]
Expand All @@ -75,6 +77,7 @@ macro_rules! metadata {
name: env!("CARGO_PKG_NAME").into(),
authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(),
homepage: env!("CARGO_PKG_HOMEPAGE").into(),
supports: Default::default(),
}
}};
}
Expand All @@ -98,7 +101,8 @@ macro_rules! metadata {
/// name: env!("CARGO_PKG_NAME").into(),
/// version: env!("CARGO_PKG_VERSION").into(),
/// authors: "My Company Support <[email protected]>".into(),
/// homepage: "support.mycompany.com".into(),
/// homepage: "www.mycompany.com".into(),
/// supports: "- Open a support request by email to [email protected]".into(),
/// });
/// ```
#[macro_export]
Expand Down Expand Up @@ -180,8 +184,13 @@ fn write_msg<P: AsRef<Path>>(
file_path: Option<P>,
meta: &Metadata,
) -> IoResult<()> {
let (_version, name, authors, homepage) =
(&meta.version, &meta.name, &meta.authors, &meta.homepage);
let Metadata {
name,
authors,
homepage,
supports,
..
} = meta;

writeln!(buffer, "Well, this is embarrassing.\n")?;
writeln!(
Expand All @@ -207,6 +216,9 @@ fn write_msg<P: AsRef<Path>>(
if !authors.is_empty() {
writeln!(buffer, "- Authors: {authors}")?;
}
if !supports.is_empty() {
writeln!(buffer, "\nTo submit the crash report:\n\n{supports}")?;
}
writeln!(
buffer,
"\nWe take privacy seriously, and do not perform any \
Expand Down
3 changes: 2 additions & 1 deletion tests/custom-panic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ fn main() {
name: env!("CARGO_PKG_NAME").into(),
version: env!("CARGO_PKG_VERSION").into(),
authors: "My Company Support <[email protected]".into(),
homepage: "support.mycompany.com".into(),
homepage: "www.mycompany.com".into(),
supports: "- Open a support request by email to [email protected]".into()
});

println!("A normal log message");
Expand Down
9 changes: 7 additions & 2 deletions tests/custom-panic/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ custom-panic-test had a problem and crashed. To help us diagnose the problem you
We have generated a report file at \"[..].toml\". Submit an issue or email with the subject of \"custom-panic-test Crash Report\" and include the report as an attachment.
- Homepage: support.mycompany.com
- Homepage: www.mycompany.com
- Authors: My Company Support <[email protected]
To submit the crash report:
- Open a support request by email to [email protected]
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
Thank you kindly!
Expand All @@ -29,7 +33,8 @@ fn debug() {
.assert()
.stderr_matches(
"\
thread 'main' panicked at 'OMG EVERYTHING IS ON FIRE!!!', tests/custom-panic/src/main.rs:12:3
thread 'main' panicked at tests/custom-panic/src/main.rs:13:5:
OMG EVERYTHING IS ON FIRE!!!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
",
)
Expand Down
3 changes: 2 additions & 1 deletion tests/single-panic/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ fn debug() {
.assert()
.stderr_matches(
"\
thread 'main' panicked at 'OMG EVERYTHING IS ON FIRE!!!', tests/single-panic/src/main.rs:7:3
thread 'main' panicked at tests/single-panic/src/main.rs:7:5:
OMG EVERYTHING IS ON FIRE!!!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
",
)
Expand Down

0 comments on commit e487206

Please sign in to comment.