diff --git a/.github/workflows/sanity-test.yml b/.github/workflows/sanity-test.yml new file mode 100644 index 0000000..11ee2e6 --- /dev/null +++ b/.github/workflows/sanity-test.yml @@ -0,0 +1,32 @@ +name: Sanity test + +on: + push: + branches: + - main + +jobs: + + workflow-sanity-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + - name: Install td + run: | + gem install td + - name: Install workflow module + env: + TD_API_ENDPOINT: https://api.treasuredata.com + TD_API_KEY: ${{ secrets.TD_API_KEY }} + run: | + yes | td -e "${TD_API_ENDPOINT}" -k "${TD_API_KEY}" workflow + - name: Run workflow sanity test + env: + TD_API_ENDPOINT: https://api-development.treasuredata.com + TD_API_KEY: ${{ secrets.TD_API_KEY }} + run: | + chmod +x .github/workflows/scripts/workflow-sanity-test.sh + .github/workflows/scripts/workflow-sanity-test.sh diff --git a/.github/workflows/scripts/workflow-sanity-test.sh b/.github/workflows/scripts/workflow-sanity-test.sh new file mode 100755 index 0000000..9072fdf --- /dev/null +++ b/.github/workflows/scripts/workflow-sanity-test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -euo pipefail + +RESPONSE=$(td -e "${TD_API_ENDPOINT}" -k "${TD_API_KEY}" workflow start td-client-python-sanity-test td-client-python-sanity-test --session now) +SESSION_ID=$(echo "${RESPONSE}" | sed -nE 's/^[ \t]*session id:[ \t]+([0-9]+)$/\1/p') + +if [ -z "${SESSION_ID}" ]; then + echo "Failed to start workflow session: ${SESSION_ID}" + exit 1 +else + echo "Started workflow session with ID: ${SESSION_ID}" +fi + +until false +do + STATUS=$(td -e "${TD_API_ENDPOINT}" -k "${TD_API_KEY}" workflow session ${SESSION_ID} | sed -nE 's/[ \t]*status:[ \t]+(.*)/\1/p') + if [ "${STATUS}" = "success" ]; then + echo "Workflow completed successfully." + exit 0 + elif [ "${STATUS}" = "error" ]; then + echo "Workflow failed." + exit 1 + elif [ "${STATUS}" = "running" ]; then + echo "Workflow running. Waiting for completion..." + sleep 10 + else + echo "Unknown status: ${STATUS}. Exiting." + exit 1 + fi +done