From 0a9ffd7a7b1e423e8ae5cee08427a416c957644f Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 1 Jun 2021 16:37:40 -0700 Subject: [PATCH] Remove `v` prefix from version (#850) --- .github/workflows/build.yaml | 27 +++++++----- Cargo.lock | 64 +++++++++++++++++++++++++++++ Cargo.toml | 3 ++ bin/prerelease/Cargo.toml | 13 ++++++ bin/prerelease/src/main.rs | 20 +++++++++ bin/prerelease/tests/integration.rs | 42 +++++++++++++++++++ justfile | 2 +- rust-toolchain | 1 + src/config.rs | 4 +- test-utilities/Cargo.toml | 1 + test-utilities/src/lib.rs | 33 --------------- 11 files changed, 163 insertions(+), 47 deletions(-) create mode 100644 bin/prerelease/Cargo.toml create mode 100644 bin/prerelease/src/main.rs create mode 100644 bin/prerelease/tests/integration.rs create mode 100644 rust-toolchain diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b5ce735d..e8f811e1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -69,25 +69,26 @@ jobs: run: | sudo apt-get update - - name: Install Main Toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: ${{ matrix.target }} - profile: minimal - components: clippy - override: true + - name: Install Rust Toolchain + run: | + rustup component add clippy + rustup target add ${{ matrix.target }} + rustup default `cat rust-toolchain`-${{ matrix.target }} - name: Install AArch64 Toolchain if: matrix.target == 'aarch64-unknown-linux-gnu' run: sudo apt-get install gcc-aarch64-linux-gnu - - name: Version + - name: Info run: | rustup --version cargo --version cargo clippy --version + - name: Check Lockfile + run: | + cargo update --locked --package just + - name: Build run: cargo build --all --target ${{ matrix.target }} @@ -144,12 +145,16 @@ jobs: run: ./bin/package ${{github.ref}} ${{matrix.os}} ${{ matrix.target }} shell: bash + - name: Prerelease Check + id: is_prerelease + run: cargo run --package prerelease -- --reference ${{ github.ref }} + - name: Publish - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v0.1.5 if: startsWith(github.ref, 'refs/tags/') with: draft: false files: ${{ steps.package.outputs.archive }} - prerelease: ${{ ! startsWith(github.ref, 'refs/tags/v') }} + prerelease: ${{ steps.is_prerelease.outputs.value }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 88812b28..24b98b43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -266,6 +266,15 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "prerelease" +version = "0.0.0" +dependencies = [ + "executable-path", + "regex", + "structopt", +] + [[package]] name = "pretty_assertions" version = "0.7.2" @@ -278,6 +287,30 @@ dependencies = [ "output_vt100", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.27" @@ -398,6 +431,30 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "structopt" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "strum" version = "0.20.0" @@ -463,6 +520,7 @@ dependencies = [ name = "test-utilities" version = "0.0.0" dependencies = [ + "just", "tempfile", ] @@ -499,6 +557,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index dbb5e22c..0612ac5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,9 @@ autotests = false categories = ["command-line-utilities", "development-tools"] keywords = ["command-line", "task", "runner", "development", "utility"] +[workspace] +members = [".", "bin/prerelease"] + [dependencies] ansi_term = "0.12.0" atty = "0.2.0" diff --git a/bin/prerelease/Cargo.toml b/bin/prerelease/Cargo.toml new file mode 100644 index 00000000..eb2960a4 --- /dev/null +++ b/bin/prerelease/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "prerelease" +version = "0.0.0" +authors = ["Casey Rodarmor "] +edition = "2018" +publish = false + +[dependencies] +regex = "1.5.4" +structopt = "0.3.21" + +[dev-dependencies] +executable-path = "1.0.0" diff --git a/bin/prerelease/src/main.rs b/bin/prerelease/src/main.rs new file mode 100644 index 00000000..c0d1b41c --- /dev/null +++ b/bin/prerelease/src/main.rs @@ -0,0 +1,20 @@ +use regex::Regex; +use structopt::StructOpt; + +#[derive(StructOpt)] +struct Arguments { + #[structopt(long)] + reference: String, +} + +fn main() { + let arguments = Arguments::from_args(); + + let regex = Regex::new("^refs/tags/[[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+$") + .expect("Failed to compile release regex"); + + println!( + "::set-output name=value::{}", + !regex.is_match(&arguments.reference) + ); +} diff --git a/bin/prerelease/tests/integration.rs b/bin/prerelease/tests/integration.rs new file mode 100644 index 00000000..54a13ddd --- /dev/null +++ b/bin/prerelease/tests/integration.rs @@ -0,0 +1,42 @@ +use executable_path::executable_path; +use std::{process::Command, str}; + +fn stdout(reference: &str) -> String { + let output = Command::new(executable_path("prerelease")) + .args(&["--reference", reference]) + .output() + .unwrap(); + + assert!(output.status.success()); + + String::from_utf8(output.stdout).unwrap() +} + +#[test] +fn junk_is_prerelease() { + assert_eq!(stdout("refs/tags/asdf"), "::set-output name=value::true\n"); +} + +#[test] +fn valid_version_is_not_prerelease() { + assert_eq!( + stdout("refs/tags/0.0.0"), + "::set-output name=value::false\n" + ); +} + +#[test] +fn valid_version_with_trailing_characters_is_prerelease() { + assert_eq!( + stdout("refs/tags/0.0.0-rc1"), + "::set-output name=value::true\n" + ); +} + +#[test] +fn valid_version_with_lots_of_digits_is_not_prerelease() { + assert_eq!( + stdout("refs/tags/01232132.098327498374.43268473849734"), + "::set-output name=value::false\n" + ); +} diff --git a/justfile b/justfile index 8b9e69a9..03e5299a 100755 --- a/justfile +++ b/justfile @@ -55,7 +55,7 @@ man: view-man: man man man/just.1 -version := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' Cargo.toml | head -1` +version := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1` # add git log messages to changelog changes: diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 00000000..154cb93b --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +1.52.1 diff --git a/src/config.rs b/src/config.rs index 60ce17b0..883350f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -310,7 +310,7 @@ impl Config { )) } else { app - .version(concat!("v", env!("CARGO_PKG_VERSION"))) + .version(env!("CARGO_PKG_VERSION")) .author(env!("CARGO_PKG_AUTHORS")) .about(concat!( env!("CARGO_PKG_DESCRIPTION"), @@ -900,7 +900,7 @@ mod tests { // have proper tests for all the flags, but this will do for now. #[test] fn help() { - const EXPECTED_HELP: &str = "just v0.9.4 + const EXPECTED_HELP: &str = "just 0.9.4 Casey Rodarmor 🤖 Just a command runner \ - https://github.com/casey/just diff --git a/test-utilities/Cargo.toml b/test-utilities/Cargo.toml index aa92a1d4..90971de0 100644 --- a/test-utilities/Cargo.toml +++ b/test-utilities/Cargo.toml @@ -7,3 +7,4 @@ publish = false [dependencies] tempfile = "3" +just = { path = ".." } diff --git a/test-utilities/src/lib.rs b/test-utilities/src/lib.rs index 88f2a0e6..414cae11 100644 --- a/test-utilities/src/lib.rs +++ b/test-utilities/src/lib.rs @@ -123,39 +123,6 @@ macro_rules! tmptree { mod tests { use super::*; - #[test] - fn unindents() { - assert_eq!(unindent("foo"), "foo"); - assert_eq!(unindent("foo\nbar\nbaz\n"), "foo\nbar\nbaz\n"); - assert_eq!(unindent(""), ""); - assert_eq!(unindent(" foo\n bar"), "foo\nbar"); - assert_eq!(unindent(" foo\n bar\n\n"), "foo\nbar\n"); - } - - #[test] - fn indentations() { - assert_eq!(indentation(""), ""); - assert_eq!(indentation("foo"), ""); - assert_eq!(indentation(" foo"), " "); - assert_eq!(indentation("\t\tfoo"), "\t\t"); - assert_eq!(indentation("\t \t foo"), "\t \t "); - } - - #[test] - fn blanks() { - assert!(blank(" \n")); - assert!(!blank(" foo\n")); - assert!(blank("\t\t\n")); - } - - #[test] - fn commons() { - assert_eq!(common("foo", "foobar"), "foo"); - assert_eq!(common("foo", "bar"), ""); - assert_eq!(common("", ""), ""); - assert_eq!(common("", "bar"), ""); - } - #[test] fn tmptree_file() { let tmpdir = tmptree! {