Skip to content

Commit

Permalink
feat: add repository dispaching and monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Apr 18, 2024
1 parent 659bb61 commit 41cecb0
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- push

jobs:
dispatch:
e2e_tests:
runs-on: ubuntu-latest
steps:
- name: Get the branch name
Expand All @@ -22,9 +22,50 @@ jobs:
fi
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3.0.0
with:
token: "${{ secrets.PAT_INTEGRATION_TESTS}}"
repository: expressjs/examples
event-type: integration-tests
client-payload: '{"branch": "${{ steps.get_branch.outputs.branch }}", "repo": "${{ steps.get_repo.outputs.repo }}"}'
env:
TOKEN: ${{ secrets.PAT_INTEGRATION_TESTS }}
run: |
curl -X POST https://api.github.com/repos/expressjs/examples/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-H "Authorization: token $TOKEN" \
--data '{"event_type": "integration-tests", "client_payload": {"branch": "${{ steps.get_branch.outputs.branch }}", "repo": "${{ steps.get_repo.outputs.repo }}"}}'
# Wait for the workflow to start
sleep 60
# Get the latest workflow run
response=$(curl -H "Authorization: token $TOKEN" https://api.github.com/repos/expressjs/examples/actions/runs)
workflow_url=$(echo "$response" | jq -r '.workflow_runs[0].url')
status=""
start_time=$(date +%s)
timeout=$((10 * 60)) # timeout after 10 minutes
while [[ "$status" != "completed" && $(( $(date +%s) - start_time )) -lt $timeout ]]; do
echo "checking..."
sleep 10
response=$(curl -H "Authorization: token $TOKEN" $workflow_url)
status=$(echo "$response" | jq -r .status)
echo "current status: $status"
done
if [[ $(( $(date +%s) - start_time )) -ge $timeout ]]; then
echo "Workflow did not complete within the expected time"
fi
# Get the conclusion of the workflow run
conclusion=$(echo "$response" | jq -r .conclusion)
# Get the URL of the workflow run
html_url=$(echo "$response" | jq -r .html_url)
echo "Check the workflow run for details: $html_url"
if [[ "$status" == "completed" && "$conclusion" != "success" ]]; then
echo "Workflow completed but failed. Conclusion: $conclusion"
exit 1
fi
if [[ "$status" == "completed" && "$conclusion" == "success" ]]; then
echo "Workflow has been completed successfully"
exit 0
fi

0 comments on commit 41cecb0

Please sign in to comment.