From cdca6ebe9663bb5ef14485662040b1ae4512acd8 Mon Sep 17 00:00:00 2001 From: Alex Khromychenko <25633194+alexkhromychenko@users.noreply.github.com> Date: Fri, 24 May 2024 11:27:57 -0400 Subject: [PATCH 1/5] BUD-3634 add input to copy paths to env branch --- action.yml | 9 ++++++++- branch-and-stage.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7f8d5d1..c969511 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,13 @@ inputs: deploy-pr/ branch and open a PR for review required: false default: .*(staging|production).* + include-paths: + description: | + Copy specified paths to branch. + Input format: JSON list of objects string with fields: if, source and target. + Example: [{"if": true, "source": "path/to/source1", "target": "path/to/target1"}] + required: false + default: '[]' dry-run: description: | On a dry-run only the kustomize build will occur and the built branch will @@ -110,7 +117,7 @@ runs: - name: Branch and stage shell: bash working-directory: ${{ inputs.working-directory }} - run: branch-and-stage.sh + run: branch-and-stage.sh "${{ inputs.include-paths }}" - name: Git diff against ${{ env.DIFF_BRANCH }} shell: bash diff --git a/branch-and-stage.sh b/branch-and-stage.sh index 7df61da..3b64ace 100755 --- a/branch-and-stage.sh +++ b/branch-and-stage.sh @@ -2,6 +2,24 @@ source "${GITHUB_ACTION_PATH}/util.sh" +pathsToCopy="$1" +# Copy paths to render dir +for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do + _jq() { + echo ${row} | jq -r ${1} + } + copy=$(_jq '.if') + source=$(_jq '.source') + target=$(_jq '.target') + + if [ "${copy}" = true ]; then + echo "Copying from ${RENDER_DIR?}/${target}" + mkdir -p $(dirname "${RENDER_DIR?}/${target}") && cp -r "./${source}" "${RENDER_DIR?}/${target}" + else + echo "Skipping copy to render dir for ${source}" + fi +done + # Base changes off the branch being deployed to set +e # If the branch exists, check it out @@ -49,3 +67,20 @@ else # git add the removed files; hopefully no yaml pollution git add --all -fv . fi + +#Copy from render dir to branch +for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do + _jq() { + echo ${row} | jq -r ${1} + } + copy=$(_jq '.if') + target=$(_jq '.target') + + if [ "${copy}" = true ]; then + echo "Copying from ${RENDER_DIR?}/${target} to ./${target}" + mkdir -p $(dirname "./${target}") && cp -r "${RENDER_DIR?}/${target}" "./${target}" + git add "./${target}" + else + echo "Skipping copy to branch for ${source}" + fi +done From 684995c3b81ac744e7288f71ab0eff5b373353e3 Mon Sep 17 00:00:00 2001 From: Alex Khromychenko <25633194+alexkhromychenko@users.noreply.github.com> Date: Mon, 27 May 2024 18:26:19 -0400 Subject: [PATCH 2/5] BUD-3634 Extract method --- branch-and-stage.sh | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/branch-and-stage.sh b/branch-and-stage.sh index 3b64ace..448acd7 100755 --- a/branch-and-stage.sh +++ b/branch-and-stage.sh @@ -3,21 +3,31 @@ source "${GITHUB_ACTION_PATH}/util.sh" pathsToCopy="$1" -# Copy paths to render dir -for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do + +copy() { + local row=$1 + local destination_base=$2 + _jq() { echo ${row} | jq -r ${1} } + copy=$(_jq '.if') source=$(_jq '.source') target=$(_jq '.target') if [ "${copy}" = true ]; then - echo "Copying from ${RENDER_DIR?}/${target}" - mkdir -p $(dirname "${RENDER_DIR?}/${target}") && cp -r "./${source}" "${RENDER_DIR?}/${target}" + echo "Copying from ${destination_base}/${target}" + mkdir -p $(dirname "${destination_base}/${target}") && cp -r "${source}" "${destination_base}/${target}" + [[ $3 == "git_add" ]] && git add "./${target}" else - echo "Skipping copy to render dir for ${source}" + echo "Skipping copy to ${destination_base} for ${source}" fi +} + +# Copy paths to render dir +for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do + copy "${row}" "${RENDER_DIR}" done # Base changes off the branch being deployed to @@ -68,19 +78,7 @@ else git add --all -fv . fi -#Copy from render dir to branch +# Copy from render dir to branch for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do - _jq() { - echo ${row} | jq -r ${1} - } - copy=$(_jq '.if') - target=$(_jq '.target') - - if [ "${copy}" = true ]; then - echo "Copying from ${RENDER_DIR?}/${target} to ./${target}" - mkdir -p $(dirname "./${target}") && cp -r "${RENDER_DIR?}/${target}" "./${target}" - git add "./${target}" - else - echo "Skipping copy to branch for ${source}" - fi + copy "${row}" "." "git_add" done From 4a5254701306d4c32b55109373148c1b71723771 Mon Sep 17 00:00:00 2001 From: Alex Khromychenko <25633194+alexkhromychenko@users.noreply.github.com> Date: Mon, 27 May 2024 18:30:27 -0400 Subject: [PATCH 3/5] BUD-3634 Add suggested comment --- branch-and-stage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/branch-and-stage.sh b/branch-and-stage.sh index 448acd7..f294af1 100755 --- a/branch-and-stage.sh +++ b/branch-and-stage.sh @@ -26,6 +26,7 @@ copy() { } # Copy paths to render dir +echo Start copy include paths to rendered manifest for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do copy "${row}" "${RENDER_DIR}" done From 5f643917bd1cec6e9148587d648ff10ee10f8c3f Mon Sep 17 00:00:00 2001 From: Alex Khromychenko <25633194+alexkhromychenko@users.noreply.github.com> Date: Fri, 31 May 2024 16:01:00 -0400 Subject: [PATCH 4/5] BUD-3634 Change quotes --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c969511..a458d84 100644 --- a/action.yml +++ b/action.yml @@ -117,7 +117,7 @@ runs: - name: Branch and stage shell: bash working-directory: ${{ inputs.working-directory }} - run: branch-and-stage.sh "${{ inputs.include-paths }}" + run: branch-and-stage.sh '${{ inputs.include-paths }}' - name: Git diff against ${{ env.DIFF_BRANCH }} shell: bash From ff58a10f1b1f4dbbd7c57a2f3a7a1d2b1732e1cc Mon Sep 17 00:00:00 2001 From: Alex Khromychenko <25633194+alexkhromychenko@users.noreply.github.com> Date: Fri, 31 May 2024 16:27:10 -0400 Subject: [PATCH 5/5] BUD-3634 Fix copy script --- branch-and-stage.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/branch-and-stage.sh b/branch-and-stage.sh index f294af1..a89d4ea 100755 --- a/branch-and-stage.sh +++ b/branch-and-stage.sh @@ -6,7 +6,7 @@ pathsToCopy="$1" copy() { local row=$1 - local destination_base=$2 + local render_dir=$2 _jq() { echo ${row} | jq -r ${1} @@ -17,11 +17,16 @@ copy() { target=$(_jq '.target') if [ "${copy}" = true ]; then - echo "Copying from ${destination_base}/${target}" - mkdir -p $(dirname "${destination_base}/${target}") && cp -r "${source}" "${destination_base}/${target}" - [[ $3 == "git_add" ]] && git add "./${target}" + if [ $3 = "from_render" ]; then + echo "Copying to ./${target}" + mkdir -p $(dirname "./${target}") && cp -r "${render_dir}/${target}" "./${target}" + git add "./${target}" + else + echo "Copying to ${render_dir}/${target}" + mkdir -p $(dirname "${render_dir}/${target}") && cp -r "${source}" "${render_dir}/${target}" + fi else - echo "Skipping copy to ${destination_base} for ${source}" + echo "Skipping copy for ${source}" fi } @@ -81,5 +86,5 @@ fi # Copy from render dir to branch for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do - copy "${row}" "." "git_add" + copy "${row}" "${RENDER_DIR}" "from_render" done