diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index fb6c92f..0ff1b58 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -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" diff --git a/convex/builds.ts b/convex/builds.ts index 76fedc1..d418942 100644 --- a/convex/builds.ts +++ b/convex/builds.ts @@ -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) }, }) diff --git a/convex/http.ts b/convex/http.ts index c59852f..a5ee5e2 100644 --- a/convex/http.ts +++ b/convex/http.ts @@ -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 }) }),