feat: initial Rust cargo-generate template
HEAD
main
13 files changed, 323 insertions(+)
@@ -1,0 +1,2 @@
/target
*.log
@@ -1,0 +1,4 @@
# Changelog
All notable changes to the `{{project-name}}` crate will be documented in this file.
## [Unreleased]
@@ -1,0 +1,34 @@
[package]
name = "{{project-name}}"
version = "0.1.0"
license = "{{license}}"
description = "{{description}}"
authors = ["Yousef Al-Harbi <yousefalharby416@gmail.com>"]
repository = "https://github.com/y2w8/{{project-name}}"
edition = "2024"
rust-version = "1.96.0"
readme = "README.md"
exclude = [
".github/",
".gitignore",
"./assets/",
"./release.toml",
"./cliff.toml",
"./justfile",
]
[dependencies]
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
all = { level = "warn", priority = -1 }
dbg_macro = "warn"
todo = "warn"
unwrap_used = "warn"
[profile.release]
lto = true
codegen-units = 1
strip = true
@@ -1,0 +1,18 @@
# {{project-name}}
{{description}}
## Development
Common tasks are automated via [`just`](https://github.com/casey/just):
```sh
just --list # List all available recipes
just run # Run locally
just ci # Run rustfmt, clippy, and tests
just release patch # Bump version, update CHANGELOG.md via git-cliff, tag & push
```
## License
Licensed under the [{{license}}](LICENSE) license.
@@ -1,0 +1,17 @@
[template]
cargo_generate_version = ">=0.18.0"
exclude = [
"release.toml",
".github/workflows/ci.yml",
]
[placeholders.description]
type = "string"
prompt = "Crate description?"
default = "A fast application written in Rust."
[placeholders.license]
type = "string"
prompt = "License?"
choices = ["GPL-3.0", "MIT", "Apache-2.0"]
default = "GPL-3.0"
@@ -1,0 +1,43 @@
[remote.github]
owner = "y2w8"
repo = "{{project-name}}"
[changelog]
header = """
# Changelog
All notable changes to the `{{project-name}}` crate will be documented in this file.
## [Unreleased]
"""
body = """
{% raw %}{% if version -%}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% endif -%}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim }}
{% for commit in commits -%}
- {{ commit.message | split(pat="\\n") | first | upper_first | trim }} \
([{{ commit.id | truncate(length=7, end="") }}](https://github.com/y2w8/{% endraw %}{{project-name}}{% raw %}/commit/{{ commit.id }})), \
by @{{ commit.remote.username | default(value=commit.author.name) }}
{% endfor %}
{% endfor -%}{% endraw %}
"""
trim = true
[git]
conventional_commits = true
filter_unconventional = false
split_commits = false
commit_parsers = [
{ message = "^feat", group = "<!-- 0 -->Added" },
{ message = "^fix", group = "<!-- 1 -->Fixed" },
{ message = "^refactor", group = "<!-- 2 -->Changed" },
{ message = "^perf", group = "<!-- 3 -->Performance" },
{ message = "^doc", group = "<!-- 4 -->Documentation" },
{ message = "^chore: release", skip = true },
{ message = "^chore\\(release\\)", skip = true },
{ message = ".*", group = "<!-- 5 -->Other" },
]
filter_commits = false
tag_pattern = "v[0-9].*"
sort_commits = "newest"
@@ -1,0 +1,2 @@
large-error-threshold = 256
too-many-arguments-threshold = 7
@@ -1,0 +1,60 @@
{% raw %}arm_target := "aarch64-unknown-linux-gnu"
default:
@just --list
# Build debug binary
build *args:
cargo build {{args}}
# Build optimized release binary (x86_64)
build-release:
cargo build --release
# Cross-compile ARM64 release binary
build-arm:
cargo build --release --target {{arm_target}}
# Run locally with arguments
run *args:
cargo run -- {{args}}
# Fast type and borrow check
check:
cargo check --all-targets --all-features
# Format all Rust code
fmt:
cargo fmt --all
# Check formatting without modifying files
fmt-check:
cargo fmt --all -- --check
# Run Clippy with all warnings denied
lint:
cargo clippy --all-targets --all-features -- -D warnings
# Run all unit and integration tests
test *args:
cargo test --all-targets --all-features {{args}}
# Run full CI quality gate locally (format check, clippy, tests)
ci: fmt-check lint test
# Preview changelog for unreleased commits
changelog-preview:
git-cliff --unreleased
# Dry-run a version bump (patch, minor, major)
release-dry level="patch":
cargo release {{level}}
# Execute a version bump, update CHANGELOG.md via git-cliff, tag, and push
release level="patch":
cargo release {{level}} --execute
# Remove build artifacts
clean:
cargo clean
{% endraw %}
@@ -1,0 +1,16 @@
push = true
publish = true
tag = true
sign-tag = false
pre-release-commit-message = "chore: release {{version}}"
tag-message = "Release {{version}}"
# Generate changelog entry with all commits and @author handles since last tag
pre-release-hook = [
"git-cliff",
"--tag",
"{{version}}",
"--unreleased",
"--prepend",
"CHANGELOG.md",
]
@@ -1,0 +1,2 @@
edition = "2024"
newline_style = "Unix"
@@ -1,0 +1,11 @@
fn main() {
println!("Hello from {{project-name}}!");
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
@@ -1,0 +1,35 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
ci:
name: Check, Lint & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
- name: Lint with Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build --all-targets --verbose
- name: Run tests
run: cargo test --all-targets --all-features --verbose
@@ -1,0 +1,79 @@
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build:
name: Build {% raw %}${{ matrix.target }}{% endraw %}
runs-on: {% raw %}${{ matrix.os }}{% endraw %}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
binary: {{project-name}}
asset: {{project-name}}-x86_64-linux
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
binary: {{project-name}}
asset: {{project-name}}-aarch64-linux
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: {% raw %}${{ matrix.target }}{% endraw %}
- uses: Swatinem/rust-cache@v2
- name: Install cross
run: cargo install cross --locked
- name: Build release binary
run: cross build --release --target {% raw %}${{ matrix.target }}{% endraw %}
- name: Rename binary
run: cp target/{% raw %}${{ matrix.target }}/release/${{ matrix.binary }} ${{ matrix.asset }}{% endraw %}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: {% raw %}${{ matrix.asset }}{% endraw %}
path: {% raw %}${{ matrix.asset }}{% endraw %}
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Extract changelog notes for tag
id: changelog
run: |
{% raw %}VERSION=${GITHUB_REF#refs/tags/v}
NOTES=$(awk "/## \[$VERSION\]/{flag=1; next} /## \[/{flag=0} flag" CHANGELOG.md)
{
echo "notes<<EOF"
echo "$NOTES"
echo "EOF"
} >> "$GITHUB_OUTPUT"{% endraw %}
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
body: {% raw %}${{ steps.changelog.outputs.notes }}{% endraw %}
files: artifacts/*