feat: enhance build status updates by including artifact path and GitHub run ID in payload, improving tracking and management of build processes

This commit is contained in:
Ben Allfree
2025-11-25 07:58:41 -08:00
parent 8e2d4f69cb
commit 79efff688d
3 changed files with 33 additions and 20 deletions

View File

@@ -39,9 +39,15 @@ jobs:
run: |
cat > /tmp/update_status.sh << 'EOF'
update_status() {
local state=$1
local artifact_path=$2
local payload="{\"build_id\": \"$BUILD_ID\", \"state\": \"$state\", \"github_run_id\": \"$GITHUB_RUN_ID\"}"
if [ -n "$artifact_path" ]; then
payload="{\"build_id\": \"$BUILD_ID\", \"state\": \"$state\", \"artifactPath\": \"$artifact_path\", \"github_run_id\": \"$GITHUB_RUN_ID\"}"
fi
curl -sSf -X POST "$CONVEX_URL/github-webhook" \
-H "Content-Type: application/json" \
-d "{\"action\": \"status_update\", \"build_id\": \"$BUILD_ID\", \"status\": \"$1\"}" || true
-d "$payload" || true
}
EOF
chmod +x /tmp/update_status.sh
@@ -188,21 +194,19 @@ jobs:
--file "$BUILD_FILE" --remote
# Update build with artifact path (with leading slash)
curl -sSf -X POST "$CONVEX_URL/github-webhook" \
-H "Content-Type: application/json" \
-d "{\"action\": \"status_update\", \"build_id\": \"$BUILD_ID\", \"status\": \"uploaded\", \"artifactPath\": \"$ARTIFACT_PATH\"}" || true
update_status uploaded "$ARTIFACT_PATH"
echo "✅ Uploaded to R2: $ARTIFACT_PATH"
- name: Update Build Status - Final
if: always()
shell: bash
run: |
source /tmp/update_status.sh
STATUS="${{ job.status }}"
if [ "$STATUS" = "success" ]; then
STATUS_MSG="success"
else
STATUS_MSG="failure"
fi
curl -X POST "${{ inputs.convex_url }}/github-webhook" \
-H "Content-Type: application/json" \
-d "{\"action\": \"completed\", \"build_id\": \"${{ inputs.build_id }}\", \"status\": \"$STATUS_MSG\"}"
update_status "$STATUS_MSG"

View File

@@ -299,12 +299,16 @@ export const updateBuildStatus = internalMutation({
buildId: v.id('builds'),
status: v.string(), // Accepts any status string value
artifactPath: v.optional(v.string()),
githubRunId: v.optional(v.number()),
},
handler: async (ctx, args) => {
const build = await ctx.db.get(args.buildId)
if (!build) return
const updateData: BuildUpdateData & { artifactPath?: string } = {
const updateData: BuildUpdateData & {
artifactPath?: string
githubRunId?: number
} = {
status: args.status,
}
@@ -318,6 +322,11 @@ export const updateBuildStatus = internalMutation({
updateData.artifactPath = args.artifactPath
}
// Set githubRunId if provided
if (args.githubRunId !== undefined) {
updateData.githubRunId = args.githubRunId
}
await ctx.db.patch(args.buildId, updateData)
},
})

View File

@@ -15,9 +15,9 @@ http.route({
// Verify signature (TODO: Add HMAC verification)
// Validate build_id is present
if (!payload.build_id || !payload.status) {
return new Response('Missing build_id or status', { status: 400 })
// Validate build_id and state are present
if (!payload.build_id || !payload.state) {
return new Response('Missing build_id or state', { status: 400 })
}
// Verify build exists
@@ -29,16 +29,16 @@ http.route({
return new Response('Build not found', { status: 404 })
}
// Handle status updates (intermediate statuses) and completion (final statuses)
if (payload.action === 'status_update' || payload.action === 'completed') {
await ctx.runMutation(internal.builds.updateBuildStatus, {
buildId: payload.build_id,
status: payload.status,
artifactPath: payload.artifactPath,
})
const githubRunId = payload.github_run_id
? Number(payload.github_run_id)
: undefined
return new Response(null, { status: 200 })
}
await ctx.runMutation(internal.builds.updateBuildStatus, {
buildId: payload.build_id,
status: payload.state,
artifactPath: payload.artifactPath,
githubRunId,
})
return new Response(null, { status: 200 })
}),