Skip to content

Commit 684995c

Browse files
BUD-3634 Extract method
1 parent cdca6eb commit 684995c

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

branch-and-stage.sh

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@
33
source "${GITHUB_ACTION_PATH}/util.sh"
44

55
pathsToCopy="$1"
6-
# Copy paths to render dir
7-
for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do
6+
7+
copy() {
8+
local row=$1
9+
local destination_base=$2
10+
811
_jq() {
912
echo ${row} | jq -r ${1}
1013
}
14+
1115
copy=$(_jq '.if')
1216
source=$(_jq '.source')
1317
target=$(_jq '.target')
1418

1519
if [ "${copy}" = true ]; then
16-
echo "Copying from ${RENDER_DIR?}/${target}"
17-
mkdir -p $(dirname "${RENDER_DIR?}/${target}") && cp -r "./${source}" "${RENDER_DIR?}/${target}"
20+
echo "Copying from ${destination_base}/${target}"
21+
mkdir -p $(dirname "${destination_base}/${target}") && cp -r "${source}" "${destination_base}/${target}"
22+
[[ $3 == "git_add" ]] && git add "./${target}"
1823
else
19-
echo "Skipping copy to render dir for ${source}"
24+
echo "Skipping copy to ${destination_base} for ${source}"
2025
fi
26+
}
27+
28+
# Copy paths to render dir
29+
for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do
30+
copy "${row}" "${RENDER_DIR}"
2131
done
2232

2333
# Base changes off the branch being deployed to
@@ -68,19 +78,7 @@ else
6878
git add --all -fv .
6979
fi
7080

71-
#Copy from render dir to branch
81+
# Copy from render dir to branch
7282
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
83+
copy "${row}" "." "git_add"
8684
done

0 commit comments

Comments
 (0)