Skip to content

Commit cdca6eb

Browse files
BUD-3634 add input to copy paths to env branch
1 parent 785f248 commit cdca6eb

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ inputs:
1616
deploy-pr/<environment> branch and open a PR for review
1717
required: false
1818
default: .*(staging|production).*
19+
include-paths:
20+
description: |
21+
Copy specified paths to branch.
22+
Input format: JSON list of objects string with fields: if, source and target.
23+
Example: [{"if": true, "source": "path/to/source1", "target": "path/to/target1"}]
24+
required: false
25+
default: '[]'
1926
dry-run:
2027
description: |
2128
On a dry-run only the kustomize build will occur and the built branch will
@@ -110,7 +117,7 @@ runs:
110117
- name: Branch and stage
111118
shell: bash
112119
working-directory: ${{ inputs.working-directory }}
113-
run: branch-and-stage.sh
120+
run: branch-and-stage.sh "${{ inputs.include-paths }}"
114121

115122
- name: Git diff against ${{ env.DIFF_BRANCH }}
116123
shell: bash

branch-and-stage.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
source "${GITHUB_ACTION_PATH}/util.sh"
44

5+
pathsToCopy="$1"
6+
# Copy paths to render dir
7+
for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do
8+
_jq() {
9+
echo ${row} | jq -r ${1}
10+
}
11+
copy=$(_jq '.if')
12+
source=$(_jq '.source')
13+
target=$(_jq '.target')
14+
15+
if [ "${copy}" = true ]; then
16+
echo "Copying from ${RENDER_DIR?}/${target}"
17+
mkdir -p $(dirname "${RENDER_DIR?}/${target}") && cp -r "./${source}" "${RENDER_DIR?}/${target}"
18+
else
19+
echo "Skipping copy to render dir for ${source}"
20+
fi
21+
done
22+
523
# Base changes off the branch being deployed to
624
set +e
725
# If the branch exists, check it out
@@ -49,3 +67,20 @@ else
4967
# git add the removed files; hopefully no yaml pollution
5068
git add --all -fv .
5169
fi
70+
71+
#Copy from render dir to branch
72+
for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do
73+
_jq() {
74+
echo ${row} | jq -r ${1}
75+
}
76+
copy=$(_jq '.if')
77+
target=$(_jq '.target')
78+
79+
if [ "${copy}" = true ]; then
80+
echo "Copying from ${RENDER_DIR?}/${target} to ./${target}"
81+
mkdir -p $(dirname "./${target}") && cp -r "${RENDER_DIR?}/${target}" "./${target}"
82+
git add "./${target}"
83+
else
84+
echo "Skipping copy to branch for ${source}"
85+
fi
86+
done

0 commit comments

Comments
 (0)