forked from huaweicloud/terraform-provider-huaweicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (198 loc) · 7.76 KB
/
pre-release.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# This is a basic workflow to help you get started with Actions
name: pre-release
# Controls when the workflow will run
on:
push:
branches: [ master ]
paths:
- 'CHANGELOG.md'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
scan-api:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# /home/runner/work/terraform-provider-huaweicloud/terraform-provider-huaweicloud
- uses: actions/checkout@v3
with:
path: terraform-provider-huaweicloud
- uses: actions/checkout@v3
with:
repository: chnsz/terraform-provider-generator
token: ${{ secrets.REVIEWDOG_TOKEN }}
path: terraform-provider-generator
- uses: actions/checkout@v3
with:
repository: chnsz/terraform-api-scan
token: ${{ secrets.REVIEWDOG_TOKEN }}
path: terraform-api-scan
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.18"
- name: Get the provider release version
run: |
version=$(head -n 4 terraform-provider-huaweicloud/CHANGELOG.md | grep "^## " | awk '{printf "v%s", $2}')
echo "VERSION=$version" >> $GITHUB_ENV
- name: Build Terraform Provider
run: |
cd terraform-provider-huaweicloud
make build FLAGS='-mod=readonly'
cd ..
- name: export schemas for the providers
env:
TF_CLI_CONFIG_FILE: ${{ github.workspace }}/hw_dev.tfrc
run: |
cat>${{ github.workspace }}/hw_dev.tfrc<<EOF
provider_installation {
dev_overrides {
"huaweicloud/huaweicloud" = "/home/runner/go/bin"
}
direct {}
}
EOF
cd terraform-api-scan
terraform init
terraform providers schema -json > schema.json
cd ..
- name: parse APIs that marked with comments
run: |
cp terraform-api-scan/scan-marked-comment-file/*.go terraform-provider-huaweicloud/
cd terraform-provider-huaweicloud
rm -rf docs/api
mkdir docs/api
go run main.go -basePath=./ -outputDir=./docs/api/ -providerSchemaPath=../terraform-api-scan/schema.json
cd ..
- name: commit APIs that resources depend-on
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: terraform-provider-huaweicloud
file_pattern: 'docs/api/*.yaml'
commit_message: Update APIs that resources depend-on ${{ env.VERSION }}
generate-schema:
if: ${{ always() }}
needs: scan-api
env:
# when HW_SCHEMA is not empty, custom schema config will be contained in the description of parameters
HW_SCHEMA: "true"
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.18"
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# /home/runner/work/terraform-provider-huaweicloud/terraform-provider-huaweicloud
- uses: actions/checkout@v3
with:
path: terraform-provider-huaweicloud
ref: master
- uses: actions/checkout@v3
with:
repository: chnsz/huaweicloud-provider-json
token: ${{ secrets.REVIEWDOG_TOKEN }}
path: huaweicloud-provider-json
- name: import the latest codes of provider and build
run: |
cd huaweicloud-provider-json
go get github.com/huaweicloud/terraform-provider-huaweicloud@master
go build -o generate-schemas
cp ./generate-schemas ../terraform-provider-huaweicloud
cd ..
- name: generate-schema
shell: bash {0}
run: |
cd terraform-provider-huaweicloud
target="./docs/json"
rm -rf $target
echo -e "\ntry to update the product config file..."
./generate-schemas -product
if [ $? -ne 0 ]; then
echo "[WARN] failed to update the product config file, using the existing one!"
fi
echo -e "\ntry to update the resource schema files..."
./generate-schemas -r -name="all" -output-dir=$target
echo -e "\ntry to update the data source schema files..."
./generate-schemas -d -name="all" -output-dir=$target
rm -f $target/data-sources/vpc_route.json
rm -f $target/resources/networking_port.json
- name: Get the provider release version
run: |
version=$(head -n 4 terraform-provider-huaweicloud/CHANGELOG.md | grep "^## " | awk '{printf "v%s", $2}')
echo "VERSION=$version" >> $GITHUB_ENV
- name: auto-commit
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: terraform-provider-huaweicloud
file_pattern: 'docs/json/'
commit_message: Update schema json files based-on ${{ env.VERSION }}
acc-test:
if: ${{ always() }}
needs: [scan-api, generate-schema]
env:
HW_ACCESS_KEY: ${{ secrets.HW_ACCESS_KEY }}
HW_SECRET_KEY: ${{ secrets.HW_SECRET_KEY }}
HW_DOMAIN_NAME: ${{ secrets.HW_DOMAIN_NAME }}
HW_REGION_NAME: cn-north-4
HW_ADMIN: "true"
HW_ENTERPRISE_PROJECT_ID: "0"
HW_ENTERPRISE_PROJECT_ID_TEST: "0"
TF_LOG: "DEBUG"
TF_LOG_PATH: "${{ github.workspace }}/acceptance.log"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.18"
# run acceptance test
- name: Run acceptance basic test
# run the step only when HW_ACCESS_KEY is setted
if: ${{ env.HW_ACCESS_KEY }}
shell: bash {0}
run: |
result=0
total=0
last_tag=$(git tag --sort=-creatordate | sed -n 1p)
all_files=$(git diff $last_tag --name-only huaweicloud | grep -v "_test.go")
echo -e "the following files have changed since $last_tag:\n$all_files\n" | tee -a ${{ env.TF_LOG_PATH }}
for f in $all_files; do
path=${f%/*}
if [ "X$path" != "Xhuaweicloud" ]; then
# update path to "huaweicloud/services/acceptance/xxx"
path=${path/"services"/"services/acceptance"}
fi
org_file=${f##*/}
test_file=$path/${org_file/%.go/_test.go}
if [ -f "./${test_file}" ]; then
basic_case=$(grep "^func TestAcc" ./${test_file} | grep _basic | awk 'NR==1{print $2}' | awk -F '(' '{print $1}')
if [ "X$basic_case" != "X" ]; then
total=`expr $total + 1`
echo -e "\n[$total] `date` run acceptance basic test: $basic_case" | tee -a ${{ env.TF_LOG_PATH }}
make testacc TEST="./$path" TESTARGS="-run ${basic_case}"
if [ $? -ne 0 ]; then
result=`expr $result + 1`
fi
fi
else
echo -e "\n[skipped] --- ./${test_file} does not exist" | tee -a ${{ env.TF_LOG_PATH }}
fi
done
echo -e "\n[summary] $result failed in $total acceptance basic tests" | tee -a ${{ env.TF_LOG_PATH }}
exit $result
- name: Upload acceptance log
if: always()
uses: actions/upload-artifact@v3
with:
name: acceptance-release
path: |
${{ env.TF_LOG_PATH }}
if-no-files-found: ignore