CI: support test for tech-solution #707
This file contains hidden or 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
name: E2E Test Check | |
on: | |
pull_request: | |
branches: | |
- master | |
- main | |
types: [ 'opened', 'synchronize' ] | |
paths: | |
- '.github/**' | |
- 'quickstarts/**' | |
- 'tech-solution/**' | |
jobs: | |
terraform-fmt: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: hashicorp/setup-terraform@v3 | |
- name: Terraform fmt | |
id: fmt | |
run: | | |
terraform -chdir=quickstarts fmt -check -recursive | |
terraform -chdir=tech-solution fmt -check -recursive | |
terraform-validate: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: hashicorp/setup-terraform@v3 | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v34 | |
with: | |
dir_names: "true" | |
separator: "," | |
files: | | |
quickstarts/* | |
tech-solution/* | |
dir_names_max_depth: 3 | |
- name: Terraform validate | |
run: | | |
CHANGED_FOLDERS="${{ steps.changed-files.outputs.all_changed_files }}" | |
if [ -z "$CHANGED_FOLDERS" ]; then | |
echo "No changed terraform code found" | |
exit 0 | |
fi | |
error=false | |
for f in ${CHANGED_FOLDERS//,/ } | |
do | |
f=$(echo $f | xargs echo -n) | |
echo "===> Terraform validating in" $f | |
terraform -chdir=$f init -upgrade | |
terraform -chdir=$f validate | |
if [[ $? -ne 0 ]]; then | |
echo -e "\033[31m[ERROR]\033[0m: Some terraform codes contain errors, and please running terraform validate command before pushing." | |
exit 1 | |
fi | |
done | |
e2e-check: | |
needs: [terraform-fmt, terraform-validate] | |
runs-on: ubuntu-latest | |
name: e2e check | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: Checking the max commits number | |
run: | | |
commitNum=${{ github.event.pull_request.commits }} | |
if [[ ${commitNum} -gt 1 ]]; then | |
echo -e "\nERROR: The PR has ${commitNum} commits, and please rebase it to 1.\n" | |
exit 1 | |
fi | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v34 | |
with: | |
dir_names: "true" | |
separator: "," | |
files: | | |
quickstarts/* | |
tech-solution/* | |
dir_names_max_depth: 3 | |
- name: set id | |
id: set-job-id | |
uses: ayachensiyuan/get-action-job-id@v1.6 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
job-name: 'e2e check' | |
- name: get pull request info | |
run: | | |
echo "repo name is" ${{github.event.pull_request.head.repo.full_name}} | |
echo "branch is" ${{github.event.pull_request.head.ref}} | |
echo "the current job id is ${{ steps.set-job-id.outputs.jobId }}" | |
- name: e2e test | |
run: | | |
CHANGED_FOLDERS="${{ steps.changed-files.outputs.all_changed_files }}" | |
if [ -z "$CHANGED_FOLDERS" ]; then | |
echo "No changed terraform code found" | |
exit 0 | |
fi | |
objectPath="github-action/${{github.repository}}/e2e/Action-${{github.run_number}}-${{github.run_id}}-${{ steps.set-job-id.outputs.jobId }}" | |
curl -H "X-Fc-Invocation-Type:Async" -s https://example-ci-terrafoodule-ci-svrrwvrpnj.ap-southeast-1.fcapp.run/?branch=${{github.event.pull_request.head.ref}}\&repo_name=${{github.event.pull_request.head.repo.full_name}}\&oss_object_path=${objectPath} | |
go run scripts/e2e_check.go ${objectPath} |