Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Jan 14, 2025
1 parent e1dc54a commit 97d8c79
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ vaccine:
needs: [create-multiarch-lib-injection-image]
script: |
GH_VACCINE_PAT=$(vault kv get -field=vaccine-token kv/k8s/gitlab-runner/dd-trace-rb/github-token)
REPO="TonyCTHsu/vaccine"
POLL_INTERVAL=30 # seconds
# Store the API response
# Trigger workflow
HTTP_RESPONSE=$(curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GH_VACCINE_PAT" \
-w "\n%{http_code}" \
https://api.github.com/repos/TonyCTHsu/vaccine/actions/workflows/vaccine.yml/dispatches \
"https://api.github.com/repos/$REPO/actions/workflows/vaccine.yml/dispatches" \
-d '{"ref":"master", "inputs": {"commit_sha": "'$CI_COMMIT_SHA'"}}' 2>&1)
# Get the HTTP status code
Expand All @@ -176,36 +178,49 @@ vaccine:
echo "Error: Authentication failed. Please check GitHub token."
echo "Response: $RESPONSE_BODY"
exit 1
elif [ "$HTTP_STATUS" -ne 201 ] && [ "$HTTP_STATUS" -ne 204 ]; then
elif [ "$HTTP_STATUS" -ne 204 ]; then
echo "Error: Unexpected status code $HTTP_STATUS"
echo "Response: $RESPONSE_BODY"
exit 1
fi
# Poll GitHub workflow status
WORKFLOW_ID=$(curl -s -H "Authorization: token $GH_VACCINE_PAT" \
"https://api.github.com/repos/TonyCTHsu/vaccine/actions/runs?event=workflow_dispatch" \
| jq -r '.workflow_runs[0].id')
echo "Successfully triggered workflow. Waiting for workflow to start..."
sleep 10 # Give GitHub a moment to create the workflow run
echo "Waiting for workflow completion..."
# Get the latest workflow run that matches our commit
WORKFLOW_ID=$(curl -s \
-H "Authorization: token $GH_VACCINE_PAT" \
"https://api.github.com/repos/$REPO/actions/runs?event=workflow_dispatch" \
| jq -r --arg SHA "$CI_COMMIT_SHA" '.workflow_runs[] | select(.head_sha == $SHA) | .id' | head -n1)
if [ -z "$WORKFLOW_ID" ]; then
echo "Error: Could not find workflow run for commit $CI_COMMIT_SHA"
exit 1
fi
echo "Found workflow run ID: $WORKFLOW_ID"
# Poll workflow status
while true; do
WORKFLOW_STATUS=$(curl -s -H "Authorization: token $GH_VACCINE_PAT" \
"https://api.github.com/repos/TonyCTHsu/vaccine/actions/runs/$WORKFLOW_ID" \
| jq -r '.status,.conclusion')
WORKFLOW_STATUS=$(curl -s \
-H "Authorization: token $GH_VACCINE_PAT" \
"https://api.github.com/repos/$REPO/actions/runs/$WORKFLOW_ID" \
| jq -r '[.status, .conclusion] | @tsv')
STATUS=$(echo "$WORKFLOW_STATUS" | head -n1)
CONCLUSION=$(echo "$WORKFLOW_STATUS" | tail -n1)
STATUS=$(echo "$WORKFLOW_STATUS" | cut -f1)
CONCLUSION=$(echo "$WORKFLOW_STATUS" | cut -f2)
if [ "$STATUS" = "completed" ]; then
if [ "$CONCLUSION" = "success" ]; then
echo "Workflow completed successfully!"
echo "Workflow completed successfully!"
exit 0
else
echo "Workflow failed with conclusion: $CONCLUSION"
echo "❌ Workflow failed with conclusion: $CONCLUSION"
echo "See details: https://github.com/$REPO/actions/runs/$WORKFLOW_ID"
exit 1
fi
fi
echo "Workflow status: $STATUS"
sleep 30
echo "Current status: $STATUS (Checking again in ${POLL_INTERVAL}s)"
sleep $POLL_INTERVAL
done

0 comments on commit 97d8c79

Please sign in to comment.