From 7337916cb78e30bd3ceebd74d420e81cf8371f60 Mon Sep 17 00:00:00 2001 From: zhangyangyu Date: Wed, 18 Oct 2023 00:06:40 +0800 Subject: [PATCH] Revert "Delete .github/workflows/create-test.yml" This reverts commit 2a8881c6b67bb1515f0a3fbe247159f9134e562d. --- .github/workflows/create-test.yml | 121 ++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .github/workflows/create-test.yml diff --git a/.github/workflows/create-test.yml b/.github/workflows/create-test.yml new file mode 100644 index 0000000..d11f5e7 --- /dev/null +++ b/.github/workflows/create-test.yml @@ -0,0 +1,121 @@ +name: Serverless Create Test + +on: + schedule: + - cron: "0/30 * * * *" # every 30 minutes + workflow_dispatch: + +jobs: + setup: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up ticloud + uses: tidbcloud/setup-tidbcloud-cli@v0 + with: + api_public_key: ${{ secrets.CREATE_TEST_PUBLIC_KEY }} + api_private_key: ${{ secrets.CREATE_TEST_PRIVATE_KEY }} + + - name: Delete all serverless + run: | + # delete all serverless + set +e + ticloud cluster list 1372813089447741295 -o json > cluster + exitcode="$?" + if [[ "$exitcode" != "0" ]]; then + cat cluster + exit "$exitcode" + fi + + total=$(jq '.total' cluster); + for i in $(seq 1 $total); + do + id=`echo $(jq ".items[$i-1].id" cluster) | sed 's/"//g'` + ticloud cluster delete -p 1372813089447741295 -c $id --force; + exitcode="$?" + if [[ "$exitcode" != "0" ]]; then + exit "$exitcode" + fi + done + + create-test: + needs: setup + strategy: + fail-fast: false + matrix: + region: [ us-east-1, us-west-2, ap-northeast-1, ap-southeast-1, eu-central-1 ] + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up ticloud + uses: tidbcloud/setup-tidbcloud-cli@v0 + with: + api_public_key: ${{ secrets.CREATE_TEST_PUBLIC_KEY}} + api_private_key: ${{ secrets.CREATE_TEST_PRIVATE_KEY }} + + - name: Create cluster + run: | + set +e + PROJECT_ID=1372813089447741295 + result=`ticloud cluster create -p $PROJECT_ID --cluster-name ${{ matrix.region }} --cloud-provider AWS -r ${{ matrix.region }} --root-password ${{ secrets.TIDB_CLOUD_PASSWORD }} --cluster-type SERVERLESS` + exitcode="$?" + if [[ "$exitcode" != "0" ]]; then + echo $result + exit "$exitcode" + fi + echo $result + + id=`echo $result | sed 's/[^0-9]//g'` + ticloud cluster get -p $PROJECT_ID -c $id > ${{ matrix.region }} + exitcode="$?" + if [[ "$exitcode" != "0" ]]; then + cat ${{ matrix.region }} + exit "$exitcode" + fi + cat ${{ matrix.region }} + echo "PROJECT_ID=$PROJECT_ID" >> $GITHUB_ENV + echo "CLUSTER_ID=`echo $(jq '.id' ${{ matrix.region }}) | sed 's/"//g'`" >> $GITHUB_ENV + echo "CLUSTER_USER=$(jq '.status.connection_strings.default_user' ${{ matrix.region }})" >> $GITHUB_ENV + echo "CLUSTER_HOST=$(jq '.status.connection_strings.standard.host' ${{ matrix.region }})" >> $GITHUB_ENV + + - name: Create branch + run: | + set +e + result=`ticloud branch create -c ${{ env.CLUSTER_ID }} --branch-name ${{ matrix.region }}` + exitcode="$?" + if [[ "$exitcode" != "0" ]]; then + echo $result + exit "$exitcode" + fi + echo $result + + id=`echo $result | grep -o 'bran-[a-zA-Z0-9]*'` + ticloud branch get -c ${{ env.CLUSTER_ID }} -b $id > ${{ matrix.region }} + exitcode="$?" + if [[ "$exitcode" != "0" ]]; then + cat ${{ matrix.region }} + exit "$exitcode" + fi + cat ${{ matrix.region }} + + echo "BRANCH_ID=`echo $(jq '.id' ${{ matrix.region }}) | sed 's/"//g'`" >> $GITHUB_ENV + echo "BRANCH_USER=$(jq '.user_prefix' ${{ matrix.region }})".root"" >> $GITHUB_ENV + echo "BRANCH_HOST=$(jq '.endpoints.public_endpoint.host' ${{ matrix.region }})" >> $GITHUB_ENV + + - name: Setup mysql + uses: shogo82148/actions-setup-mysql@v1 + + - name: Run test + run: | + mysql -u ${{ env.CLUSTER_USER }} -h ${{ env.CLUSTER_HOST }} -P 4000 -D test --ssl-mode=VERIFY_IDENTITY --ssl-ca=/etc/ssl/certs/ca-certificates.crt -p${{ secrets.TIDB_CLOUD_PASSWORD }} + + - name: Delete cluster & branch + run: | + ticloud branch delete -c ${{ env.CLUSTER_ID }} -b ${{ env.BRANCH_ID }} --force + ticloud cluster delete -p ${{ env.PROJECT_ID }} -c ${{ env.CLUSTER_ID }} --force