Skip to content

Commit 7206edd

Browse files
committed
feat: add sentry and dotenv
1 parent 88b38db commit 7206edd

10 files changed

Lines changed: 157 additions & 3 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
YOUR_KEY=""

.github/CODEOWNERS.liquid

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
2+
3+
## Global owners
4+
* @{{ codeowner }}

.github/workflows/release.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: test, analyze and publish
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Quality Gate"]
6+
types:
7+
- completed
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
release:
15+
uses: jd-apprentice/jd-workflows/.github/workflows/release.yml@main
16+
if: github.ref == 'refs/heads/main'
17+
with:
18+
name: release
19+
runs_on: ubuntu-latest
20+
secrets:
21+
gh_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ Cargo.lock
1818
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
1919
# and can be added to the global gitignore or merged into this file. For a more nuclear
2020
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21-
#.idea/
21+
#.idea/
22+
23+
# Environment
24+
.env

.gitignore.liquid

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# MSVC Windows builds of rustc generate these, which store debugging information
14+
*.pdb
15+
16+
# RustRover
17+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
18+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
19+
# and can be added to the global gitignore or merged into this file. For a more nuclear
20+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21+
#.idea/
22+
23+
{% if dotenv == true %}
24+
# Environment variables
25+
.env
26+
{% endif %}

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "jd-rust"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

Cargo.toml.liquid

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ license = "Apache-2.0"
1313
license = "MIT OR Apache-2.0"
1414
{% endif %}
1515

16-
[dependencies]
16+
[dependencies]
17+
{% if dotenv == true %}
18+
dotenv = "0.15.0"
19+
{% endif %}
20+
21+
{% if sentry == true %}
22+
sentry = "0.34.0"
23+
tokio = { version = "1", features = ["full"] }
24+
{% endif %}

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ The project is using [make](https://www.gnu.org/software/make/) and [docker](htt
1818

1919
You can run it with `make dev` for development and `make` for production
2020

21+
## 🦀 Features
22+
23+
- Github Actions (Quality Gate)
24+
- Dockerfile + docker-compose
25+
- Testing + Coverage
26+
- CODEOWNERS
27+
- Docker security (user/group, apparmor, seccomp, capabilities, etc.)
28+
- Github Release (optional)
29+
- Sentry (optional)
30+
- Dotenv (optional)
31+
2132
## 🦀 Contributing
2233

2334
Check the [CONTRIBUTING.md](CONTRIBUTING.md) file

cargo-generate.toml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,50 @@ choices = ["all", "MIT", "APACHE"]
1818
type = "string"
1919
prompt = "What is your email? (CONTRIBUTING, LICENSE, etc)"
2020

21+
[placeholders.codeowner]
22+
type = "string"
23+
prompt = "What is your github username? (CODEOWNERS)"
24+
2125
[placeholders.toolchain.channel]
2226
type = "string"
2327
prompt = "What is the rust toolchain version?"
2428
choices = ["stable", "beta", "nightly"]
2529

30+
[placeholders.github_release]
31+
type = "bool"
32+
prompt = "Do you want to create a github release?"
33+
default = false
34+
35+
## Dependencies
36+
[placeholders.dotenv]
37+
type = "bool"
38+
prompt = "Do you want to use dotenv?"
39+
default = false
40+
41+
[placeholders.sentry]
42+
type = "bool"
43+
prompt = "Do you want to use sentry?"
44+
default = false
45+
2646
# Conditions
2747
## License
2848

2949
[conditional.'license != "MIT" && license != "all"']
3050
ignore = ["LICENSE-MIT"]
3151

3252
[conditional.'license != "APACHE" && license != "all"']
33-
ignore = ["LICENSE-APACHE"]
53+
ignore = ["LICENSE-APACHE"]
54+
55+
## Workflows
56+
[conditional.'github_release == false']
57+
ignore = [".github/workflows/release.yaml"]
58+
59+
## Dependencies
60+
[conditional.'dotenv == false']
61+
ignore = [".env.example"]
62+
63+
[conditional. 'sentry == true']
64+
type = "string"
65+
name = "sentry_dsn"
66+
prompt = "What is your sentry dsn?"
67+
default = "https://examplePublicKey@o0.ingest.sentry.io/0"

src/main.rs.liquid

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::thread::sleep;
2+
3+
{% if dotenv == true %}
4+
use dotenv;
5+
6+
dotenv::dotenv().ok();
7+
{% endif %}
8+
9+
#[path = "1_module/tests/add_sub.rs"]
10+
mod add_sub;
11+
#[path = "2_module/tests/mul_div.rs"]
12+
mod mul_div;
13+
14+
fn main() {
15+
16+
{% if sentry == true %}
17+
const _config: sentry::ClientInitGuard = sentry::init(({{ sentry_dsn }}, sentry::ClientOptions {
18+
release: sentry::release_name!(),
19+
..Default::default()
20+
}));
21+
{% endif %}
22+
23+
const SLEEP_MESSAGE: &str = "Sleep forever...";
24+
const HELLO_SENTRY: &str = "Hello, sentry!";
25+
println!("{}", SLEEP_MESSAGE);
26+
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 %}
38+
}
39+
40+

0 commit comments

Comments
 (0)