Skip to content
Open
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
55 changes: 55 additions & 0 deletions .github/workflows/trigger_local_env.yml
Original file line number Diff line number Diff line change
@@ -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