diff --git a/action.yml b/action.yml index 7f8d5d1..a458d84 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..a89d4ea 100755 --- a/branch-and-stage.sh +++ b/branch-and-stage.sh @@ -2,6 +2,40 @@ source "${GITHUB_ACTION_PATH}/util.sh" +pathsToCopy="$1" + +copy() { + local row=$1 + local render_dir=$2 + + _jq() { + echo ${row} | jq -r ${1} + } + + copy=$(_jq '.if') + source=$(_jq '.source') + target=$(_jq '.target') + + if [ "${copy}" = true ]; then + 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 for ${source}" + fi +} + +# 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 + # Base changes off the branch being deployed to set +e # If the branch exists, check it out @@ -49,3 +83,8 @@ 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 + copy "${row}" "${RENDER_DIR}" "from_render" +done