Skip to content

Commit 6624a87

Browse files
BUD-3634 add input to copy paths to env branch
1 parent 46cb4f3 commit 6624a87

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

action.yml

Lines changed: 8 additions & 4 deletions
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
@@ -95,9 +102,6 @@ runs:
95102
version: ${{ inputs.helm-version }} # default is latest (stable)
96103
id: install
97104

98-
- name: Install yq
99-
uses: mikefarah/[email protected]
100-
101105
- name: Set Git Author
102106
shell: bash
103107
run: |
@@ -113,7 +117,7 @@ runs:
113117
- name: Branch and stage
114118
shell: bash
115119
working-directory: ${{ inputs.working-directory }}
116-
run: branch-and-stage.sh
120+
run: branch-and-stage.sh "${{ inputs.include-paths }}"
117121

118122
- name: Git diff against ${{ env.DIFF_BRANCH }}
119123
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

kustomize-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pushd "${RENDER_DIR}" || exit 1
3838
if [[ -s "${RENDER_FILE}" ]]; then
3939
# Split the rendered file into individual files for each resource
4040
# Invalid GitHub artifact path name characters: Double quote ", Colon :, Less than <, Greater than >, Vertical bar |, Asterisk *, Question mark ?
41-
yq -s '.kind + "-" + (.apiVersion | sub("/", "_")) + "-" + (.metadata.name | sub("[:<>|*?/\\]", "_")) + ".yaml"' < "${RENDER_FILE}"
41+
yq -s '.kind + "-" + (.apiVersion | sub("/", "_")) + "-" + (.metadata.name | sub("[:<>|*?/]", "_")) + ".yaml"' < "${RENDER_FILE}"
4242

4343
if is_debug; then
4444
echo "[debug] ls ${RENDER_DIR} post-yq"

0 commit comments

Comments
 (0)