Skip to content

Commit

Permalink
Use string value for ref-type check (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jul 4, 2021
1 parent 32f3132 commit a846a72
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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 .
Expand Down
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/prerelease/Cargo.toml → bin/ref-type/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "prerelease"
name = "ref-type"
version = "0.0.0"
authors = ["Casey Rodarmor <[email protected]>"]
edition = "2018"
Expand Down
14 changes: 10 additions & 4 deletions bin/prerelease/src/main.rs → bin/ref-type/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"
);
}

0 comments on commit a846a72

Please sign in to comment.