Continuous Integration #147
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a periodic workflow to help you run Continuous Integration with Actions | |
name: Continuous Integration | |
on: | |
schedule: | |
# UTC time, schedule at 22:00 (UTC+8) on every Sunday | |
- cron: '00 14 * * SUN' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ">=1.18" | |
- name: Build | |
run: make build FLAGS='-mod=readonly' | |
- name: Vet | |
run: make vet | |
# This workflow contains a job called "tfproviderlint" | |
tfproviderlint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: bflad/tfproviderlint-github-action@master | |
with: | |
args: -R019=false -S018=false -V011=false -V012=false -V013=false -V014=false ./... | |
# This workflow contains a job called "acc-test" | |
acc-test: | |
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: | |
- uses: actions/checkout@v3 | |
with: | |
ref: master | |
fetch-depth: 100 | |
- 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 | |
commitID=$(git log --before="1 week ago" --pretty=format:"%h" -n 1) | |
all_files=$(git diff $commitID --name-only huaweicloud | grep -v "_test.go") | |
echo -e "the following files have changed since $commitID:\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 "\nrun 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-ci | |
path: | | |
${{ env.TF_LOG_PATH }} | |
if-no-files-found: ignore |