Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflow/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: E2E Test Check
on:
pull_request:
branches:
- master
- main
types: [ 'opened', 'synchronize' ]
paths:
- '.github/**'
- '.github/workflows/**'
- 'examples/**'

jobs:
e2e-check:
runs-on: terraform-alicloud-landing
environment:
name: acctests
steps:
- name: checkout
uses: actions/checkout@v3
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v34
with:
dir_names: "true"
separator: ","
files: "examples/*"
files_ignore: "**/TestRecord.md"
dir_names_max_depth: 2
- name: test pr
run: |
bash scripts/terraform-install.sh
bash scripts/terraform-test.sh false
35 changes: 35 additions & 0 deletions .github/workflow/weekly_e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Weekly E2E Test Check
on:
workflow_dispatch:
schedule:
- cron: '0 17 * * 0'


jobs:
all-e2e-test:
runs-on: terraform-alicloud-landing
timeout-minutes: 1440
environment:
name: acctests
permissions: write-all
steps:
- name: checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: test all and update TestRecord
run: |
bash scripts/terraform-install.sh
bash scripts/terraform-test.sh true
cd .git
sudo chmod -R a+rwX .
sudo find . -type d -exec chmod g+s '{}' +
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: 'Update TestRecord'
branch: main
- name: upload to oss bucket
run: |
aliyun oss cp examples/TestRecord.md oss://$BUCKET_MODULE_OBJECT/terraform-alicloud-acr-enterprise.md -u -e $ossEndpoint --region $ossRegion
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# .tfstate files
*.tfstate
*.tfstate.*
**/TestRecord.md.tmp

# Crash log files
crash.log
Expand Down
3 changes: 3 additions & 0 deletions scripts/apply.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run "apply" {
command = apply
}
50 changes: 50 additions & 0 deletions scripts/generate-test-record.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# generate-test-record
if [ "$1" == "false" ];then
exit 0
fi

success=true
if [ -n "$2" ] ;then
success=false
fi

executePath=examples/complete

testRecordFileTmp=${executePath}/TestRecord.md.tmp
touch $testRecordFileTmp

time=$(date -u "+%d %b %Y %H:%M UTC")
echo -e "## $time\n" > $testRecordFileTmp
echo -e "success: ${success}\n\n### Versions\n" >> $testRecordFileTmp

cd $executePath
row=$(terraform version | sed -n '/^$/=')
if [ -n "$row" ]; then
version=`echo "$(terraform version | sed -n "1,${row}p")"`
else
version=`echo "$(terraform version)"`
fi
cd - >/dev/null 2>&1

echo "${version}" >> $testRecordFileTmp
echo -e "\n### Error\n" >> $testRecordFileTmp

if [ -n "$2" ] ;then
echo $2 >> $testRecordFileTmp
fi

# update-test-record
git pull --rebase origin main
git config --global --add safe.directory '*'

if [ ! -f "${executePath}/TestRecord.md" ]; then
touch ${executePath}/TestRecord.md
fi

echo -e "\n" >> ${executePath}/TestRecord.md.tmp
cat ${executePath}/TestRecord.md >> ${executePath}/TestRecord.md.tmp
cat ${executePath}/TestRecord.md.tmp > ${executePath}/TestRecord.md

git add **/TestRecord.md
3 changes: 3 additions & 0 deletions scripts/plan.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run "plan" {
command = plan
}
20 changes: 20 additions & 0 deletions scripts/terraform-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

if [ ! -f /usr/bin/terraform ]; then
echo "terraform does not exist!"
wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
unzip terraform_1.6.0_linux_amd64.zip -d /usr/bin/
else
echo "terraform exists!"
fi

if [ ! -f /usr/bin/aliyun ]; then
echo "aliyun does not exist!"
wget -q https://github.com/aliyun/aliyun-cli/releases/download/v3.0.186/aliyun-cli-linux-3.0.186-amd64.tgz
tar xzvf aliyun-cli-linux-3.0.186-amd64.tgz
mv aliyun /usr/bin
else
echo "aliyun exists!"
fi

exit 0
48 changes: 48 additions & 0 deletions scripts/terraform-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env sh

record=$1
success=true

f=examples/complete
f=$(echo $f | xargs echo -n)
echo $f
export TF_LOG_PATH=${f}/terraform.log
echo $TF_LOG_PATH
echo ""
echo "====> Terraform testing in" $f
terraform -chdir=$f init -upgrade
~/init_env.sh
source ~/.terraform_profile
echo ""
echo "----> Plan Testing"
cp scripts/plan.tftest.hcl $f/
terraform -chdir=$f test test -verbose
if [[ $? -ne 0 ]]; then
success=false
echo -e "\033[31m[ERROR]\033[0m: running terraform test for plan failed."
bash scripts/generate-test-record.sh $record "Plan: running terraform test for plan failed."
else
echo ""
echo "----> Apply Testing"
rm -rf $f/plan.tftest.hcl
cp scripts/apply.tftest.hcl $f/
terraform -chdir=$f test test
if [[ $? -ne 0 ]]; then
success=false
echo -e "\033[31m[ERROR]\033[0m: running terraform test for apply failed."
bash scripts/generate-test-record.sh $record "Apply: running terraform test for apply failed."
fi
rm -rf $f/apply.tftest.hcl
fi
if [[ $success == "true" ]]; then
bash scripts/generate-test-record.sh $record
fi

unset TF_LOG_PATH

# e2e
if [[ $success == "false" && $record == "false" ]]; then
exit 1
fi

exit 0