Skip to content

Commit f3fd011

Browse files
authored
Merge pull request #16 from tj-actions/chore/update-test
2 parents f592650 + 2173f41 commit f3fd011

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

.github/workflows/test.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,25 @@ jobs:
108108
uses: ./
109109
with:
110110
outputs: ${{ toJSON(steps.changed-files.outputs) }}
111-
directory: test/output
112-
keys: "added_files copied_files deleted_files modified_files"
111+
keys: |
112+
added_files
113+
copied_files
114+
deleted_files
115+
modified_files
116+
renamed_files
117+
all_old_new_renamed_files
118+
type_changed_files
119+
unmerged_files
120+
unknown_files
121+
all_changed_and_modified_files
122+
all_changed_files
123+
any_changed
124+
only_changed
125+
other_changed_files
126+
all_modified_files
127+
any_modified
128+
only_modified
129+
other_modified_files
130+
any_deleted
131+
only_deleted
132+
other_deleted_files

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ Cargo.lock
1212
**/*.rs.bk
1313

1414
# JetBrains IDEs
15-
.idea/
15+
.idea/
16+
17+
test/

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ inputs:
55
directory:
66
description: "Directory to write to"
77
required: true
8-
default: "outputs"
8+
default: ".github/outputs"
99
outputs:
1010
description: "JSON string"
1111
required: true
1212
keys:
13-
description: "List of Keys to read from the outputs. Example: foo,bar"
13+
description: "List of Keys to read from the outputs."
1414
required: true
1515
extension:
1616
description: "File extension to use"

entrypoint.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
set -euo pipefail
33

44
INPUT_OUTPUTS="$(echo "$INPUT_OUTPUTS" | jq -r @json)"
5+
INPUT_KEYS="$(echo "$INPUT_KEYS" | tr '\n' ' ' | xargs)"
56

67
if [[ -z "$INPUT_BIN_PATH" ]]; then
78
## TODO: use "curl -sf https://[github releases - latest]] | PREFIX=. sh"
89
exit 1;
910
fi
1011

11-
echo "::debug::Generating output using $INPUT_BIN_PATH..."
12+
echo "Generating output using $INPUT_BIN_PATH..."
1213

13-
$INPUT_BIN_PATH --keys="$INPUT_KEYS" --outputs="$INPUT_OUTPUTS" \
14-
--directory="$INPUT_DIRECTORY" --extension="$INPUT_EXTENSION" && exit_status=$? || exit_status=$?
14+
$INPUT_BIN_PATH --keys="$INPUT_KEYS" --outputs="$INPUT_OUTPUTS" --directory="$INPUT_DIRECTORY" --extension="$INPUT_EXTENSION" && exit_status=$? || exit_status=$?
1515

1616
rm -f "$INPUT_BIN_PATH"
1717

1818
if [[ $exit_status -ne 0 ]]; then
1919
echo "::error::Error generating output files from JSON"
20-
exit $exit_status;
20+
exit 1;
2121
fi

src/main.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,27 @@ fn get_args_as_bool(pattern: &str) -> bool {
8787
fn parse_keys() -> Result<Vec<String>, String> {
8888
let keys: Vec<String> = get_args_as_vec(r"^(--keys|-k)=");
8989
// Split the keys by commas or spaces or newlines
90-
let re: regex::Regex = regex::Regex::new(r"[,\s\\n]+").unwrap();
90+
let re: regex::Regex = regex::Regex::new(r"[[:space:]]+").unwrap();
9191
let mut output: Vec<String> = Vec::new();
9292

93+
println!("Keys: {:?}", keys);
94+
9395
if keys.is_empty() {
9496
Err("No keys provided, Please specify at least one key using --key=[KEY_NAME] or -k=[KEY_NAME].".to_string())
9597
} else {
9698
for key in keys {
97-
if re.is_match(&key) {
98-
output.extend(re.split(&key).map(|s| s.trim().to_string()));
99-
} else if !key.is_empty() {
100-
output.push(key.trim().to_string());
99+
if !key.is_empty() {
100+
output.extend(re.split(&key).filter_map(|s| {
101+
if s.is_empty() {
102+
None
103+
} else {
104+
Some(s.trim().to_string())
105+
}
106+
}));
107+
108+
println!("Output: {:?}", output);
109+
} else {
110+
Err("Invalid key provided, Please specify at least one key using --key=[KEY_NAME] or -k=[KEY_NAME].".to_string())?;
101111
}
102112
}
103113
Ok(output)
@@ -207,6 +217,17 @@ fn options_valid() -> bool {
207217
true
208218
}
209219

220+
// TODO: Switch to use https://rust-cli.github.io/book/tutorial/index.html
221+
// #[derive(Parser)]
222+
// struct Options {
223+
// help: bool,
224+
// version: bool,
225+
// keys: Vec<String>,
226+
// outputs: String,
227+
// directory: String,
228+
// extension: String,
229+
// }
230+
210231
fn main() {
211232
if !options_valid() {
212233
std::process::exit(1);

0 commit comments

Comments
 (0)