generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 9
98 lines (91 loc) · 2.99 KB
/
integration-test-branch.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
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
87
88
89
90
91
92
93
94
95
96
97
98
# Terraform Provider testing workflow.
name: resource development branch tests
# This GitHub action runs your tests for each pull request and push.
# Optionally, you can turn it on using a schedule for regular testing.
on:
push:
branches-ignore:
- main
- development
# Testing only needs permissions to read the repository contents.
permissions:
contents: read
jobs:
# Ensure project builds before running testing matrix
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 30
needs: lint # Add dependency on the "lint" job in the lint.yml workflow
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
env:
working-directory: ./
- run: go mod download
- run: go build -v .
generate:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
env:
working-directory: ./
- run: go generate ./...
- name: git diff
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1)
# Run acceptance tests for the resource on the development branch
test:
name: Terraform Provider Acceptance Tests
needs: generate
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
working-directory: ./
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.2.*'
terraform_wrapper: false
- run: go mod download
- env:
TF_ACC: "1"
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
run: |
go test -sweep -v -cover ./internal/provider/
timeout-minutes: 10
# Check test results and fail the workflow if the tests fail
check_results:
needs: test
runs-on: ubuntu-latest
steps:
- name: Check test results
run: |
changed_files=$(git diff --name-only HEAD $(git merge-base HEAD main))
test_function=$(grep -E '^func TestAcc.*\(t \*testing.T\)' $changed_files | awk -F 'func ' '{print $2}' | awk -F '(' '{print $1}')
if [[ -n "$test_function" ]]; then
# Run the test and store the output in a variable
test_output=$(go test -v -cover -run "$test_function" ./internal/provider/ 2>&1)
# Check if the test passed by searching for a specific pattern in the output
if echo "$test_output" | grep -q "PASS"; then
echo "TestAcc Passed"
else
echo "TestAcc Failed"
exit 1
fi
else
echo "TestAcc function not found"
fi