|
| 1 | +name: Trigger and Monitor SQ Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + SQA_branch: |
| 7 | + description: 'SQA Branch name' |
| 8 | + required: true |
| 9 | + default: '2-add-bluetooth-aoa-project' |
| 10 | + |
| 11 | +jobs: |
| 12 | + trigger-SQ-test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Trigger Check-Time Workflow |
| 16 | + id: trigger |
| 17 | + run: | |
| 18 | + echo "Repository: $REPOSITORY_NAME" |
| 19 | + echo "Branch: $BRANCH_NAME" |
| 20 | + echo "Owner: $OWNER_NAME" |
| 21 | + response=$(curl -X POST \ |
| 22 | + -H "Accept: application/vnd.github.v3+json" \ |
| 23 | + -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 24 | + https://api.github.com/repos/SiliconLabsInternal/DevS-SQA/actions/workflows/01-sonarqube-analysis.yml/dispatches \ |
| 25 | + -d '{"ref":"${{inputs.SQA_branch}}","inputs":{"repository": "${{ github.repository }}" ,"ref":"${{ github.ref }}"}}') |
| 26 | + echo "Triggered workflow: $response" |
| 27 | + if echo "$response" | grep -q '"message": "Not Found"'; then |
| 28 | + echo "Error: Workflow or repository not found. Please check the repository name, workflow file name, and branch name." |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +
|
| 32 | + - name: Wait for Check-Time Workflow to Complete |
| 33 | + id: wait |
| 34 | + env: |
| 35 | + TIMEOUT: 1800 |
| 36 | + run: | |
| 37 | + sleep 30 |
| 38 | + run_id=$(curl -s \ |
| 39 | + -H "Accept: application/vnd.github.v3+json" \ |
| 40 | + -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 41 | + https://api.github.com/repos/SiliconLabsInternal/DevS-SQA/actions/runs \ |
| 42 | + | jq '.workflow_runs[] | select(.name=="Bluetooth AoA Check") | .id' | head -n 1) |
| 43 | + echo "Run ID: $run_id" |
| 44 | + start_time=$(date +%s) |
| 45 | + while true; do |
| 46 | + current_time=$(date +%s) |
| 47 | + elapsed_time=$((current_time - start_time)) |
| 48 | + if [ $elapsed_time -ge $TIMEOUT ]; then |
| 49 | + echo "Error: Workflow did not complete within $((TIMEOUT / 60)) minutes." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + status=$(curl -s \ |
| 53 | + -H "Accept: application/vnd.github.v3+json" \ |
| 54 | + -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 55 | + https://api.github.com/repos/SiliconLabsInternal/DevS-SQA/actions/runs/$run_id \ |
| 56 | + | jq -r '.status') |
| 57 | + conclusion=$(curl -s \ |
| 58 | + -H "Accept: application/vnd.github.v3+json" \ |
| 59 | + -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ |
| 60 | + https://api.github.com/repos/SiliconLabsInternal/DevS-SQA/actions/runs/$run_id \ |
| 61 | + | jq -r '.conclusion') |
| 62 | + echo "Status: $status, Conclusion: $conclusion" |
| 63 | + if [[ "$status" == "completed" ]]; then |
| 64 | + if [[ "$conclusion" == "success" ]]; then |
| 65 | + echo "Workflow completed successfully." |
| 66 | + exit 0 |
| 67 | + else |
| 68 | + echo "Workflow failed." |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + fi |
| 72 | + sleep 30 |
| 73 | + done |
0 commit comments