diff --git a/.github/workflows/trigger_local_env.yml b/.github/workflows/trigger_local_env.yml new file mode 100644 index 0000000..e051f63 --- /dev/null +++ b/.github/workflows/trigger_local_env.yml @@ -0,0 +1,55 @@ +name: Trigger Local Env + +on: + pull_request: + branches: + - master + +jobs: + trigger: + runs-on: ubuntu-latest + steps: + - name: Send dispatch event + env: + GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }} + run: | + echo "${{ github.head_ref }}" + curl -X POST \ + -H "Accept: application/vnd.github.everest-preview+json" \ + -H "Authorization: token $GITHUB_TOKEN" \ + https://api.github.com/repos/Yam1x/to-dos-local-env/dispatches \ + -d '{"event_type": "trigger_from_API", "client_payload": {"branch": "${{ github.head_ref }}"}}' + + - name: Wait for Local Env tests to pass + run: | + sleep 10 + + RUN_ID=$(curl -s -H "Authorization: token ${{ secrets.DISPATCH_TOKEN }}" \ + "https://api.github.com/repos/Yam1x/to-dos-local-env/actions/runs?event=repository_dispatch" \ + | jq -r '.workflow_runs | map(select(.display_title == "trigger_from_API")) | .[0].id') + + echo "Workflow Run ID: $RUN_ID" + + while true; do + STATUS=$(curl -s -H "Authorization: token ${{ secrets.DISPATCH_TOKEN }}" \ + "https://api.github.com/repos/Yam1x/to-dos-local-env/actions/runs/$RUN_ID" \ + | jq -r '.status') + + if [ "$STATUS" == "completed" ]; then + CONCLUSION=$(curl -s -H "Authorization: token ${{ secrets.DISPATCH_TOKEN }}" \ + "https://api.github.com/repos/Yam1x/to-dos-local-env/actions/runs/$RUN_ID" \ + | jq -r '.conclusion') + + if [ "$CONCLUSION" == "success" ]; then + echo "Tests passed" + exit 0 + else + echo "Tests failed" + exit 1 + fi + else + echo "Waiting for test results..." + sleep 30 + fi + done +