Skip to content

Commit 1240bb4

Browse files
committed
chore: general improvements
1 parent eb77fef commit 1240bb4

File tree

9 files changed

+68
-58
lines changed

9 files changed

+68
-58
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
name: test, analyze and publish
22

33
on:
4-
workflow_run:
5-
workflows: ["Quality Gate"]
6-
types:
7-
- completed
8-
workflow_dispatch:
4+
workflow_run:
5+
workflows: ["Quality Gate"]
6+
types:
7+
- completed
8+
workflow_dispatch:
99

1010
permissions:
1111
contents: write
1212

1313
jobs:
1414
release:
1515
uses: jd-apprentice/jd-workflows/.github/workflows/release.yml@main
16-
if: github.ref == 'refs/heads/main'
16+
if: ${{ github.ref == 'refs/heads/master' && github.event.workflow_run.conclusion == 'success' }}
1717
with:
1818
name: release
1919
runs_on: ubuntu-latest
20+
release_notes: true
2021
secrets:
21-
gh_token: ${{ secrets.GITHUB_TOKEN }}
22+
gh_token: ${{ secrets.GITHUB_TOKEN }}

Cargo.toml.liquid

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
[package]
22
name = "{{ package_name }}"
3+
description = "{{ package_description }}"
34
version = "0.1.0"
45
edition = "2021"
6+
documentation = ""
7+
repository = ""
8+
categories = ["command-line-utilities"]
9+
keywords = ["cli"]
510

611
{% if license == "MIT" %}
712
license = "MIT"
@@ -15,10 +20,10 @@ license = "MIT OR Apache-2.0"
1520

1621
[dependencies]
1722
{% if dotenv == true %}
18-
dotenv = "0.15.0"
23+
dotenvy = "0.15.7"
1924
{% endif %}
2025

2126
{% if sentry == true %}
2227
sentry = "0.34.0"
2328
tokio = { version = "1", features = ["full"] }
24-
{% endif %}
29+
{% endif %}

Makefile.liquid

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dev:
66
build: src/main.rs
77
cargo build --release --bin {{ package_name }}
88

9-
docker:
9+
docker:
1010
docker build -f docker/Dockerfile -t rust_template .
1111

1212
compose:
@@ -16,9 +16,15 @@ test:
1616
cargo test
1717

1818
lint:
19-
cargo clippy -- -D warnings
20-
19+
cargo clippy --all-targets --all-features
20+
21+
lint-fix:
22+
cargo clippy --all-targets --all-features --fix --allow-dirty
23+
2124
format:
2225
cargo fmt --all --check
2326

24-
.PHONY: build docker test lint format compose
27+
format-fix:
28+
cargo fmt --all
29+
30+
.PHONY: build docker test lint format compose

cargo-generate.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
[template]
44
cargo_generate_version = ">=0.22.0"
5-
exclude = ["assets"]
5+
exclude = ["assets/*, Cargo.toml"]
66

77
[placeholders.package_name]
88
type = "string"
99
prompt = "What is the name of the package?"
1010

11+
[placeholders.package_description]
12+
type = "string"
13+
propt = "Enter a project description"
14+
1115
[placeholders.license]
1216
type = "string"
1317
prompt = "What licenses will the project have?"
@@ -47,21 +51,25 @@ default = false
4751
## License
4852

4953
[conditional.'license != "MIT" && license != "all"']
50-
ignore = ["LICENSE-MIT"]
54+
exclude = ["LICENSE-MIT"]
5155

5256
[conditional.'license != "APACHE" && license != "all"']
53-
ignore = ["LICENSE-APACHE"]
57+
exclude = ["LICENSE-APACHE"]
5458

5559
## Workflows
5660
[conditional.'github_release == false']
57-
ignore = [".github/workflows/release.yaml"]
61+
exclude = [".github/workflows/release.yaml"]
5862

5963
## Dependencies
6064
[conditional.'dotenv == false']
61-
ignore = [".env.example"]
65+
exclude = [".env.example"]
6266

6367
[conditional. 'sentry == true']
6468
type = "string"
6569
name = "sentry_dsn"
6670
prompt = "What is your sentry dsn?"
67-
default = "https://examplePublicKey@o0.ingest.sentry.io/0"
71+
default = "https://examplePublicKey@o0.ingest.sentry.io/0"
72+
73+
## Files
74+
[conditional. 'sentry == false']
75+
exclude = ["./src/functions.rs"]

rust-toolchain.toml.liquid

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = {{ toolchain }}
2+
channel = "{{ toolchain }}"
33
profile = "default"
4-
components = ["clippy", "rustfmt"]
4+
components = ["clippy", "rustfmt"]

src/functions.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// # Panics
2+
/// Will panic if `SENTRY_DSN` is not set in the .env file
3+
#[inline]
4+
pub fn load_sentry() {
5+
dotenvy::dotenv().unwrap_or_else(|_| {
6+
panic!("Missing .env file");
7+
});
8+
9+
let sentry_dns = env::var("SENTRY_DSN").unwrap_or_else(|_| {
10+
panic!("Missing SENTRY_DSN environment variable");
11+
});
12+
13+
let _guard = sentry::init((
14+
sentry_dns,
15+
sentry::ClientOptions {
16+
release: sentry::release_name!(),
17+
..Default::default()
18+
},
19+
));
20+
}

src/lib.rs renamed to src/lib.rs.liquid

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
{% if sentry == true %}
2+
mod functions;
3+
pub use functions::load_sentry;
4+
{% endif %}
5+
16
#[derive(Default)]
27
pub struct MathOperation {
38
pub operator: String,

src/main.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main.rs.liquid

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1+
use {{ project_name }}::{load_sentry};
12
use std::thread::sleep;
23

3-
{% if dotenv == true %}
4-
use dotenv;
5-
6-
dotenv::dotenv().ok();
7-
{% endif %}
8-
94
#[path = "1_module/tests/add_sub.rs"]
105
mod add_sub;
116
#[path = "2_module/tests/mul_div.rs"]
127
mod mul_div;
138

149
fn main() {
15-
1610
{% if sentry == true %}
17-
const _config: sentry::ClientInitGuard = sentry::init(({{ sentry_dsn }}, sentry::ClientOptions {
18-
release: sentry::release_name!(),
19-
..Default::default()
20-
}));
11+
load_sentry();
2112
{% endif %}
22-
2313
const SLEEP_MESSAGE: &str = "Sleep forever...";
2414
const HELLO_SENTRY: &str = "Hello, sentry!";
2515
println!("{}", SLEEP_MESSAGE);
2616
sleep(std::time::Duration::from_millis(f64::INFINITY as u64));
27-
28-
{% if sentry == true %}
29-
tokio::runtime::Builder::new_multi_thread()
30-
.enable_all()
31-
.build()
32-
.unwrap()
33-
.block_on(async {
34-
let _ = sentry::capture_message(HELLO_SENTRY, sentry::Level::Info);
35-
println!("{}", HELLO_SENTRY);
36-
});
37-
{% endif %}
3817
}
39-
40-

0 commit comments

Comments
 (0)