-
Notifications
You must be signed in to change notification settings - Fork 961
146 lines (124 loc) · 4.66 KB
/
ci.yml
File metadata and controls
146 lines (124 loc) · 4.66 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: GitHub Actions CI
on:
push:
branches: [main]
pull_request: {}
permissions:
contents: read # for actions/checkout
env:
test_stacks_directory: test_tf_stacks
jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-latest
env:
GITHUB_TEST_ORGANIZATION: kfcampbell-terraform-provider
steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
with:
go-version-file: go.mod
cache: true
- run: make tools
- run: make lint
- run: make docs-lint
- name: Check for uncommitted docs changes
run: |
tfplugindocs generate
if ! [[ -z $(git status --porcelain) ]]; then
echo "::error::Uncommitted changes after tfplugindocs generate"
exit 1
fi
- run: make build
- run: make test
generate-matrix:
name: Generate matrix for test stacks
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has-tests: ${{ steps.set-matrix.outputs.has-tests }}
steps:
- name: Checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- name: Generate matrix
id: set-matrix
run: |
if [ -d "${{ env.test_stacks_directory }}" ]; then
# find all directories and validate their names
VALID_TESTS=()
INVALID_TESTS=()
while IFS= read -r dir; do
dirname=$(basename "$dir")
# validate that directory name only contains alphanumeric, hyphens, underscores, and dots
if [[ "$dirname" =~ ^[a-zA-Z0-9_.-]+$ ]]; then
VALID_TESTS+=("$dirname")
else
INVALID_TESTS+=("$dirname")
fi
done < <(find ${{ env.test_stacks_directory }} -mindepth 1 -maxdepth 1 -type d)
# report invalid directory names if any
if [ ${#INVALID_TESTS[@]} -gt 0 ]; then
echo "::warning::Invalid test directory names found (must contain only alphanumeric, hyphens, underscores, and dots):"
printf ' - %s (will be skipped)\n' "${INVALID_TESTS[@]}"
fi
# create JSON array from valid tests
if [ ${#VALID_TESTS[@]} -gt 0 ]; then
TESTS=$(printf '%s\n' "${VALID_TESTS[@]}" | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${TESTS}" >> $GITHUB_OUTPUT
echo "has-tests=true" >> $GITHUB_OUTPUT
echo "Found valid test directories: ${TESTS}"
else
echo "matrix=[]" >> $GITHUB_OUTPUT
echo "has-tests=false" >> $GITHUB_OUTPUT
echo "No valid test directories found"
fi
else
echo "Test directory ${{ env.test_stacks_directory }} does not exist"
echo "matrix=[]" >> $GITHUB_OUTPUT
echo "has-tests=false" >> $GITHUB_OUTPUT
fi
tests:
name: Run tests for Terraform test stacks
needs: [ci, generate-matrix]
if: ${{ needs.generate-matrix.outputs.has-tests == 'true' }} # only run if there are some test stacks
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tests: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- name: Setup Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
with:
go-version-file: go.mod
cache: true
- name: Build provider
run: go build -o terraform-provider-github
- name: Setup dev overrides
run: |
ROOT_DIR=$(pwd)
cat > ~/.terraformrc << EOF
provider_installation {
dev_overrides {
"integrations/github" = "${ROOT_DIR}"
}
direct {}
}
EOF
- name: Verify dev overrides setup
run: cat ~/.terraformrc
- name: Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: 1.x
- name: Check Terraform version
run: terraform version
- name: Terraform init
continue-on-error: true # continue even if init fails
run: terraform -chdir=./${{ env.test_stacks_directory }}/${{ matrix.tests }} init
- name: Terraform validate
run: terraform -chdir=./${{ env.test_stacks_directory }}/${{ matrix.tests }} validate
- name: Clean up
run: rm -f ~/.terraformrc terraform-provider-github