From 757e4bcffda204da2fea5b3351fc2b04d39a4c03 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Thu, 11 Jul 2024 00:03:42 -0300 Subject: [PATCH 01/27] feat: Read from values from yq --- .github/workflows/ci.yml | 2 +- entrypoint.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36dfe2a..b7eedef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: push: branches: - main - - feature/v1 + - feature/** permissions: contents: read diff --git a/entrypoint.sh b/entrypoint.sh index aea1926..c3f156f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,6 +6,27 @@ _yaml_to_properties() { yq -o p --properties-separator '=' '... comments = ""' "$yaml_file" } +_yaml_properties_name() { + local yaml_file="$1" + local yaml_properties=$(_yaml_to_properties "$yaml_file") + local propertyNames="" + while IFS= read -r propertyLine; do + propertyName="${propertyLine%%=*}" + if [ -n "$propertyNames" ]; then + propertyNames="$propertyNames"$'\n'"$propertyName" + else + propertyNames="$propertyName" + fi + done < <(echo "$yaml_properties") + echo "$propertyNames" +} + +_yaml_property_value() { + local yaml_file="$1" + local propertyName="$2" + yq '."$propertyName"' "$yaml_file" +} + _replace_dots() { local string="$1" local replacement="$2" From b6a9a70d0e28eefa314ef34e1aa951854420346f Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 01:43:54 -0300 Subject: [PATCH 02/27] feat: Add support filter and rename --- .github/workflows/ci.yml | 2 +- README.md | 2 +- action.yml | 21 ++++- entrypoint.sh | 163 +++++++++++++++++++++++++++++---------- yq-test-action.yml | 2 +- 5 files changed, 143 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7eedef..83bfebe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: id: action uses: ./ with: - file-path: ./yq-test-action.yml + file-path: ./yq-test-action.yml test-action-output-comment-line: name: GitHub Actions Test Output - Comment Line diff --git a/README.md b/README.md index e028a90..be73831 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# yq YAML parser action +# YAML parser action [![GitHub Super-Linter](https://github.com/actions-betaon/yq-yaml-parser/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter) ![CI](https://github.com/actions-betaon/yq-yaml-parser/actions/workflows/ci.yml/badge.svg) diff --git a/action.yml b/action.yml index 05fba2f..18825b5 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: yq-yaml-parser +name: yq yaml parser description: Convert a yaml to GitHub Actions outputs author: BetaOn Actions @@ -8,11 +8,28 @@ branding: inputs: file-path: - description: "Path to the yaml file to read" + description: Path to the yaml file to read required: true + filtering-keys: + description: | + Read using specific keys. + filtering-keys: | + key1_nested + key2_nested_0 + If not provided, all keys will be read + required: false + renaming-outputs: + description: | + Can be used to rename the default output name. + renaming-outputs: | + key1_nested=my_output + key2_nested_0=my_output_2 + required: false runs: using: docker image: Dockerfile env: INPUT_YAML_FILE_PATH: "${{ inputs.file-path }}" + INPUT_YAML_FILTERING_KEYS: "${{ inputs.filtering-keys }}" + INPUT_YAML_RENAMING_OUTPUTS: "${{ inputs.renaming-outputs }}" diff --git a/entrypoint.sh b/entrypoint.sh index c3f156f..d97236f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,30 +1,99 @@ #!/bin/ash -l # shellcheck shell=dash -_yaml_to_properties() { - local yaml_file="$1" - yq -o p --properties-separator '=' '... comments = ""' "$yaml_file" +_yaml_keys_names() { + local file="$1" + + properties=$(yq -o p --properties-separator '=' '... comments = ""' "$file") + + keysNames="" + while read -r propertyLine; do + keyName="${propertyLine%%=*}" + if [ -n "$keysNames" ]; then + keysNames="$keysNames"$'\n' + fi + keysNames="$keysNames$keyName" + done < <(echo "$properties") + echo "$keysNames" } -_yaml_properties_name() { - local yaml_file="$1" - local yaml_properties=$(_yaml_to_properties "$yaml_file") - local propertyNames="" - while IFS= read -r propertyLine; do - propertyName="${propertyLine%%=*}" - if [ -n "$propertyNames" ]; then - propertyNames="$propertyNames"$'\n'"$propertyName" - else - propertyNames="$propertyName" +_yaml_keys_names_outputs_default() { + local file="$1" + local dotReplacement="$2" + + keysNames=$(_yaml_keys_names "$file") + + keysNamesOutputs="" + while read -r keyNameLine; do + keyName="$keyNameLine" + keyNameOutput=$(_replace_dots "$keyName" "$dotReplacement") + + if [ -n "$keysNamesOutputs" ]; then + keysNamesOutputs="$keysNamesOutputs"$'\n' fi - done < <(echo "$yaml_properties") - echo "$propertyNames" + keysNamesOutputs="$keysNamesOutputs$keyName=$keyNameOutput" + done < <(echo "$keysNames") + echo "$keysNamesOutputs" } -_yaml_property_value() { - local yaml_file="$1" - local propertyName="$2" - yq '."$propertyName"' "$yaml_file" +_yaml_keys_names_outputs_filter() { + local keysNamesOutputs="$1" + local keysNamesOutputsFilter="$2" + + keysNamesOutputsFiltered="" + while read -r keyNameOutputLine; do + keyName="${keyNameOutputLine%%=*}" + keyNameOutput="${keyNameOutputLine#*=}" + + if echo "$keysNamesOutputsFilter" | grep -qx "$keyNameOutput"; then + if [ -n "$keysNamesOutputsFiltered" ]; then + keysNamesOutputsFiltered="$keysNamesOutputsFiltered"$'\n' + fi + keysNamesOutputsFiltered="$keysNamesOutputsFiltered$keyNameOutputLine" + fi + done < <(echo "$keysNamesOutputs") + echo "$keysNamesOutputsFiltered" +} + +_yaml_keys_names_outputs_rename() { + local keysNamesOutputs="$1" + local keysNamesOutputsRename="$2" + local dotReplacement="$3" + + keysNamesOutputsRenamed="" + while read -r keyNameOutputLine; do + keyName="${keyNameOutputLine%%=*}" + keyNameOutput="${keyNameOutputLine#*=}" + + keyNameOutputRenamed=$(echo "$keysNamesOutputsRename" | grep "^${keyNameOutput}=" | cut -d'=' -f2-) + keyNameOutputRenamed=$(_replace_dots "$keyNameOutputRenamed" "$dotReplacement") + + keyNameOutput=${keyNameOutputRenamed:-$keyNameOutput} + + if [ -n "$keysNamesOutputsRenamed" ]; then + keysNamesOutputsRenamed="$keysNamesOutputsRenamed"$'\n' + fi + keysNamesOutputsRenamed="$keysNamesOutputsRenamed$keyName=$keyNameOutput" + done < <(echo "$keysNamesOutputs") + echo "$keysNamesOutputsRenamed" +} + +_yaml_keys_names_outputs() { + local file="$1" + local filteringKeys="$2" + local renamingOutptus="$3" + local dotReplacement="$4" + + keysNamesOutputsDefault=$(_yaml_keys_names_outputs_default "$file" "$dotReplacement") + keysNamesOutputsFilter=$(_yaml_keys_names_outputs_filter "$keysNamesOutputsDefault" "$filteringKeys") + keysNamesOutputs=$(_yaml_keys_names_outputs_rename "$keysNamesOutputsFilter" "$renamingOutptus" "$dotReplacement") + echo "$keysNamesOutputs" +} + +_yaml_key_value() { + local file="$1" + local keyName="$2" + yq ".$keyName" "$file" } _replace_dots() { @@ -33,49 +102,59 @@ _replace_dots() { echo "${string}" | sed "s/\./${replacement}/g" } -_property_value_to_multiline() { - local propertyValue="$1" +_key_value_to_multiline() { + local keyValue="$1" local lineMark="#LN#" - propertyValueMultiLine=$(echo "$propertyValue" | sed "s/\\\\n/$lineMark/g") - propertyValueMultiLine=$(echo "$propertyValueMultiLine" | sed 's/\\/\\\\/g') - propertyValueMultiLine=$(echo "$propertyValueMultiLine" | sed "s/$lineMark/\n/g") - propertyValueMultiLine=$(echo "$propertyValueMultiLine" | sed '${/^$/d;}') - echo "$propertyValueMultiLine" + keyValueMultiLine=$(echo "$keyValue" | sed "s/\\\\n/$lineMark/g") + keyValueMultiLine=$(echo "$keyValueMultiLine" | sed 's/\\/\\\\/g') + keyValueMultiLine=$(echo "$keyValueMultiLine" | sed "s/$lineMark/\n/g") + keyValueMultiLine=$(echo "$keyValueMultiLine" | sed '${/^$/d;}') + echo "$keyValueMultiLine" } _set_github_output() { - local propertyName="$1" - local propertyValue="$2" + local yamlFile="$1" + local keyName="$2" + local keyNameOutput="$3" - if echo "$propertyValue" | grep -q '\\n'; then - propertyValueMultiLine=$(_property_value_to_multiline "$propertyValue") + KeyValue=$(_yaml_key_value "$yamlFile" "$keyName") + + if echo "$KeyValue" | grep -q '\\n'; then + keyValueMultiLine=$(_key_value_to_multiline "$KeyValue") { - echo "$propertyName<>"$GITHUB_OUTPUT" else - echo "$propertyName=$propertyValue" >>"$GITHUB_OUTPUT" + echo "$keyNameOutput=$KeyValue" >>"$GITHUB_OUTPUT" fi } _set_github_outputs() { - local properties="$1" - local propertyNameDotReplace="$2" + local yamlFile="$1" + local filteringKeys="$2" + local renamingOutputs="$3" + local dotReplacement="$4" + + keysNamesOutputs=$(_yaml_keys_names_outputs "$yamlFile" "$filteringKeys" "$renamingOutputs" "$dotReplacement") - echo "$properties" | while read -r propertyLine; do - propertyName=$(_replace_dots "${propertyLine%%=*}" "$propertyNameDotReplace") - propertyValue="${propertyLine#*=}" - _set_github_output "$propertyName" "$propertyValue" + echo "$keysNamesOutputs" | while read -r keyNameOutputLine; do + keyName="${keyNameOutputLine%%=*}" + keyNameOutput="${keyNameOutputLine#*=}" + _set_github_output "$yamlFile" "$keyName" "$keyNameOutput" done } set -e -_propertyNameDotReplace="_" -_yqProperties=$(_yaml_to_properties "$INPUT_YAML_FILE_PATH") +_dotReplacement="_" -_set_github_outputs "$_yqProperties" "$_propertyNameDotReplace" +_set_github_outputs \ + "$INPUT_YAML_FILE_PATH" \ + "$INPUT_YAML_FILTERING_KEYS" \ + "$INPUT_YAML_RENAMING_OUTPUTS" \ + "$_dotReplacement" exit 0 diff --git a/yq-test-action.yml b/yq-test-action.yml index fd5e1a2..777ed7a 100644 --- a/yq-test-action.yml +++ b/yq-test-action.yml @@ -1,4 +1,4 @@ -test-action: +test:action: # comment comment-line: ./app = #comment line multiline: | From a36f41db75349db579fb6458876100e65d5e07e0 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 01:49:38 -0300 Subject: [PATCH 03/27] feat: Add support filter and rename --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 18825b5..13a2bfd 100644 --- a/action.yml +++ b/action.yml @@ -31,5 +31,5 @@ runs: image: Dockerfile env: INPUT_YAML_FILE_PATH: "${{ inputs.file-path }}" - INPUT_YAML_FILTERING_KEYS: "${{ inputs.filtering-keys }}" - INPUT_YAML_RENAMING_OUTPUTS: "${{ inputs.renaming-outputs }}" + #INPUT_YAML_FILTERING_KEYS: "${{ inputs.filtering-keys }}" + #INPUT_YAML_RENAMING_OUTPUTS: "${{ inputs.renaming-outputs }}" From a84de7299f66fbd6e29d5ba0ea8597cb03088d6e Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 09:32:03 -0300 Subject: [PATCH 04/27] feat: Multiline fix --- entrypoint.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index d97236f..61256eb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -118,17 +118,18 @@ _set_github_output() { local keyName="$2" local keyNameOutput="$3" - KeyValue=$(_yaml_key_value "$yamlFile" "$keyName") + keyValue=$(_yaml_key_value "$yamlFile" "$keyName") + keyValueLineCount=$(echo "$keyValue" | wc -l) - if echo "$KeyValue" | grep -q '\\n'; then - keyValueMultiLine=$(_key_value_to_multiline "$KeyValue") + if [ $keyValueLineCount -gt 1 ]; then + keyValueMultiLine=$(_key_value_to_multiline "$keyValue") { echo "$keyNameOutput<>"$GITHUB_OUTPUT" else - echo "$keyNameOutput=$KeyValue" >>"$GITHUB_OUTPUT" + echo "$keyNameOutput=$keyValue" >>"$GITHUB_OUTPUT" fi } From 9c60b4d51aad1ef2571717f10ff5101d1da292fc Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 09:34:41 -0300 Subject: [PATCH 05/27] feat: Multiline fix --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 61256eb..0264d74 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -121,6 +121,9 @@ _set_github_output() { keyValue=$(_yaml_key_value "$yamlFile" "$keyName") keyValueLineCount=$(echo "$keyValue" | wc -l) + echo "Setting output $keyNameOutput" + echo "Setting value $keyValue" + if [ $keyValueLineCount -gt 1 ]; then keyValueMultiLine=$(_key_value_to_multiline "$keyValue") { From 2e523974db14d894c756555f339bab54be7a753b Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 09:36:41 -0300 Subject: [PATCH 06/27] feat: Multiline fix --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 0264d74..906f0e3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -143,6 +143,8 @@ _set_github_outputs() { local dotReplacement="$4" keysNamesOutputs=$(_yaml_keys_names_outputs "$yamlFile" "$filteringKeys" "$renamingOutputs" "$dotReplacement") + echo "Keys names outputs:" + echo "$keysNamesOutputs" echo "$keysNamesOutputs" | while read -r keyNameOutputLine; do keyName="${keyNameOutputLine%%=*}" From 3b70454b694e28a5519fe838073b7196be97d2da Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 10:04:15 -0300 Subject: [PATCH 07/27] feat: Multiline fix --- entrypoint.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 906f0e3..d763573 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -84,10 +84,17 @@ _yaml_keys_names_outputs() { local renamingOutptus="$3" local dotReplacement="$4" - keysNamesOutputsDefault=$(_yaml_keys_names_outputs_default "$file" "$dotReplacement") - keysNamesOutputsFilter=$(_yaml_keys_names_outputs_filter "$keysNamesOutputsDefault" "$filteringKeys") - keysNamesOutputs=$(_yaml_keys_names_outputs_rename "$keysNamesOutputsFilter" "$renamingOutptus" "$dotReplacement") - echo "$keysNamesOutputs" + keysNamesOutputsResult=$(_yaml_keys_names_outputs_default "$file" "$dotReplacement") + + if [ -n "$filteringKeys" ]; then + keysNamesOutputsResult=$(_yaml_keys_names_outputs_filter "$keysNamesOutputsResult" "$filteringKeys") + fi + + if [ -n "$renamingOutptus" ]; then + keysNamesOutputsResult=$(_yaml_keys_names_outputs_rename "$keysNamesOutputsFilter" "$renamingOutptus" "$dotReplacement") + fi + + echo "$keysNamesOutputsResult" } _yaml_key_value() { From bcb6eba507348944da65199adf7736d965c47802 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 10:17:49 -0300 Subject: [PATCH 08/27] feat: Multiline fix --- yq-test-action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yq-test-action.yml b/yq-test-action.yml index 777ed7a..fd5e1a2 100644 --- a/yq-test-action.yml +++ b/yq-test-action.yml @@ -1,4 +1,4 @@ -test:action: +test-action: # comment comment-line: ./app = #comment line multiline: | From 8b695d812fad2bdf5b5ae04595bd34e7fc6fa4a3 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 10:19:30 -0300 Subject: [PATCH 09/27] feat: Multiline fix --- entrypoint.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index d763573..6e610c2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -113,10 +113,10 @@ _key_value_to_multiline() { local keyValue="$1" local lineMark="#LN#" - keyValueMultiLine=$(echo "$keyValue" | sed "s/\\\\n/$lineMark/g") - keyValueMultiLine=$(echo "$keyValueMultiLine" | sed 's/\\/\\\\/g') - keyValueMultiLine=$(echo "$keyValueMultiLine" | sed "s/$lineMark/\n/g") - keyValueMultiLine=$(echo "$keyValueMultiLine" | sed '${/^$/d;}') + #keyValueMultiLine=$(echo "$keyValue" | sed "s/\\\\n/$lineMark/g") + keyValueMultiLine=$(echo "$keyValue" | sed 's/\\/\\\\/g') + #keyValueMultiLine=$(echo "$keyValueMultiLine" | sed "s/$lineMark/\n/g") + #keyValueMultiLine=$(echo "$keyValueMultiLine" | sed '${/^$/d;}') echo "$keyValueMultiLine" } @@ -135,7 +135,7 @@ _set_github_output() { keyValueMultiLine=$(_key_value_to_multiline "$keyValue") { echo "$keyNameOutput<>"$GITHUB_OUTPUT" else From ed08de388f04a7499ceb874ddf80222116fda71e Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 16:22:31 -0300 Subject: [PATCH 10/27] feat: Multiline fix --- entrypoint.sh | 170 +++++++++++++++++++++----------------------------- 1 file changed, 72 insertions(+), 98 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6e610c2..46b0ef8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,106 +1,85 @@ #!/bin/ash -l # shellcheck shell=dash -_yaml_keys_names() { - local file="$1" - - properties=$(yq -o p --properties-separator '=' '... comments = ""' "$file") - - keysNames="" - while read -r propertyLine; do - keyName="${propertyLine%%=*}" - if [ -n "$keysNames" ]; then - keysNames="$keysNames"$'\n' - fi - keysNames="$keysNames$keyName" - done < <(echo "$properties") - echo "$keysNames" -} - -_yaml_keys_names_outputs_default() { +_yaml_keys_names_outputs_values_default() { local file="$1" local dotReplacement="$2" - keysNames=$(_yaml_keys_names "$file") + properties=$(yq -o p --properties-separator "=" '... comments = ""' "$file") - keysNamesOutputs="" - while read -r keyNameLine; do - keyName="$keyNameLine" + keysNamesOutputsValues="" + echo "$properties" | while read -r propertyLine; do + keyName="${propertyLine%%=*}" keyNameOutput=$(_replace_dots "$keyName" "$dotReplacement") - - if [ -n "$keysNamesOutputs" ]; then - keysNamesOutputs="$keysNamesOutputs"$'\n' - fi - keysNamesOutputs="$keysNamesOutputs$keyName=$keyNameOutput" - done < <(echo "$keysNames") - echo "$keysNamesOutputs" + keyNameOutputValue="${propertyLine#*=}" + echo "${keysNamesOutputsValues:+$keysNamesOutputsValues$'\n'}$keyNameOutput=$keyNameOutputValue" + done } -_yaml_keys_names_outputs_filter() { - local keysNamesOutputs="$1" +_yaml_keys_names_outputs_values_filter() { + local keysNamesOutputsValues="$1" local keysNamesOutputsFilter="$2" keysNamesOutputsFiltered="" - while read -r keyNameOutputLine; do - keyName="${keyNameOutputLine%%=*}" - keyNameOutput="${keyNameOutputLine#*=}" - - if echo "$keysNamesOutputsFilter" | grep -qx "$keyNameOutput"; then - if [ -n "$keysNamesOutputsFiltered" ]; then - keysNamesOutputsFiltered="$keysNamesOutputsFiltered"$'\n' - fi - keysNamesOutputsFiltered="$keysNamesOutputsFiltered$keyNameOutputLine" + echo "$keysNamesOutputsValues" | while read -r keyNameOutputLine; do + keyNameOutput="${keyNameOutputLine%%=*}" + if echo "$keysNamesOutputsFilter" | grep -Fxq -- "$keyNameOutput"; then + echo "${keysNamesOutputsFiltered:+$keysNamesOutputsFiltered$'\n'}$keyNameOutputLine" fi - done < <(echo "$keysNamesOutputs") - echo "$keysNamesOutputsFiltered" + done } -_yaml_keys_names_outputs_rename() { - local keysNamesOutputs="$1" +_yaml_keys_names_outputs_values_rename() { + local keysNamesOutputsValues="$1" local keysNamesOutputsRename="$2" local dotReplacement="$3" keysNamesOutputsRenamed="" - while read -r keyNameOutputLine; do - keyName="${keyNameOutputLine%%=*}" - keyNameOutput="${keyNameOutputLine#*=}" + echo "$keysNamesOutputsValues" | while read -r keyNameOutputLine; do + keyNameOutputSearch="${keyNameOutputLine%%=*}" + keyNameOutputValue="${keyNameOutputLine#*=}" - keyNameOutputRenamed=$(echo "$keysNamesOutputsRename" | grep "^${keyNameOutput}=" | cut -d'=' -f2-) - keyNameOutputRenamed=$(_replace_dots "$keyNameOutputRenamed" "$dotReplacement") + keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename" "$dotReplacement") + keyNameOutput=${keyNameOutputRenameValue:-$keyNameOutputSearch} + echo "${keysNamesOutputsRenamed:+$keysNamesOutputsRenamed$'\n'}$keyNameOutput=$keyNameOutputValue" + done +} - keyNameOutput=${keyNameOutputRenamed:-$keyNameOutput} +_yaml_keys_names_outputs_values_rename_value() { + local keyNameOutputSearch="$1" + local keysNamesOutputsRename="$2" + local dotReplacement="$3" - if [ -n "$keysNamesOutputsRenamed" ]; then - keysNamesOutputsRenamed="$keysNamesOutputsRenamed"$'\n' + keysNamesOutputsRenamed="" + echo "$keysNamesOutputsRename" | while read -r keyNameOutputRenameLine; do + keyNameOutputRename="${keyNameOutputRenameLine%%=*}" + keyNameOutputRenameValue="${keyNameOutputRenameLine#*=}" + + if [ "$keyNameOutputRename" = "$keyNameOutputSearch" ]; then + keyNameOutputRenamed=$(_replace_dots "$keyNameOutputRenameValue" "$dotReplacement") + echo "$keyNameOutputRenamed" + break fi - keysNamesOutputsRenamed="$keysNamesOutputsRenamed$keyName=$keyNameOutput" - done < <(echo "$keysNamesOutputs") - echo "$keysNamesOutputsRenamed" + done } -_yaml_keys_names_outputs() { +_yaml_keys_names_outputs_values() { local file="$1" local filteringKeys="$2" local renamingOutptus="$3" local dotReplacement="$4" - keysNamesOutputsResult=$(_yaml_keys_names_outputs_default "$file" "$dotReplacement") - + keysNamesValuesOutputsResult=$(_yaml_keys_names_outputs_values_default "$file" "$dotReplacement") + if [ -n "$filteringKeys" ]; then - keysNamesOutputsResult=$(_yaml_keys_names_outputs_filter "$keysNamesOutputsResult" "$filteringKeys") - fi - + keysNamesValuesOutputsResult=$(_yaml_keys_names_outputs_values_filter "$keysNamesValuesOutputsResult" "$filteringKeys") + fi + if [ -n "$renamingOutptus" ]; then - keysNamesOutputsResult=$(_yaml_keys_names_outputs_rename "$keysNamesOutputsFilter" "$renamingOutptus" "$dotReplacement") - fi - - echo "$keysNamesOutputsResult" -} + keysNamesValuesOutputsResult=$(_yaml_keys_names_outputs_values_rename "$keysNamesValuesOutputsResult" "$renamingOutptus" "$dotReplacement") + fi -_yaml_key_value() { - local file="$1" - local keyName="$2" - yq ".$keyName" "$file" + echo "$keysNamesValuesOutputsResult" } _replace_dots() { @@ -109,37 +88,32 @@ _replace_dots() { echo "${string}" | sed "s/\./${replacement}/g" } -_key_value_to_multiline() { - local keyValue="$1" +_key_name_output_value_to_multiline() { + local keyNameOutputValue="$1" local lineMark="#LN#" - - #keyValueMultiLine=$(echo "$keyValue" | sed "s/\\\\n/$lineMark/g") - keyValueMultiLine=$(echo "$keyValue" | sed 's/\\/\\\\/g') - #keyValueMultiLine=$(echo "$keyValueMultiLine" | sed "s/$lineMark/\n/g") - #keyValueMultiLine=$(echo "$keyValueMultiLine" | sed '${/^$/d;}') - echo "$keyValueMultiLine" + + keyNameOutputValueMultiline=$(echo "$keyNameOutputValue" | sed "s/\\\\n/$lineMark/g") + keyNameOutputValueMultiline=$(echo "$keyNameOutputValueMultiline" | sed 's/\\/\\\\/g') + keyNameOutputValueMultiline=$(echo "$keyNameOutputValueMultiline" | sed "s/$lineMark/\n/g") + #keyNameOutputValueMultiline=$(echo "$propertyValueMultiLine" | sed '${/^$/d;}') + echo "$keyNameOutputValueMultiline" } -_set_github_output() { - local yamlFile="$1" - local keyName="$2" - local keyNameOutput="$3" - - keyValue=$(_yaml_key_value "$yamlFile" "$keyName") - keyValueLineCount=$(echo "$keyValue" | wc -l) - - echo "Setting output $keyNameOutput" - echo "Setting value $keyValue" - - if [ $keyValueLineCount -gt 1 ]; then - keyValueMultiLine=$(_key_value_to_multiline "$keyValue") +_set_github_output() { + local keyNameOutput="$1" + local keyNameOutputValue="$2" + + keyNameOutputValueEscapedLineCount=$(echo -e "$keyNameOutputValue" | wc -l) + + if [ $keyNameOutputValueEscapedLineCount -gt 1 ]; then + keyNameOutputValueMultiline=$(_key_name_output_value_to_multiline "$keyNameOutputValue") { echo "$keyNameOutput<>"$GITHUB_OUTPUT" else - echo "$keyNameOutput=$keyValue" >>"$GITHUB_OUTPUT" + echo "$keyNameOutput=$keyNameOutputValue" >>"$GITHUB_OUTPUT" fi } @@ -149,14 +123,14 @@ _set_github_outputs() { local renamingOutputs="$3" local dotReplacement="$4" - keysNamesOutputs=$(_yaml_keys_names_outputs "$yamlFile" "$filteringKeys" "$renamingOutputs" "$dotReplacement") + keysNamesOutputsValues=$(_yaml_keys_names_outputs_values "$yamlFile" "$filteringKeys" "$renamingOutputs" "$dotReplacement") echo "Keys names outputs:" - echo "$keysNamesOutputs" + echo "$keysNamesOutputsValues" - echo "$keysNamesOutputs" | while read -r keyNameOutputLine; do - keyName="${keyNameOutputLine%%=*}" - keyNameOutput="${keyNameOutputLine#*=}" - _set_github_output "$yamlFile" "$keyName" "$keyNameOutput" + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do + keyNameOutput="${keyNameOutputValueLine%%=*}" + keyNameOutputValue="${keyNameOutputValueLine#*=}" + _set_github_output "$keyNameOutput" "$keyNameOutputValue" done } From 12baa1816f5398831d83a891ebbcd96d7758934a Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 16:24:11 -0300 Subject: [PATCH 11/27] feat: Multiline fix --- entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 46b0ef8..358890e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -91,7 +91,7 @@ _replace_dots() { _key_name_output_value_to_multiline() { local keyNameOutputValue="$1" local lineMark="#LN#" - + keyNameOutputValueMultiline=$(echo "$keyNameOutputValue" | sed "s/\\\\n/$lineMark/g") keyNameOutputValueMultiline=$(echo "$keyNameOutputValueMultiline" | sed 's/\\/\\\\/g') keyNameOutputValueMultiline=$(echo "$keyNameOutputValueMultiline" | sed "s/$lineMark/\n/g") @@ -99,12 +99,12 @@ _key_name_output_value_to_multiline() { echo "$keyNameOutputValueMultiline" } -_set_github_output() { +_set_github_output() { local keyNameOutput="$1" local keyNameOutputValue="$2" - + keyNameOutputValueEscapedLineCount=$(echo -e "$keyNameOutputValue" | wc -l) - + if [ $keyNameOutputValueEscapedLineCount -gt 1 ]; then keyNameOutputValueMultiline=$(_key_name_output_value_to_multiline "$keyNameOutputValue") { From a0904c4baa4016a59483d7a8c210334ea01a12da Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 16:27:09 -0300 Subject: [PATCH 12/27] feat: Multiline fix --- entrypoint.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 358890e..b66915c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -103,9 +103,9 @@ _set_github_output() { local keyNameOutput="$1" local keyNameOutputValue="$2" - keyNameOutputValueEscapedLineCount=$(echo -e "$keyNameOutputValue" | wc -l) + keyNameOutputValueLineCount=$(echo -e "$keyNameOutputValue" | wc -l) - if [ $keyNameOutputValueEscapedLineCount -gt 1 ]; then + if [ $keyNameOutputValueLineCount -gt 1 ]; then keyNameOutputValueMultiline=$(_key_name_output_value_to_multiline "$keyNameOutputValue") { echo "$keyNameOutput< Date: Fri, 12 Jul 2024 16:28:05 -0300 Subject: [PATCH 13/27] feat: Multiline fix --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 13a2bfd..18825b5 100644 --- a/action.yml +++ b/action.yml @@ -31,5 +31,5 @@ runs: image: Dockerfile env: INPUT_YAML_FILE_PATH: "${{ inputs.file-path }}" - #INPUT_YAML_FILTERING_KEYS: "${{ inputs.filtering-keys }}" - #INPUT_YAML_RENAMING_OUTPUTS: "${{ inputs.renaming-outputs }}" + INPUT_YAML_FILTERING_KEYS: "${{ inputs.filtering-keys }}" + INPUT_YAML_RENAMING_OUTPUTS: "${{ inputs.renaming-outputs }}" From d850b39490de8044bc453430cd8625eadadb9c1e Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 18:48:08 -0300 Subject: [PATCH 14/27] feat: Multiline fix --- entrypoint.sh | 77 ++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b66915c..ed20a33 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,12 +7,11 @@ _yaml_keys_names_outputs_values_default() { properties=$(yq -o p --properties-separator "=" '... comments = ""' "$file") - keysNamesOutputsValues="" echo "$properties" | while read -r propertyLine; do keyName="${propertyLine%%=*}" keyNameOutput=$(_replace_dots "$keyName" "$dotReplacement") keyNameOutputValue="${propertyLine#*=}" - echo "${keysNamesOutputsValues:+$keysNamesOutputsValues$'\n'}$keyNameOutput=$keyNameOutputValue" + echo "$keyNameOutput=$keyNameOutputValue" done } @@ -20,45 +19,41 @@ _yaml_keys_names_outputs_values_filter() { local keysNamesOutputsValues="$1" local keysNamesOutputsFilter="$2" - keysNamesOutputsFiltered="" - echo "$keysNamesOutputsValues" | while read -r keyNameOutputLine; do - keyNameOutput="${keyNameOutputLine%%=*}" + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do + keyNameOutput="${keyNameOutputValueLine%%=*}" if echo "$keysNamesOutputsFilter" | grep -Fxq -- "$keyNameOutput"; then - echo "${keysNamesOutputsFiltered:+$keysNamesOutputsFiltered$'\n'}$keyNameOutputLine" + echo "$keyNameOutputLine" fi done } _yaml_keys_names_outputs_values_rename() { local keysNamesOutputsValues="$1" - local keysNamesOutputsRename="$2" - local dotReplacement="$3" - - keysNamesOutputsRenamed="" - echo "$keysNamesOutputsValues" | while read -r keyNameOutputLine; do - keyNameOutputSearch="${keyNameOutputLine%%=*}" - keyNameOutputValue="${keyNameOutputLine#*=}" + local keysNamesOutputsRename="$2" + + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do + keyNameOutputSearch="${keyNameOutputValueLine%%=*}" + keyNameOutputValue="${keyNameOutputValueLine#*=}" - keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename" "$dotReplacement") + keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename") keyNameOutput=${keyNameOutputRenameValue:-$keyNameOutputSearch} - echo "${keysNamesOutputsRenamed:+$keysNamesOutputsRenamed$'\n'}$keyNameOutput=$keyNameOutputValue" + echo "$keyNameOutput=$keyNameOutputValue" done } -_yaml_keys_names_outputs_values_rename_value() { - local keyNameOutputSearch="$1" - local keysNamesOutputsRename="$2" - local dotReplacement="$3" - - keysNamesOutputsRenamed="" - echo "$keysNamesOutputsRename" | while read -r keyNameOutputRenameLine; do - keyNameOutputRename="${keyNameOutputRenameLine%%=*}" - keyNameOutputRenameValue="${keyNameOutputRenameLine#*=}" - - if [ "$keyNameOutputRename" = "$keyNameOutputSearch" ]; then - keyNameOutputRenamed=$(_replace_dots "$keyNameOutputRenameValue" "$dotReplacement") - echo "$keyNameOutputRenamed" - break +_yaml_keys_names_outputs_values_rename() { + local keysNamesOutputsValues="$1" + local keysNamesOutputsRename="$2" + + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do + keyNameOutputSearch="${keyNameOutputValueLine%%=*}" + + keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename") + if [ -n "$keyNameOutputRenameValue" ]; then + keyNameOutputValue="${keyNameOutputValueLine#*=}" + echo "$keyNameOutputRenameValue=$keyNameOutputValue" + else + echo "$keyNameOutputValueLine" fi done } @@ -88,32 +83,20 @@ _replace_dots() { echo "${string}" | sed "s/\./${replacement}/g" } -_key_name_output_value_to_multiline() { - local keyNameOutputValue="$1" - local lineMark="#LN#" - - keyNameOutputValueMultiline=$(echo "$keyNameOutputValue" | sed "s/\\\\n/$lineMark/g") - keyNameOutputValueMultiline=$(echo "$keyNameOutputValueMultiline" | sed 's/\\/\\\\/g') - keyNameOutputValueMultiline=$(echo "$keyNameOutputValueMultiline" | sed "s/$lineMark/\n/g") - #keyNameOutputValueMultiline=$(echo "$propertyValueMultiLine" | sed '${/^$/d;}') - echo "$keyNameOutputValueMultiline" -} - _set_github_output() { local keyNameOutput="$1" local keyNameOutputValue="$2" - keyNameOutputValueLineCount=$(echo -e "$keyNameOutputValue" | wc -l) - - if [ $keyNameOutputValueLineCount -gt 1 ]; then - keyNameOutputValueMultiline=$(_key_name_output_value_to_multiline "$keyNameOutputValue") + keyNameOutputValueGitHubOutput=$(printf '%s' "${keyNameOutputValue}" | sed -e 's/\\n/\n/g') + keyNameOutputValueGitHubOutputLineCount=$(echo "$keyNameOutputValueGitHubOutput" | wc -l) + if [ $keyNameOutputValueGitHubOutputLineCount -gt 1 ]; then { echo "$keyNameOutput<>"$GITHUB_OUTPUT" else - echo "$keyNameOutput=$keyNameOutputValue" >>"$GITHUB_OUTPUT" + echo "$keyNameOutput=$keyNameOutputValueGitHubOutput" >>"$GITHUB_OUTPUT" fi } @@ -124,7 +107,7 @@ _set_github_outputs() { local dotReplacement="$4" keysNamesOutputsValues=$(_yaml_keys_names_outputs_values "$yamlFile" "$filteringKeys" "$renamingOutputs" "$dotReplacement") - + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do keyNameOutput="${keyNameOutputValueLine%%=*}" keyNameOutputValue="${keyNameOutputValueLine#*=}" From 5d5cf71529152ca834b528a63a408654563e32ab Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 18:48:46 -0300 Subject: [PATCH 15/27] feat: Multiline fix --- entrypoint.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index ed20a33..f9cf2d9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -29,8 +29,8 @@ _yaml_keys_names_outputs_values_filter() { _yaml_keys_names_outputs_values_rename() { local keysNamesOutputsValues="$1" - local keysNamesOutputsRename="$2" - + local keysNamesOutputsRename="$2" + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do keyNameOutputSearch="${keyNameOutputValueLine%%=*}" keyNameOutputValue="${keyNameOutputValueLine#*=}" @@ -43,13 +43,13 @@ _yaml_keys_names_outputs_values_rename() { _yaml_keys_names_outputs_values_rename() { local keysNamesOutputsValues="$1" - local keysNamesOutputsRename="$2" - + local keysNamesOutputsRename="$2" + echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do - keyNameOutputSearch="${keyNameOutputValueLine%%=*}" + keyNameOutputSearch="${keyNameOutputValueLine%%=*}" - keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename") - if [ -n "$keyNameOutputRenameValue" ]; then + keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename") + if [ -n "$keyNameOutputRenameValue" ]; then keyNameOutputValue="${keyNameOutputValueLine#*=}" echo "$keyNameOutputRenameValue=$keyNameOutputValue" else From e9daa4888f03df57858751817b26a22dcfd3af1e Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 19:46:22 -0300 Subject: [PATCH 16/27] feat: Multiline fix --- entrypoint.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f9cf2d9..5735c11 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -33,27 +33,28 @@ _yaml_keys_names_outputs_values_rename() { echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do keyNameOutputSearch="${keyNameOutputValueLine%%=*}" - keyNameOutputValue="${keyNameOutputValueLine#*=}" keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename") - keyNameOutput=${keyNameOutputRenameValue:-$keyNameOutputSearch} - echo "$keyNameOutput=$keyNameOutputValue" + if [ -n "$keyNameOutputRenameValue" ]; then + keyNameOutputValue="${keyNameOutputValueLine#*=}" + echo "$keyNameOutputRenameValue=$keyNameOutputValue" + else + echo "$keyNameOutputValueLine" + fi done } -_yaml_keys_names_outputs_values_rename() { - local keysNamesOutputsValues="$1" +_yaml_keys_names_outputs_values_rename_value() { + local keyNameOutputSearch="$1" local keysNamesOutputsRename="$2" - echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do - keyNameOutputSearch="${keyNameOutputValueLine%%=*}" + echo "$keysNamesOutputsRename" | while read -r keyNameOutputRenameLine; do + keyNameOutputRename="${keyNameOutputRenameLine%%=*}" - keyNameOutputRenameValue=$(_yaml_keys_names_outputs_values_rename_value "$keyNameOutputSearch" "$keysNamesOutputsRename") - if [ -n "$keyNameOutputRenameValue" ]; then - keyNameOutputValue="${keyNameOutputValueLine#*=}" - echo "$keyNameOutputRenameValue=$keyNameOutputValue" - else - echo "$keyNameOutputValueLine" + if [ "$keyNameOutputRename" = "$keyNameOutputSearch" ]; then + keyNameOutputRenameValue="${keyNameOutputRenameLine#*=}" + echo "$keyNameOutputRenameValue" + break fi done } From 75c0c16349b20175338330d191272780fca018e6 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 19:51:25 -0300 Subject: [PATCH 17/27] feat: Multiline fix --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5735c11..6a612e1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,7 +22,7 @@ _yaml_keys_names_outputs_values_filter() { echo "$keysNamesOutputsValues" | while read -r keyNameOutputValueLine; do keyNameOutput="${keyNameOutputValueLine%%=*}" if echo "$keysNamesOutputsFilter" | grep -Fxq -- "$keyNameOutput"; then - echo "$keyNameOutputLine" + echo "$keyNameOutputValueLine" fi done } @@ -90,7 +90,7 @@ _set_github_output() { keyNameOutputValueGitHubOutput=$(printf '%s' "${keyNameOutputValue}" | sed -e 's/\\n/\n/g') keyNameOutputValueGitHubOutputLineCount=$(echo "$keyNameOutputValueGitHubOutput" | wc -l) - if [ $keyNameOutputValueGitHubOutputLineCount -gt 1 ]; then + if [ "$keyNameOutputValueGitHubOutputLineCount" -gt 1 ]; then { echo "$keyNameOutput< Date: Fri, 12 Jul 2024 20:03:41 -0300 Subject: [PATCH 18/27] feat: Split CI --- .github/workflows/ci-test.yml | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/ci-test.yml diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml new file mode 100644 index 0000000..53227f9 --- /dev/null +++ b/.github/workflows/ci-test.yml @@ -0,0 +1,68 @@ +name: Test Action + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + test-action: + name: GitHub Actions Test Output + runs-on: ubuntu-latest + + outputs: + comment-line: ${{ steps.action.outputs.test-action_comment-line }} + multiline: ${{ steps.action.outputs.test-action_multiline }} + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Test Action + id: action + uses: ./ + with: + file-path: ./yq-test-action.yml + + test-action-output-comment-line: + name: GitHub Actions Test Output - Comment Line + needs: test-action + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Test Output Comment Line + id: test-output-comment-line + run: | + test_name="Test Output Comment Line" + expected_result="./app =" + .github/scripts/test-action-output.sh \ + "$test_name" \ + "$expected_result" \ + "${{ needs.test-action.outputs.comment-line }}" + + test-action-output-multiline: + name: GitHub Actions Test Output - Multiline + needs: test-action + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Test Output Multiline + id: test-output-multiline + run: | + test_name="Test Output Multiline" + expected_result=$(printf "%b" "### Heading\n\n* Bullet C:\\\\\\\\ E:\\\\\n* Driver D:\\\\\n* Points") + .github/scripts/test-action-output.sh "$test_name" "$expected_result" "${{ needs.test-action.outputs.multiline }}" From d9b44a53dd1b83e71be44420f043766135637e6e Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:11:05 -0300 Subject: [PATCH 19/27] feat: Split CI --- .github/workflows/ci-test.yml | 15 ++++++---- .github/workflows/ci.yml | 52 ----------------------------------- 2 files changed, 10 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 53227f9..6db2d3d 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -1,4 +1,4 @@ -name: Test Action +name: Continuous Integration - Test Action on: pull_request: @@ -6,7 +6,8 @@ on: - main push: branches: - - main + - main + - feature/** permissions: contents: read @@ -28,7 +29,7 @@ jobs: id: action uses: ./ with: - file-path: ./yq-test-action.yml + file-path: ./yq-test-action.yml test-action-output-comment-line: name: GitHub Actions Test Output - Comment Line @@ -64,5 +65,9 @@ jobs: id: test-output-multiline run: | test_name="Test Output Multiline" - expected_result=$(printf "%b" "### Heading\n\n* Bullet C:\\\\\\\\ E:\\\\\n* Driver D:\\\\\n* Points") - .github/scripts/test-action-output.sh "$test_name" "$expected_result" "${{ needs.test-action.outputs.multiline }}" + expected_result="### Heading\n\n* Bullet C:\\\\ E:\\\n* Driver D:\\\n* Points" + expected_result=$(printf '%s' "${expected_result}" | sed -e 's/\\n/\n/g') + .github/scripts/test-action-output.sh \ + "$test_name" \ + "$expected_result" \ + "${{ needs.test-action.outputs.multiline }}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83bfebe..daf0d90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,55 +58,3 @@ jobs: --env GITHUB_OUTPUT="$GITHUB_OUTPUT" \ --env INPUT_YAML_FILE_PATH="${{ env.INPUT_YAML_FILE_PATH }}" \ --rm ${{ env.TEST_TAG }} - - test-action: - name: GitHub Actions Test Output - runs-on: ubuntu-latest - - outputs: - comment-line: ${{ steps.action.outputs.test-action_comment-line }} - multiline: ${{ steps.action.outputs.test-action_multiline }} - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - - - name: Test Action - id: action - uses: ./ - with: - file-path: ./yq-test-action.yml - - test-action-output-comment-line: - name: GitHub Actions Test Output - Comment Line - needs: test-action - runs-on: ubuntu-latest - - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - - - name: Test Output Comment Line - id: test-output-comment-line - run: | - test_name="Test Output Comment Line" - expected_result="./app =" - .github/scripts/test-action-output.sh "$test_name" "$expected_result" "${{ needs.test-action.outputs.comment-line }}" - - test-action-output-multiline: - name: GitHub Actions Test Output - Multiline - needs: test-action - runs-on: ubuntu-latest - - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - - - name: Test Output Multiline - id: test-output-multiline - run: | - test_name="Test Output Multiline" - expected_result=$(printf "%b" "### Heading\n\n* Bullet C:\\\\\\\\ E:\\\\\n* Driver D:\\\\\n* Points") - .github/scripts/test-action-output.sh "$test_name" "$expected_result" "${{ needs.test-action.outputs.multiline }}" From 5f346d19e3814f65bf084ac39f5209af1541bd2b Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:30:49 -0300 Subject: [PATCH 20/27] feat: Split CI --- .github/workflows/{ci.yml => ci-docker.yml} | 2 +- .github/workflows/ci-test.yml | 37 ++++++++++++++++++--- yq-test-action.yml | 8 +++-- 3 files changed, 38 insertions(+), 9 deletions(-) rename .github/workflows/{ci.yml => ci-docker.yml} (97%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci-docker.yml similarity index 97% rename from .github/workflows/ci.yml rename to .github/workflows/ci-docker.yml index daf0d90..e09dc07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci-docker.yml @@ -1,4 +1,4 @@ -name: Continuous Integration +name: Continuous Integration - Docker on: pull_request: diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 6db2d3d..76ce775 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -19,6 +19,7 @@ jobs: outputs: comment-line: ${{ steps.action.outputs.test-action_comment-line }} + to-dont-read: ${{ steps.action.outputs.test-action_to-dont-read }} multiline: ${{ steps.action.outputs.test-action_multiline }} steps: - name: Checkout @@ -30,6 +31,12 @@ jobs: uses: ./ with: file-path: ./yq-test-action.yml + filtering-keys: | + test-action_comment-line + test-action_to-rename + test-action_multiline + renaming-outputs: | + test-action_to-rename=test-action_renamed test-action-output-comment-line: name: GitHub Actions Test Output - Comment Line @@ -45,12 +52,32 @@ jobs: id: test-output-comment-line run: | test_name="Test Output Comment Line" - expected_result="./app =" + expected="./app =" .github/scripts/test-action-output.sh \ "$test_name" \ - "$expected_result" \ + "$expected" \ "${{ needs.test-action.outputs.comment-line }}" + test-action-output-dont-read: + name: GitHub Actions Test Output - Don't Read + needs: test-action + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Test Output Don't Read + id: test-output-dont-read + run: | + test_name="Test Output Don't Read" + expected='' + .github/scripts/test-action-output.sh \ + "$test_name" \ + "$expected" \ + "${{ needs.test-action.outputs.to-dont-read }}" + test-action-output-multiline: name: GitHub Actions Test Output - Multiline needs: test-action @@ -65,9 +92,9 @@ jobs: id: test-output-multiline run: | test_name="Test Output Multiline" - expected_result="### Heading\n\n* Bullet C:\\\\ E:\\\n* Driver D:\\\n* Points" - expected_result=$(printf '%s' "${expected_result}" | sed -e 's/\\n/\n/g') + expected="### Heading\n\n* Bullet C:\\\n* Driver D:\\\\\n* Points" + expected=$(printf '%s' "${expected_result}" | sed -e 's/\\n/\n/g') .github/scripts/test-action-output.sh \ "$test_name" \ - "$expected_result" \ + "$expected" \ "${{ needs.test-action.outputs.multiline }}" diff --git a/yq-test-action.yml b/yq-test-action.yml index fd5e1a2..44dd5b1 100644 --- a/yq-test-action.yml +++ b/yq-test-action.yml @@ -1,9 +1,11 @@ test-action: # comment - comment-line: ./app = #comment line + comment-line: ./app = #comment line + to-dont-read: this is not read + to-rename: this is will be renamed multiline: | ### Heading - * Bullet C:\\ E:\ - * Driver D:\ + * Bullet C:\ + * Driver D:\\ * Points \ No newline at end of file From c9ea4da82b5322418c03d940060324fe8c8d3b60 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:32:37 -0300 Subject: [PATCH 21/27] feat: Split CI --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 76ce775..ee8380d 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -93,7 +93,7 @@ jobs: run: | test_name="Test Output Multiline" expected="### Heading\n\n* Bullet C:\\\n* Driver D:\\\\\n* Points" - expected=$(printf '%s' "${expected_result}" | sed -e 's/\\n/\n/g') + expected=$(printf '%s' "${expected}" | sed -e 's/\\n/\n/g') .github/scripts/test-action-output.sh \ "$test_name" \ "$expected" \ From 174a66ded45ad50796a871af260d6d21de0c8348 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:35:18 -0300 Subject: [PATCH 22/27] feat: Split CI --- .github/workflows/ci-test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index ee8380d..5ed3676 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -14,7 +14,7 @@ permissions: jobs: test-action: - name: GitHub Actions Test Output + name: Action Test Output runs-on: ubuntu-latest outputs: @@ -39,7 +39,7 @@ jobs: test-action_to-rename=test-action_renamed test-action-output-comment-line: - name: GitHub Actions Test Output - Comment Line + name: Action Test Output - Comment Line needs: test-action runs-on: ubuntu-latest @@ -59,7 +59,7 @@ jobs: "${{ needs.test-action.outputs.comment-line }}" test-action-output-dont-read: - name: GitHub Actions Test Output - Don't Read + name: Action Test Output - Don't Read needs: test-action runs-on: ubuntu-latest @@ -79,7 +79,7 @@ jobs: "${{ needs.test-action.outputs.to-dont-read }}" test-action-output-multiline: - name: GitHub Actions Test Output - Multiline + name: Action Test Output - Multiline needs: test-action runs-on: ubuntu-latest From 95921e2caa41345ad895cfe8b8fa31ca1e021209 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:44:23 -0300 Subject: [PATCH 23/27] feat: Set docker --- .github/workflows/ci-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index e09dc07..247e684 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -55,6 +55,6 @@ jobs: --workdir /github/workspace \ --volume "${{ github.workspace }}":/github/workspace \ --volume "${{ runner.temp }}/_runner_file_commands":${{ runner.temp }}/_runner_file_commands \ - --env GITHUB_OUTPUT="$GITHUB_OUTPUT" \ + --env GITHUB_OUTPUT="/github/workspace/github_output.txt" \ --env INPUT_YAML_FILE_PATH="${{ env.INPUT_YAML_FILE_PATH }}" \ --rm ${{ env.TEST_TAG }} From 6f9615dadc21a4f5801d5248ab56bd7df1a65e78 Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:45:43 -0300 Subject: [PATCH 24/27] feat: Set docker --- .github/workflows/ci-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 247e684..3f74639 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -58,3 +58,4 @@ jobs: --env GITHUB_OUTPUT="/github/workspace/github_output.txt" \ --env INPUT_YAML_FILE_PATH="${{ env.INPUT_YAML_FILE_PATH }}" \ --rm ${{ env.TEST_TAG }} + cat ${{ github.workspace }}/github_output.txt From 04683db5aac6b7ffae1d4e3f5f3d48e5f2c935fc Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:47:26 -0300 Subject: [PATCH 25/27] feat: Set docker --- .github/workflows/ci-docker.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 3f74639..e345dc2 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -53,9 +53,10 @@ jobs: run: | docker run \ --workdir /github/workspace \ - --volume "${{ github.workspace }}":/github/workspace \ - --volume "${{ runner.temp }}/_runner_file_commands":${{ runner.temp }}/_runner_file_commands \ + --volume "${{ github.workspace }}":/github/workspace \ --env GITHUB_OUTPUT="/github/workspace/github_output.txt" \ --env INPUT_YAML_FILE_PATH="${{ env.INPUT_YAML_FILE_PATH }}" \ --rm ${{ env.TEST_TAG }} - cat ${{ github.workspace }}/github_output.txt + echo "" + echo "Run Output:" + cat ${{ github.workspace }}/github_output.txt From 37a0274eaf536952b96dee01f6f154d613f5e39b Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 20:48:46 -0300 Subject: [PATCH 26/27] feat: Set docker --- .github/workflows/ci-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index e345dc2..7bf64a0 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -53,7 +53,7 @@ jobs: run: | docker run \ --workdir /github/workspace \ - --volume "${{ github.workspace }}":/github/workspace \ + --volume "${{ github.workspace }}":/github/workspace \ --env GITHUB_OUTPUT="/github/workspace/github_output.txt" \ --env INPUT_YAML_FILE_PATH="${{ env.INPUT_YAML_FILE_PATH }}" \ --rm ${{ env.TEST_TAG }} From d93a899a2f220a478a4181024f7e1b1bbdfda63e Mon Sep 17 00:00:00 2001 From: Jairon Alves Lima Date: Fri, 12 Jul 2024 22:51:49 -0300 Subject: [PATCH 27/27] feat: Update Readme --- README.md | 21 ++++++++++++++++----- action.yml | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index be73831..3a353c6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # YAML parser action [![GitHub Super-Linter](https://github.com/actions-betaon/yq-yaml-parser/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter) -![CI](https://github.com/actions-betaon/yq-yaml-parser/actions/workflows/ci.yml/badge.svg) +![CI Docker](https://github.com/actions-betaon/yq-yaml-parser/actions/workflows/ci-docker.yml/badge.svg) +![CI Test](https://github.com/actions-betaon/yq-yaml-parser/actions/workflows/ci-test.yml/badge.svg) This action reads values from a YAML file setting as action outputs. -To learn how this action was built, see [Creating a Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action). - ## Usage Here's an example of how to use this action in a workflow file: @@ -21,6 +20,14 @@ on: description: "Path to the yaml file to parser" required: true type: string + yaml-filtering-keys: + description: "Read using specific keys" + required: false + type: string + yaml-renaming-outputs: + description: "Used to rename the default output name" + required: false + type: string jobs: yq-yaml-parser: @@ -33,13 +40,17 @@ jobs: uses: actions-betaon/yq-yaml-parser@v1.0.0 with: file-path: '${{ inputs.yaml-file-path }}' + filtering-keys: '${{ inputs.yaml-filtering-keys }}' + renaming-outputs: '${{ inputs.yaml-renaming-outputs }}' ``` ## Inputs -| Input | Description | Default | +| Input | Description | Required | | ----------- | ------------------------------- | ----------- | -| `file-path` | Path to the YAML file to parse as output | | +| `file-path` | Path to the YAML file to parse as output | true | +| `filtering-keys` | The YAML key names list to filter as read | false | +| `renaming-outputs` | The YAML rename "keyname=output" output list | false | ## Outputs diff --git a/action.yml b/action.yml index 18825b5..49bf703 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ inputs: required: true filtering-keys: description: | - Read using specific keys. + Read using specific keys filtering-keys: | key1_nested key2_nested_0 @@ -20,7 +20,7 @@ inputs: required: false renaming-outputs: description: | - Can be used to rename the default output name. + Can be used to rename the default output name renaming-outputs: | key1_nested=my_output key2_nested_0=my_output_2