From a846a728f13a1c8d952c75ee23983bd617fffc5e Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 3 Jul 2021 21:16:24 -0700 Subject: [PATCH] Use string value for ref-type check (#897) --- .github/workflows/build.yaml | 10 +++++----- Cargo.lock | 18 +++++++++--------- Cargo.toml | 2 +- bin/{prerelease => ref-type}/Cargo.toml | 2 +- bin/{prerelease => ref-type}/src/main.rs | 14 ++++++++++---- .../tests/integration.rs | 18 +++++++++--------- 6 files changed, 35 insertions(+), 29 deletions(-) rename bin/{prerelease => ref-type}/Cargo.toml (91%) rename bin/{prerelease => ref-type}/src/main.rs (58%) rename bin/{prerelease => ref-type}/tests/integration.rs (60%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9f27b14..f15a09f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -123,12 +123,12 @@ jobs: sudo apt-get install ripgrep ./bin/forbid - - name: Prerelease Check - id: is_prerelease - run: cargo run --package prerelease -- --reference ${{ github.ref }} + - name: Ref Type + id: ref-type + run: cargo run --package ref-type -- --reference ${{ github.ref }} - name: Test Install Script With Explicit Target - if: matrix.os != 'windows-2016' && steps.is_prerelease.outputs.value + if: matrix.os != 'windows-2016' && steps.ref-type.outputs.value != 'release' run: | cd `mktemp -d` cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --target ${{ matrix.target }} --to . @@ -137,7 +137,7 @@ jobs: fi - name: Test Install Script Without Explicit Target - if: matrix.os != 'windows-2016' && steps.is_prerelease.outputs.value + if: matrix.os != 'windows-2016' && steps.ref-type.outputs.value != 'release' run: | cd `mktemp -d` cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --to . diff --git a/Cargo.lock b/Cargo.lock index 139df89..c8f446d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,15 +288,6 @@ 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" @@ -400,6 +391,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "ref-type" +version = "0.0.0" +dependencies = [ + "executable-path", + "regex", + "structopt", +] + [[package]] name = "regex" version = "1.5.4" diff --git a/Cargo.toml b/Cargo.toml index 4d67879..b0e9982 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ keywords = ["command-line", "task", "runner", "development", "utility"] resolver = "2" [workspace] -members = [".", "bin/prerelease"] +members = [".", "bin/ref-type"] [dependencies] ansi_term = "0.12.0" diff --git a/bin/prerelease/Cargo.toml b/bin/ref-type/Cargo.toml similarity index 91% rename from bin/prerelease/Cargo.toml rename to bin/ref-type/Cargo.toml index eb2960a..bdc99c4 100644 --- a/bin/prerelease/Cargo.toml +++ b/bin/ref-type/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "prerelease" +name = "ref-type" version = "0.0.0" authors = ["Casey Rodarmor "] edition = "2018" diff --git a/bin/prerelease/src/main.rs b/bin/ref-type/src/main.rs similarity index 58% rename from bin/prerelease/src/main.rs rename to bin/ref-type/src/main.rs index c0d1b41..4620220 100644 --- a/bin/prerelease/src/main.rs +++ b/bin/ref-type/src/main.rs @@ -13,8 +13,14 @@ fn main() { 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) - ); + let value = if regex.is_match(&arguments.reference) { + "release" + } else { + "other" + }; + + eprintln!("ref: {}", arguments.reference); + eprintln!("value: {}", value); + + println!("::set-output name=value::{}", value); } diff --git a/bin/prerelease/tests/integration.rs b/bin/ref-type/tests/integration.rs similarity index 60% rename from bin/prerelease/tests/integration.rs rename to bin/ref-type/tests/integration.rs index 54a13dd..20bad36 100644 --- a/bin/prerelease/tests/integration.rs +++ b/bin/ref-type/tests/integration.rs @@ -2,7 +2,7 @@ use executable_path::executable_path; use std::{process::Command, str}; fn stdout(reference: &str) -> String { - let output = Command::new(executable_path("prerelease")) + let output = Command::new(executable_path("ref-type")) .args(&["--reference", reference]) .output() .unwrap(); @@ -13,30 +13,30 @@ fn stdout(reference: &str) -> String { } #[test] -fn junk_is_prerelease() { - assert_eq!(stdout("refs/tags/asdf"), "::set-output name=value::true\n"); +fn junk_is_other() { + assert_eq!(stdout("refs/tags/asdf"), "::set-output name=value::other\n"); } #[test] -fn valid_version_is_not_prerelease() { +fn valid_version_is_release() { assert_eq!( stdout("refs/tags/0.0.0"), - "::set-output name=value::false\n" + "::set-output name=value::release\n" ); } #[test] -fn valid_version_with_trailing_characters_is_prerelease() { +fn valid_version_with_trailing_characters_is_other() { assert_eq!( stdout("refs/tags/0.0.0-rc1"), - "::set-output name=value::true\n" + "::set-output name=value::other\n" ); } #[test] -fn valid_version_with_lots_of_digits_is_not_prerelease() { +fn valid_version_with_lots_of_digits_is_release() { assert_eq!( stdout("refs/tags/01232132.098327498374.43268473849734"), - "::set-output name=value::false\n" + "::set-output name=value::release\n" ); }