-
-
Notifications
You must be signed in to change notification settings - Fork 217
59 lines (56 loc) · 2.13 KB
/
bats.yml
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
name: bats
on:
pull_request_target:
types: [labeled, opened, synchronize, unlabeled]
jobs:
bats:
runs-on: ubuntu-latest
if: github.event.pull_request.state == 'open'
container: cloudposse/test-harness:latest
env:
MAKE_INCLUDES: Makefile
TF_PLUGIN_CACHE_DIR: /tmp
BATS_MODULE_TESTS: input-descriptions lint output-descriptions provider-pinning
BATS_SUBMODULE_TESTS: input-descriptions lint output-descriptions
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
# Check out the PR commit, not the merge commit
# Use `ref` instead of `sha` to enable pushing back to `ref`
ref: ${{ github.event.pull_request.head.ref }}
- name: Run tests on modified modules
id: get-modified-files
shell: bash -x -e -o pipefail {0}
env:
BASE_REF: ${{ github.base_ref }}
HEAD_REF: ${{ github.head_ref }}
run: |
# when running in test-harness, need to mark the directory safe for git operations
make safe-directory
MODIFIED_MODULES=($(git diff --name-only origin/${BASE_REF} origin/${HEAD_REF} | xargs -n 1 dirname | sort | uniq | grep ^modules/ || true))
if [ -z "$MODIFIED_MODULES" ]; then
echo "No modules changed in this PR. Skipping tests."
exit 0
else
echo "Running checks on the following modules:"
printf -- "- %s\n" "${MODIFIED_MODULES[@]#modules/}"
fi
pass=true
for dir in "${MODIFIED_MODULES[@]}"; do
printf "\n\nBegin testing in $dir\n"
(
status=pass
cd $dir
[[ $dir =~ modules/.*/modules/ ]] && tests=$BATS_SUBMODULE_TESTS || tests=$BATS_MODULE_TESTS
for test in $tests; do
printf "\n\nRunning ${test} in $dir\n"
bats -t /test/terraform/${test}.bats || status=fail
done
[[ $status == "pass" ]]
) || pass=false
printf "\n\nEnd of testing in $dir\n\n\n"
done
[[ $pass == "true" ]]