Skip to content

Commit

Permalink
Cliff && test pipeline && Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
containerscrew committed Aug 27, 2024
1 parent 344a44f commit 7429e29
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "20:00"
open-pull-requests-limit: 10
62 changes: 62 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "mtoc"
version = "0.1.0"
edition = "2021"
authors = ["containerscrew [email protected]"]
repository = "https://github.com/containerscrew/gitrack"
rust-version = "1.80.1"


[dependencies]
clap = { version = "4.5.16", features = ["derive"] }
Expand Down
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
SHELL:=/bin/sh
.PHONY: all

BINARY_NAME = mtoc


help: ## this help
@awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n make \033[36m<target> \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 .
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@




<h1 align="center">mtoc 📄</h1>
<p align="center">Markdown table of contents generator</p>

Expand Down
28 changes: 28 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -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 = """
<!-- generated by git-cliff -->
"""
trim = true

[git]
conventional_commits = false
filter_unconventional = false
split_commits = false
tag_pattern = "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
sort_commits = "oldest"
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Hellooooo!!!](#hellooooo!!!)
<!-- END OF TOC -->


# Hi!

## Hello!!
Expand Down
1 change: 1 addition & 0 deletions docs/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Test 3](#test-3)
<!-- END OF TOC -->


# Test 1

## Test 2
Expand Down
10 changes: 5 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;

Expand All @@ -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(())
}

0 comments on commit 7429e29

Please sign in to comment.