From c7b0e7743c02974fe84dc395bd58a097d350ffde Mon Sep 17 00:00:00 2001 From: Martin Michaelis Date: Fri, 7 Jun 2024 13:04:49 +0000 Subject: [PATCH] Updated CI --- .github/workflows/ci.yaml | 16 +++ Cargo.lock | 250 ++++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 + README.md | 4 +- build.rs | 41 +++++++ rustfmt.toml | 3 + src/lib.rs | 5 + src/main.rs | 30 ++++- 8 files changed, 337 insertions(+), 14 deletions(-) create mode 100644 build.rs create mode 100644 rustfmt.toml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5fc1f0f..4801598 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,6 +14,18 @@ env: RUSTFLAGS: -C link-arg=-s jobs: + format: + name: Check rust format + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + - name: Setup rust + run: | + rustup toolchain install nightly --profile minimal --component rustfmt --no-self-update + - name: Run cargo fmt + run: cargo +nightly fmt --check + test: name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) ${{ matrix.features }} runs-on: ubuntu-latest @@ -83,6 +95,8 @@ jobs: file target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} stat target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} mv target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }} + - name: Run for ${{ matrix.target.name }} + run: ./badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }} --help - uses: actions/upload-artifact@v4 with: name: badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }} @@ -92,6 +106,7 @@ jobs: ready: name: All required checks passed needs: + - format - test - build runs-on: ubuntu-latest @@ -104,6 +119,7 @@ jobs: permissions: contents: write needs: + - format - test - build runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 93ecf2c..e603e60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,60 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "cc" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -14,6 +63,58 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9689a29b593160de5bc4aacab7b5d54fb52231de70122626c178e6a368994c7" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5387378c84f6faa26890ebf9f0a92989f8873d4d380467bcd0d8d8620424df" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hidapi" version = "2.6.1" @@ -24,9 +125,15 @@ dependencies = [ "cfg-if", "libc", "pkg-config", - "windows-sys", + "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "libc" version = "0.2.155" @@ -39,20 +146,77 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + [[package]] name = "rust-github-actions-test" version = "0.1.0" dependencies = [ + "clap", "hidapi", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", ] [[package]] @@ -61,13 +225,29 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -76,38 +256,86 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml index 91c44fe..9c5dd30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "rust-github-actions-test" version = "0.1.0" +authors = ["Martin Michaelis "] edition = "2021" [[bin]] @@ -13,4 +14,5 @@ example = [] cli = ["example"] [dependencies] +clap = { version = "4.5.6", features = ["derive"] } hidapi = "2.6.1" diff --git a/README.md b/README.md index 1a0a202..505140f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The latest commit on the main branch just gets build and released automatically. Download the prebuild program for one of the following operating systems: -- [Linux (GNU / 64 bit)](../../releaset/download/badgemagic.x86_64-unknown-linux-gnu) +- [Linux (GNU / 64 bit)](../../releases/download/badgemagic.x86_64-unknown-linux-gnu) - [Windows (64 bit)](../../releases/latest/download/badgemagic.x86_64-pc-windows-msvc.exe) - [MacOS (Intel)](../../releases/latest/download/badgemagic.x86_64-apple-darwin) - [MacOS (M1, etc.)](../../releases/latest/download/badgemagic.aarch64-apple-darwin) @@ -93,7 +93,7 @@ mode = "center" text = "Hello" ``` -If you want you can "draw" images as ascii art (`_` = Off, `X` = On): +If you want you can "draw" images as ASCII art (`_` = Off, `X` = On): ```toml [[message]] mode = "center" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..413b504 --- /dev/null +++ b/build.rs @@ -0,0 +1,41 @@ +fn main() { + #[cfg(feature = "cli")] + cli::generate_version_info(); +} + +#[cfg(feature = "cli")] +mod cli { + use std::{env, fs, path::PathBuf, process::Command, str}; + + pub fn generate_version_info() { + let pkg_version = env::var("CARGO_PKG_VERSION").expect("missing package version"); + let git_version = git_version(); + let git_prefix = git_version + .is_some() + .then_some("commit-") + .unwrap_or_default(); + let git_version = git_version.as_deref().unwrap_or("unknown"); + let version = format!("{pkg_version}-git.{git_prefix}{git_version}"); + + let out: PathBuf = env::var_os("OUT_DIR").expect("build output path").into(); + fs::write( + out.join("cli.rs"), + format!("pub const VERSION: &str = {version:?};\n"), + ) + .expect("write cli.rs"); + } + + fn git_version() -> Option { + let output = Command::new("git") + .arg("describe") + .arg("--always") + .arg("--dirty=-modified") + .output() + .ok()?; + if output.status.success() { + Some(str::from_utf8(&output.stdout).ok()?.trim().into()) + } else { + None + } + } +} diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..e3d0a76 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +format_code_in_doc_comments = true +imports_granularity = "Crate" +use_field_init_shorthand = true diff --git a/src/lib.rs b/src/lib.rs index d2bc429..00784f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,3 +11,8 @@ pub fn foo() { pub fn foo() { println!("the C runtime should be dynamically linked"); } + +#[cfg(feature = "cli")] +pub mod cli { + include!(concat!(env!("OUT_DIR"), "/cli.rs")); +} diff --git a/src/main.rs b/src/main.rs index af65d04..7994319 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,40 @@ #![warn(clippy::all, clippy::pedantic)] +use std::{env, path::PathBuf}; + +use clap::Parser; use rust_github_actions_test::foo; +#[derive(Parser)] +/// Upload a configuration with up to 8 messages to an LED badge +#[clap( + version = rust_github_actions_test::cli::VERSION, + author, + help_template = "\ +{before-help}{name} {version} +{author-with-newline} +{about-with-newline} +{usage-heading} {usage} + +{all-args}{after-help} + ", +)] +struct Args { + /// File format of the config file (toml, json) + #[clap(long)] + format: Option, + + /// Path to TOML configuration file + config: PathBuf, +} + fn main() { + let _args = Args::parse(); + println!( "Hello, world V2!: {:?} {:?}", std::path::MAIN_SEPARATOR, - std::env::current_dir().unwrap(), + env::current_dir().unwrap(), ); foo();