diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ecd8e0..361c20c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,32 +19,21 @@ jobs: - nightly timeout-minutes: 45 steps: - - - uses: actions/checkout@v4 - - - uses: dtolnay/rust-toolchain@stable + - uses: actions/checkout@v4 + - uses: jdx/mise-action@v2 + with: + version: 2024.11.37 + - name: Remove rust from mise + run: | + # a different rust version will be installed in the next step + mise rm rust + - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} components: clippy, rustfmt - - - uses: taiki-e/install-action@nextest - - - uses: actions/setup-node@v4 - with: - node-version: lts/Iron # 20 - - - uses: denoland/setup-deno@v1 - with: - deno-version: v1.45.x - - - run: ./install.sh - - - uses: Swatinem/rust-cache@v2.7.3 - - - run: lefthook run --force pre-commit - - - run: cargo hack test --feature-powerset - - - name: Validate PR commits with commitlint + - uses: Swatinem/rust-cache@v2.7.3 + - run: lefthook run --force pre-commit + - run: cargo hack test --feature-powerset + - name: Validate PR commits with commitlint if: github.event_name == 'pull_request' run: commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose diff --git a/Cargo.lock b/Cargo.lock index 1624702..6417ac6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,21 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "anstream" @@ -57,6 +72,45 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "bitflags" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" + +[[package]] +name = "bytes" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "clap" version = "4.5.9" @@ -112,6 +166,7 @@ dependencies = [ "derive-new", "derive_setters", "fs_extra", + "tokio", ] [[package]] @@ -184,6 +239,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + [[package]] name = "heck" version = "0.5.0" @@ -202,11 +263,91 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -220,6 +361,52 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "strsim" version = "0.11.1" @@ -228,15 +415,44 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.71" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "tokio" +version = "1.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -249,6 +465,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 9ceae31..12cace3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,5 +22,4 @@ clap = { version = "4.3.24", features = ["derive", "env"] } derive-new = "0.7.0" derive_setters = "0.1.6" fs_extra = "1.3.0" -hedgehog-rs = { version = "0.1.8" } tokio = { version = "1.40.0", features = ["full", "process"] } diff --git a/Justfile b/Justfile deleted file mode 100644 index 4b79a2f..0000000 --- a/Justfile +++ /dev/null @@ -1,33 +0,0 @@ -import? 'Justfile.local.just' - -set quiet - -default: - just --list - -build *args: - cargo build {{args}} - -lint *args: - cargo clippy --all-targets --all-features {{args}} -- -D warnings - -test *args: - cargo nextest run {{args}} - -watch *args: - #!/usr/bin/env bash - set -euxo pipefail - PWD=$(pwd) - CMD_RAW="nextest run $*" - CMD_NO_WHITESPACE="$(echo -e "${CMD_RAW}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - cargo watch --clear --watch "$PWD" --exec "$CMD_NO_WHITESPACE" - -check *args: - cargo check --all-targets "$@" - -fix *args: - cargo fix --workspace --allow-dirty --allow-staged {{args}} - -reset *args: - supabase db reset - just migrate {{args}} diff --git a/README.md b/README.md index 4d356f9..26066ac 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,9 @@ Options: [default: "git push"] + --after-all-cmd + Shell command to execute after all other commands (supports substitutions - see help below) + -s, --support-link-probability The probability of seeing a support link in a single execution of the command is `1 / {{this-field-value}}`. diff --git a/install.sh b/install.sh deleted file mode 100755 index 8ebc110..0000000 --- a/install.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -npm install --global \ - lefthook@1.6.9 \ - remark-cli@12.0.1 \ - remark-validate-links@8.0.0 \ - remark-lint-no-dead-urls@1.1.0 \ - @commitlint/cli@19.3.0 \ - @commitlint/config-conventional@19.2.2 \ - @commitlint/types@19.0.3 - -cargo install --git https://github.com/DenisGorbachev/cargo-doc2readme --branch dev -cargo install cargo-machete --locked -cargo install cargo-hack --locked -cargo install cargo-sort --locked - -# Install yj -curl -L https://github.com/sclevine/yj/releases/download/v5.1.0/yj-linux-amd64 -o /tmp/yj -chmod +x /tmp/yj -sudo mv /tmp/yj /usr/local/bin/yj diff --git a/lefthook.yml b/lefthook.yml index 40482a4..325254e 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -2,28 +2,29 @@ assert_lefthook_installed: true pre-commit: parallel: true commands: - generate-readme: + gen:readme: run: | set -eu - ./README.ts > README.md - remark --ignore-path .gitignore --quiet --frail --no-stdout README.md # run remark again because README.md has changed - git add README.md # add README.md manually instead of using `stage_fixed` because it may not have been staged - format: - run: cargo fmt --all + mise run gen:readme + # run remark again because README.md has changed + mise run remark README.md + # add README.md manually instead of using `stage_fixed` because it may not have been staged + git add README.md + fmt: + run: mise run fmt + stage_fixed: true + lint:code: + run: mise run lint:code + lint:docs: + run: mise run lint:docs + lint:deps: + run: mise run lint:deps + test:code: + run: mise run test:code --no-fail-fast + sort:deps: + run: mise run sort:deps stage_fixed: true - lint-code: - run: cargo clippy --all-targets --all-features -- -D warnings - test-code: - run: cargo nextest run --no-fail-fast - lint-docs: - run: remark --ignore-path .gitignore --quiet --frail --no-stdout . - test-docs: - run: cargo test --doc - sort-deps: - run: cargo sort - lint-deps: - run: cargo machete --with-metadata commit-msg: commands: - "lint commit message": - run: commitlint --edit "$1" + commitlint: + run: mise exec -- commitlint --edit "$1" diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..cbadf50 --- /dev/null +++ b/mise.toml @@ -0,0 +1,80 @@ +min_version = "2025.1.14" + +[tools] +rust = "stable" +node = "22.12.0" +deno = "1.46.1" +cargo-binstall = "1.10.15" +"npm:lefthook" = "1.8.5" +"npm:@commitlint/config-conventional" = "19.6.0" +"npm:@commitlint/cli" = "19.6.0" +"npm:@commitlint/types" = "19.5.0" +"npm:remark-cli" = "12.0.1" +"npm:remark-validate-links" = "8.0.0" +"npm:remark-lint-no-dead-urls" = "1.1.0" +"cargo:https://github.com/DenisGorbachev/cargo-doc2readme" = "branch:dev" +"cargo:cargo-sort" = "1.0.9" +"cargo:cargo-hack" = "0.6.33" +"cargo:cargo-machete" = "0.7.0" +"cargo:cargo-nextest" = "0.9.72" +"aqua:sclevine/yj" = "5.1.0" + +[tasks."build"] +run = "cargo build" + +[tasks."fmt"] +run = "cargo fmt --all" + +[tasks."lint"] +depends = ["lint:code", "lint:docs"] + +[tasks."test"] +depends = ["test:code", "test:docs"] + +[tasks."lint:code"] +run = "cargo clippy --all-targets --all-features -- -D warnings" + +[tasks."lint:docs"] +run = "mise run remark ." + +[tasks."lint:deps"] +run = "cargo machete --with-metadata" + +[tasks."test:code"] +run = "cargo nextest run" + +[tasks."test:docs"] +run = "cargo test --doc" + +[tasks."sort:deps"] +run = "cargo sort" + +[tasks."watch"] +run = """ +#!/usr/bin/env bash +set -euo pipefail +PWD=$(pwd) +CMD_RAW="nextest run $*" +CMD_NO_WHITESPACE="$(echo -e "${CMD_RAW}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +cargo watch --clear --watch "$PWD" --exec "$CMD_NO_WHITESPACE" "$@" +""" + +[tasks."check"] +run = "cargo check --all-targets" + +[tasks."fix"] +run = "cargo fix --workspace --allow-dirty --allow-staged" + +[tasks."gen:readme"] +run = "./README.ts > README.md" +sources = ["README.ts"] +outputs = ["README.md"] + +[tasks."remark"] +run = """ +#!/usr/bin/env bash +set -euo pipefail +REMARK_VALIDATE_LINKS="$(mise where npm:remark-validate-links)/lib/node_modules/remark-validate-links/index.js" +REMARK_LINT_NO_DEAD_URLS="$(mise where npm:remark-lint-no-dead-urls)/lib/node_modules/remark-lint-no-dead-urls/index.js" +remark --ignore-path .gitignore --quiet --frail --no-stdout --use "$REMARK_VALIDATE_LINKS" --use "$REMARK_LINT_NO_DEAD_URLS" "$@" +""" diff --git a/src/lib.rs b/src/lib.rs index 4878550..f5f876c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,10 +36,10 @@ use std::fs::create_dir_all; use std::io; use std::io::Write; use std::path::{Path, PathBuf}; -use tokio::process::Command; use std::process::ExitStatus; use std::sync::LazyLock; use std::time::{SystemTime, UNIX_EPOCH}; +use tokio::process::Command; use anyhow::{anyhow, Context}; use clap::{value_parser, Parser}; @@ -97,6 +97,9 @@ pub struct CreateRustGithubRepo { #[arg(long, help = "Shell command to push the commit (supports substitutions - see help below)", default_value = "git push")] repo_push_args: String, + #[arg(long, help = "Shell command to execute after all other commands (supports substitutions - see help below)")] + after_all_cmd: Option, + /// The probability of seeing a support link in a single execution of the command is `1 / {{this-field-value}}`. /// /// Set it to 0 to disable the support link. @@ -221,6 +224,14 @@ impl CreateRustGithubRepo { .await .context("Failed to push changes")?; + // after all + if let Some(after_all_cmd) = self.after_all_cmd { + executor + .exec(replace_all(after_all_cmd, &substitutions), &dir, stderr) + .await + .context("Failed to run after_all_cmd")?; + } + let timestamp = now.unwrap_or_else(get_unix_timestamp_or_zero); if self.support_link_probability != 0 && timestamp % self.support_link_probability == 0 { @@ -397,7 +408,7 @@ static _POSTHOG_API_KEY: LazyLock = LazyLock::new(|| { String::from_utf8(vec![ 112, 104, 99, 95, 111, 86, 117, 105, 97, 50, 73, 111, 119, 90, 121, 116, 99, 77, 84, 81, 110, 55, 108, 81, 86, 87, 103, 87, 89, 80, 117, 49, 99, 107, 100, 112, 106, 52, 51, 68, 110, 74, 55, 84, 97, 109, 74, ]) - .unwrap() + .unwrap() }); #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index a73de2a..0172bc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,5 +5,7 @@ use create_rust_github_repo::CreateRustGithubRepo; #[tokio::main] async fn main() -> anyhow::Result<()> { - CreateRustGithubRepo::parse().run(&mut stdout(), &mut stderr(), None).await + CreateRustGithubRepo::parse() + .run(&mut stdout(), &mut stderr(), None) + .await }