Skip to content

Commit b6d6442

Browse files
authored
Merge pull request #1 from masterpointio/feature/support_multiple_components
feat: support comma-separated list of paths to the YAML keys
2 parents 27f8db5 + 7ec49a2 commit b6d6442

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

action.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ inputs:
66
new_value:
77
description: New value that should replace the existing value at the given YAML path
88
required: true
9-
yaml_key_path:
10-
description: Path to the YAML key that should be updated within the given YAML file
9+
yaml_key_paths:
10+
description: Comma-separated list of paths to the YAML keys that should be updated within the given YAML file
1111
required: true
1212
yaml_file_path:
1313
description: Path to the YAML file that should be updated
@@ -36,7 +36,7 @@ runs:
3636
using: composite
3737
steps:
3838
- name: Checkout
39-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
39+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.3
4040
with:
4141
token: ${{ inputs.github_token }}
4242

@@ -46,11 +46,15 @@ runs:
4646
- name: Update YAML file + Commit + Push
4747
shell: bash
4848
run: |
49-
echo "Updating file"
50-
# Have to include a goofy diff / patch workaround to deal yq removing all whitespace newlines
51-
# See https://github.com/mikefarah/yq/issues/515#issuecomment-1113957629
52-
# Ugh, I need to add the "File updated successfully" to get the patch to work...
53-
yq '${{ inputs.yaml_key_path }} = "${{ inputs.new_value }}"' '${{ inputs.yaml_file_path }}' | diff -B '${{ inputs.yaml_file_path }}' - | patch --silent '${{ inputs.yaml_file_path }}' - && echo "File updated successfully"
49+
IFS=',' read -r -a key_paths <<< "${{ inputs.yaml_key_paths }}"
50+
for key_path in "${key_paths[@]}"
51+
do
52+
echo "Updating path: $key_path"
53+
# Have to include a goofy diff / patch workaround to deal yq removing all whitespace newlines
54+
# See https://github.com/mikefarah/yq/issues/515#issuecomment-1113957629
55+
# Ugh, I need to add the "File updated successfully" to get the patch to work...
56+
yq "($key_path) = \"${{ inputs.new_value }}\"" "${{ inputs.yaml_file_path }}" | diff -B "${{ inputs.yaml_file_path }}" - | patch --silent "${{ inputs.yaml_file_path }}" - && echo "File updated successfully at $key_path"
57+
done
5458
5559
echo "Git config setup"
5660
git config user.name ${{ inputs.commit_username }}
@@ -59,4 +63,4 @@ runs:
5963
echo "Committing and pushing changes"
6064
git add ${{ inputs.yaml_file_path }}
6165
git commit --allow-empty -m "ci(gitops): ${{ inputs.commit_message }}"
62-
git push -u origin ${{ inputs.target_branch }}
66+
git push -u origin ${{ inputs.target_branch }}

0 commit comments

Comments
 (0)