From 7429e29db45a5f721c9fe057f33d8eb7ef06480f Mon Sep 17 00:00:00 2001 From: containerscrew <131241415+containerscrew@users.noreply.github.com> Date: Tue, 27 Aug 2024 18:56:19 +0200 Subject: [PATCH] Cliff && test pipeline && Makefile --- .github/dependabot.yml | 8 +++++ .github/workflows/test.yml | 62 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 +++ Makefile | 35 +++++++++++++++++++++ README.md | 1 + cliff.toml | 28 +++++++++++++++++ docs/README.md | 1 + docs/test.md | 1 + src/cli.rs | 10 +++--- src/main.rs | 10 ++++-- 10 files changed, 152 insertions(+), 8 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/test.yml create mode 100644 Makefile create mode 100644 cliff.toml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e257d0c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + time: "20:00" + open-pull-requests-limit: 10 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1b4ec03 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,62 @@ +name: Test 🤖 + +on: + pull_request: + push: + paths: + - 'src/**' + branches: + - '**' + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macOS-latest + target: x86_64-apple-darwin + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + targets: ${{ matrix.target }} + + - name: Run cargo test + run: cargo test --locked --target ${{ matrix.target }} + + - name: Run tests feature variation + run: cargo test --locked --target ${{ matrix.target }} --no-default-features + rusfmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + components: rustfmt + + - name: Check formatting + run: cargo fmt --all -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + components: clippy + + - name: Check formatting + run: cargo clippy --all-features -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 31da7af..a1b98ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,10 @@ name = "mtoc" version = "0.1.0" edition = "2021" +authors = ["containerscrew info@containerscrew.com"] +repository = "https://github.com/containerscrew/gitrack" +rust-version = "1.80.1" + [dependencies] clap = { version = "4.5.16", features = ["derive"] } diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c46b0e5 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +SHELL:=/bin/sh +.PHONY: all + +BINARY_NAME = mtoc + + +help: ## this help + @awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n make \033[36m \033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +pre-commit: ## Run pre-commit + pre-commit run -a + +package: ## Package binary with zip + zip -j ${BINARY_NAME}-$(PLATFORM).zip target/$(TARGET)/release/${BINARY_NAME} + +generate-changelog: ## Generate changelog using git cliff + git cliff --output CHANGELOG.md + +build: ## Build binary + cargo build --release + +install: ## Install binary + cargo install --path . + +uninstall: ## Uninstall binary + cargo uninstall ${BINARY_NAME} + +build: ## Build binary + cargo build --release --locked + +cargo-fix: ## Run cargo fix + cargo fix --bin mtoc + +mtoc: ## Create table of contents with doctoc + mtoc -d . diff --git a/README.md b/README.md index 76b8b70..794303f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ +

mtoc 📄

Markdown table of contents generator

diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..65c48fd --- /dev/null +++ b/cliff.toml @@ -0,0 +1,28 @@ +[changelog] +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" + +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for commit in commits | unique(attribute="message") %} + - {{ commit.message | upper_first }} +{% endfor %}\n +""" + +footer = """ + +""" +trim = true + +[git] +conventional_commits = false +filter_unconventional = false +split_commits = false +tag_pattern = "^v[0-9]+\\.[0-9]+\\.[0-9]+$" +sort_commits = "oldest" diff --git a/docs/README.md b/docs/README.md index 7443e92..f8fb359 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,6 +5,7 @@ - [Hellooooo!!!](#hellooooo!!!) + # Hi! ## Hello!! diff --git a/docs/test.md b/docs/test.md index 6562197..d5873e3 100644 --- a/docs/test.md +++ b/docs/test.md @@ -5,6 +5,7 @@ - [Test 3](#test-3) + # Test 1 ## Test 2 diff --git a/src/cli.rs b/src/cli.rs index d8ba99f..1f13d85 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -11,11 +11,11 @@ use clap::Parser; pub struct Args { #[arg( - short = 'f', - long = "file-name", - help = "Name of the markdown file to generate the table of contents for", - default_value = "README.md", + short = 'd', + long = "directory", + help = "Directory to search for markdown files", + default_value = ".", required = false )] - pub file_name: String, + pub directory: String, } diff --git a/src/main.rs b/src/main.rs index e9e0d06..1c5612d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,12 +17,12 @@ use std::path::Path; fn main() -> io::Result<()> { // Parse command-line arguments - // let args = Args::parse(); + let args = Args::parse(); // Find markdown files in all the repo - let markdown_files = find_markdown_files(Path::new(".")); + let markdown_files = find_markdown_files(Path::new(&args.directory)); - for markdown_file in markdown_files { + for markdown_file in &markdown_files { // Read the original file content let contents = read_markdown_file(markdown_file.as_str())?; @@ -43,5 +43,9 @@ fn main() -> io::Result<()> { eprintln!("{} {}", "Updated markdown file ".green(), markdown_file); } + if markdown_files.is_empty() { + eprintln!("{}", "No markdown files found in the given directory".red()); + } + Ok(()) }