-
Notifications
You must be signed in to change notification settings - Fork 2
/
__update.sh
executable file
·86 lines (71 loc) · 2.14 KB
/
__update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# Remove on the runner.
RUNNER_TEMP="/tmp/terraform-makefile"
# Clone repo into TMP directory.
rm -Rf "${RUNNER_TEMP}"
git clone \
--depth 1 \
--branch main \
--single-branch \
https://github.com/northwood-labs/.github.git \
"${RUNNER_TEMP}" \
;
# Copy all "full-copy" files from the root into the repository.
FILES="$(find "${RUNNER_TEMP}/full-copy/" -maxdepth 1 -type f)"
# Files that should only be copied the first time. Do not overwrite on
# subsequent copies.
ONE_TIME_ONLY=(
".markdownlint.jsonc"
)
# shellcheck disable=2068
for FILE in ${FILES[@]}; do
for IGNORE in "${ONE_TIME_ONLY[@]}"; do
# If the file does not exist, go ahead and copy it (first time)
if [[ ! -f "${PWD}/${IGNORE}" ]]; then
cp -Rfv "${FILE}" "${PWD}"
# Otherwise, as long as the copied file is not the ignored file, go
# ahead and copy it (no restricton)
elif [[ "${FILE}" != "${RUNNER_TEMP}/full-copy/${IGNORE}" ]]; then
cp -Rfv "${FILE}" "${PWD}"
fi
done
done
# Folders to copy
FOLDERS=(
".githooks"
".github"
"scripts"
)
for FOLDER in "${FOLDERS[@]}"; do
# Copy all files from this directory into the root of the repository.
mkdir -p "${PWD}/${FOLDER}"
find "${RUNNER_TEMP}/full-copy/${FOLDER}/" -maxdepth 1 -type f -print0 |
xargs -0 -I% cp -Rfv "%" "${PWD}/${FOLDER}" ||
true
done
TYPES=()
# Pass GO=true when calling the script.
# shellcheck disable=2154
if [[ "${GO}" == "true" ]]; then
TYPES+=("go")
fi
# Pass TF=true when calling the script.
# shellcheck disable=2154
if [[ "${TF}" == "true" ]]; then
TYPES+=("tf")
fi
for TYPE in "${TYPES[@]}"; do
# Copy all files from this directory into the root of the repository.
mkdir -p "${PWD}"
find "${RUNNER_TEMP}/full-copy/${TYPE}/" -maxdepth 1 -type f -print0 |
xargs -0 -I% cp -Rfv "%" "${PWD}" ||
true
done
# Run Goplicate
goplicate run --allow-dirty --confirm --stash-changes
# Generate .ecrc
tomljson ecrc.toml >.ecrc
# Make shell scripts executable
find "${PWD}" -type f -name "*.sh" -print0 |
xargs -0 -I% chmod +x "%" ||
true