Use string value for ref-type check (#897)

This commit is contained in:
Casey Rodarmor 2021-07-03 21:16:24 -07:00 committed by GitHub
parent 32f3132997
commit a846a728f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 29 deletions

View File

@ -123,12 +123,12 @@ jobs:
sudo apt-get install ripgrep sudo apt-get install ripgrep
./bin/forbid ./bin/forbid
- name: Prerelease Check - name: Ref Type
id: is_prerelease id: ref-type
run: cargo run --package prerelease -- --reference ${{ github.ref }} run: cargo run --package ref-type -- --reference ${{ github.ref }}
- name: Test Install Script With Explicit Target - 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: | run: |
cd `mktemp -d` cd `mktemp -d`
cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --target ${{ matrix.target }} --to . cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --target ${{ matrix.target }} --to .
@ -137,7 +137,7 @@ jobs:
fi fi
- name: Test Install Script Without Explicit Target - 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: | run: |
cd `mktemp -d` cd `mktemp -d`
cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --to . cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --to .

18
Cargo.lock generated
View File

@ -288,15 +288,6 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "prerelease"
version = "0.0.0"
dependencies = [
"executable-path",
"regex",
"structopt",
]
[[package]] [[package]]
name = "pretty_assertions" name = "pretty_assertions"
version = "0.7.2" version = "0.7.2"
@ -400,6 +391,15 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "ref-type"
version = "0.0.0"
dependencies = [
"executable-path",
"regex",
"structopt",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.5.4" version = "1.5.4"

View File

@ -14,7 +14,7 @@ keywords = ["command-line", "task", "runner", "development", "utility"]
resolver = "2" resolver = "2"
[workspace] [workspace]
members = [".", "bin/prerelease"] members = [".", "bin/ref-type"]
[dependencies] [dependencies]
ansi_term = "0.12.0" ansi_term = "0.12.0"

View File

@ -1,5 +1,5 @@
[package] [package]
name = "prerelease" name = "ref-type"
version = "0.0.0" version = "0.0.0"
authors = ["Casey Rodarmor <casey@rodarmor.com>"] authors = ["Casey Rodarmor <casey@rodarmor.com>"]
edition = "2018" edition = "2018"

View File

@ -13,8 +13,14 @@ fn main() {
let regex = Regex::new("^refs/tags/[[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+$") let regex = Regex::new("^refs/tags/[[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+$")
.expect("Failed to compile release regex"); .expect("Failed to compile release regex");
println!( let value = if regex.is_match(&arguments.reference) {
"::set-output name=value::{}", "release"
!regex.is_match(&arguments.reference) } else {
); "other"
};
eprintln!("ref: {}", arguments.reference);
eprintln!("value: {}", value);
println!("::set-output name=value::{}", value);
} }

View File

@ -2,7 +2,7 @@ use executable_path::executable_path;
use std::{process::Command, str}; use std::{process::Command, str};
fn stdout(reference: &str) -> String { fn stdout(reference: &str) -> String {
let output = Command::new(executable_path("prerelease")) let output = Command::new(executable_path("ref-type"))
.args(&["--reference", reference]) .args(&["--reference", reference])
.output() .output()
.unwrap(); .unwrap();
@ -13,30 +13,30 @@ fn stdout(reference: &str) -> String {
} }
#[test] #[test]
fn junk_is_prerelease() { fn junk_is_other() {
assert_eq!(stdout("refs/tags/asdf"), "::set-output name=value::true\n"); assert_eq!(stdout("refs/tags/asdf"), "::set-output name=value::other\n");
} }
#[test] #[test]
fn valid_version_is_not_prerelease() { fn valid_version_is_release() {
assert_eq!( assert_eq!(
stdout("refs/tags/0.0.0"), stdout("refs/tags/0.0.0"),
"::set-output name=value::false\n" "::set-output name=value::release\n"
); );
} }
#[test] #[test]
fn valid_version_with_trailing_characters_is_prerelease() { fn valid_version_with_trailing_characters_is_other() {
assert_eq!( assert_eq!(
stdout("refs/tags/0.0.0-rc1"), stdout("refs/tags/0.0.0-rc1"),
"::set-output name=value::true\n" "::set-output name=value::other\n"
); );
} }
#[test] #[test]
fn valid_version_with_lots_of_digits_is_not_prerelease() { fn valid_version_with_lots_of_digits_is_release() {
assert_eq!( assert_eq!(
stdout("refs/tags/01232132.098327498374.43268473849734"), stdout("refs/tags/01232132.098327498374.43268473849734"),
"::set-output name=value::false\n" "::set-output name=value::release\n"
); );
} }