Continuous Integration #8
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" | |
# Ignoring bflad/tfproviderlint until https://github.com/bflad/tfproviderlint/issues/255 is fixed... | |
# using ShiChangkuo/tfproviderlint instead | |
tfproviderlint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: ">=1.18" | |
- name: Checkout provider | |
uses: actions/checkout@v3 | |
with: | |
path: terraform-provider-huaweicloudstack | |
- name: Checkout tfproviderlint | |
uses: actions/checkout@v3 | |
with: | |
repository: ShiChangkuo/tfproviderlint | |
path: tfproviderlint | |
- name: Install tfproviderlint and Check | |
run: | | |
cd ${{ github.workspace }}/tfproviderlint/cmd/tfproviderlint | |
go install | |
cd ${{ github.workspace }}/terraform-provider-hcs | |
tfproviderlint -V011=false -V012=false -V013=false -V014=false -R019=false ./... | |
# This workflow contains a job called "acc-test" | |
acc-test: | |
env: | |
HCS_ACCESS_KEY: ${{ secrets.HCS_ACCESS_KEY }} | |
HCS_SECRET_KEY: ${{ secrets.HCS_SECRET_KEY }} | |
HCS_DOMAIN_NAME: ${{ secrets.HCS_DOMAIN_NAME }} | |
HCS_REGION_NAME: cn-north-4 | |
HCS_ADMIN: "true" | |
HCS_ENTERPRISE_PROJECT_ID: "0" | |
HCS_ENTERPRISE_PROJECT_ID_TEST: "0" | |
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 HCS_ACCESS_KEY is setted | |
if: ${{ env.HCS_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" | |
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" | |
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" | |
fi | |
done | |
echo -e "\n[summary] $result failed in $total acceptance basic tests" | |
exit $result |