Skip to content

Commit

Permalink
gh workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonianb committed Aug 26, 2024
1 parent fda94ac commit 55a72d0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/codius-astro/src/lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const apps = sqliteTable(
status: text("status", { enum: ["deployed", "failed", "pending"] })
.notNull()
.default("pending"),
// TODO: remove
githubWorkflowJobId: integer("github_workflow_job_id"),
githubWorkflowRunId: integer("github_workflow_run_id"),
createdAt: integer("created_at", { mode: "timestamp" })
Expand Down
3 changes: 2 additions & 1 deletion packages/codius-astro/src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const triggerWorkflow = async (
const octokit = new Octokit({
auth,
})
await octokit.rest.actions.createWorkflowDispatch({
const resp = await octokit.rest.actions.createWorkflowDispatch({
workflow_id: "deploy-worker.yml",
owner: "codius",
repo: "codius-astro",
Expand All @@ -55,4 +55,5 @@ export const triggerWorkflow = async (
dispatchNamespace,
},
})
console.log(resp)
}
59 changes: 34 additions & 25 deletions packages/codius-astro/src/pages/webhooks/github/workflow-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,43 @@ export async function POST(context: APIContext): Promise<Response> {
secret: context.locals.runtime.env.GITHUB_WEBHOOK_SECRET,
})

webhooks.on("workflow_job.in_progress", async (data) => {
// steps[1] isn't consistently included in workflow_job.in_progress
// so we can't reliable get appId + jobId + runId until workflow_job.completed
if (
data.payload.workflow_job.workflow_name === WORKFLOW_NAME &&
data.payload.workflow_job.steps[1]
) {
const appId = data.payload.workflow_job.steps[1].name
webhooks.on("workflow_dispatch", async (data) => {
console.log(JSON.stringify(data, null, 2))
// const appId = data.payload.inputs.appId
// await context.locals.db.apps.updateGitHubWorkflowJob(appId, {
// githubWorkflowRunId: data.payload.workflow.id,
// })
})

await context.locals.db.apps.updateGitHubWorkflowJob(appId, {
githubWorkflowJobId: data.payload.workflow_job.id,
githubWorkflowRunId: data.payload.workflow_job.run_id,
})
}
webhooks.on("workflow_run.in_progress", async (data) => {
console.log(JSON.stringify(data, null, 2))
// data.payload.workflow.display_title
// // steps[1] isn't consistently included in workflow_job.in_progress
// // so we can't reliable get appId + jobId + runId until workflow_job.completed
// if (
// data.payload.workflow_run.name === WORKFLOW_NAME &&
// data.payload.workflow_run.steps[1]
// ) {
// const appId = data.payload.workflow_job.steps[1].name

// await context.locals.db.apps.updateGitHubWorkflowJob(appId, {
// githubWorkflowRunId: data.payload.workflow_run.id,
// })
// }
})

webhooks.on("workflow_job.completed", async (data) => {
if (data.payload.workflow_job.workflow_name === WORKFLOW_NAME) {
const appId = data.payload.workflow_job.steps[1].name
await context.locals.db.apps.updateCompletedGitHubWorkflowJob(appId, {
githubWorkflowJobId: data.payload.workflow_job.id,
githubWorkflowRunId: data.payload.workflow_job.run_id,
status:
data.payload.workflow_job.conclusion === "success"
? "deployed"
: "failed",
})
}
webhooks.on("workflow_run.completed", async (data) => {
console.log(JSON.stringify(data, null, 2))
// if (data.payload.workflow_run.name === WORKFLOW_NAME) {
// const appId = data.payload.workflow_run.steps[1].name
// await context.locals.db.apps.updateCompletedGitHubWorkflowJob(appId, {
// githubWorkflowRunId: data.payload.workflow_run.id,
// status:
// data.payload.workflow_run.conclusion === "success"
// ? "deployed"
// : "failed",
// })
// }
})

try {
Expand Down

0 comments on commit 55a72d0

Please sign in to comment.