Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Specifiable targets - graphql-codegen #475

Closed
wants to merge 44 commits into from
Closed

Conversation

kachick
Copy link
Owner

@kachick kachick commented May 5, 2023

Resolves #474

Looks still nothing in GraphQL: https://docs.github.com/en/graphql/overview/explorer

REST based API needs to get workflow names as https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28

gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/kachick/wait-other-jobs/actions/workflows
{
  "total_count": 5,
  "workflows": [
    {
      "id": 45658325,
      "node_id": "W_kwDOHZ9uqs4CuLDV",
      "name": "CI",
      "path": ".github/workflows/ci.yml",
      "state": "active",
      "created_at": "2023-01-17T13:31:53.000+09:00",
      "updated_at": "2023-01-17T13:31:53.000+09:00",
      "url": "https://api.github.com/repos/kachick/wait-other-jobs/actions/workflows/45658325",
      "html_url": "https://github.com/kachick/wait-other-jobs/blob/main/.github/workflows/ci.yml",
      "badge_url": "https://github.com/kachick/wait-other-jobs/workflows/CI/badge.svg"
    },
    {
      "id": 27324077,
      "node_id": "W_kwDOHZ9uqs4BoO6t",
      "name": "Dependency Review",
      "path": ".github/workflows/dependency-review.yml",
      "state": "active",
      "created_at": "2022-06-02T10:20:59.000+09:00",
      "updated_at": "2022-06-02T10:20:59.000+09:00",
      "url": "https://api.github.com/repos/kachick/wait-other-jobs/actions/workflows/27324077",
      "html_url": "https://github.com/kachick/wait-other-jobs/blob/main/.github/workflows/dependency-review.yml",
      "badge_url": "https://github.com/kachick/wait-other-jobs/workflows/Dependency%20Review/badge.svg"
    },
    {
      "id": 29518292,
      "node_id": "W_kwDOHZ9uqs4BwmnU",
      "name": "Format",
      "path": ".github/workflows/format.yml",
      "state": "active",
      "created_at": "2022-07-04T17:29:55.000+09:00",
      "updated_at": "2022-07-06T02:38:43.000+09:00",
      "url": "https://api.github.com/repos/kachick/wait-other-jobs/actions/workflows/29518292",
      "html_url": "https://github.com/kachick/wait-other-jobs/blob/main/.github/workflows/format.yml",
      "badge_url": "https://github.com/kachick/wait-other-jobs/workflows/Format/badge.svg"
    },
    {
      "id": 29636671,
      "node_id": "W_kwDOHZ9uqs4BxDg_",
      "name": "Itself",
      "path": ".github/workflows/itself.yml",
      "state": "active",
      "created_at": "2022-07-06T02:47:51.000+09:00",
      "updated_at": "2022-07-06T02:47:51.000+09:00",
      "url": "https://api.github.com/repos/kachick/wait-other-jobs/actions/workflows/29636671",
      "html_url": "https://github.com/kachick/wait-other-jobs/blob/main/.github/workflows/itself.yml",
      "badge_url": "https://github.com/kachick/wait-other-jobs/workflows/Itself/badge.svg"
    },
    {
      "id": 39084448,
      "node_id": "W_kwDOHZ9uqs4CVGGg",
      "name": "Merge bot PR after CI",
      "path": ".github/workflows/merge-bot-pr.yml",
      "state": "active",
      "created_at": "2022-10-30T16:06:06.000+09:00",
      "updated_at": "2022-10-30T16:06:06.000+09:00",
      "url": "https://api.github.com/repos/kachick/wait-other-jobs/actions/workflows/39084448",
      "html_url": "https://github.com/kachick/wait-other-jobs/blob/main/.github/workflows/merge-bot-pr.yml",
      "badge_url": "https://github.com/kachick/wait-other-jobs/workflows/Merge%20bot%20PR%20after%20CI/badge.svg"
    }
  ]
}

List does not show useful props.
Getting from the filename is a way. But might make N+1 query

gh api \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/kachick/wait-other-jobs/actions/workflows/itself.yml
{
  "id": 29636671,
  "node_id": "W_kwDOHZ9uqs4BxDg_",
  "name": "Itself",
  "path": ".github/workflows/itself.yml",
  "state": "active",
  "created_at": "2022-07-06T02:47:51.000+09:00",
  "updated_at": "2022-07-06T02:47:51.000+09:00",
  "url": "https://api.github.com/repos/kachick/wait-other-jobs/actions/workflows/29636671",
  "html_url": "https://github.com/kachick/wait-other-jobs/blob/main/.github/workflows/itself.yml",
  "badge_url": "https://github.com/kachick/wait-other-jobs/workflows/Itself/badge.svg"
}

@kachick kachick added the enhancement New feature or request label May 5, 2023
@kachick
Copy link
Owner Author

kachick commented May 9, 2023

Struggling with API and schema is an annoy task to me, ChatGPT helped me a lot 😇

query GetCheckRuns($commitSha: String!) {
  repository(owner: "kachick", name: "wait-other-jobs") {
    object(expression: $commitSha) {
      ... on Commit {
        checkSuites(first: 10) {
          edges {
            node {
              id
              status
              conclusion
              workflowRun {
                id
                databaseId
                createdAt
                workflow {
                  id
                  databaseId
                  name
                  resourcePath
                  url
                }
              }
              checkRuns(first: 10) {
                edges {
                  node {
                    id
                    databaseId
                    name
                    status
                    conclusion
                    startedAt
                    completedAt
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
{
  "commitSha": "4686c4074b62976294e65cd06eafd7429784ff02"
}
{
  "data": {
    "repository": {
      "object": {
        "checkSuites": {
          "edges": [
            {
              "node": {
                "id": "CS_kwDOHZ9uqs8AAAAC-PmvVA",
                "status": "QUEUED",
                "conclusion": null,
                "workflowRun": null,
                "checkRuns": {
                  "edges": []
                }
              }
            },
            {
              "node": {
                "id": "CS_kwDOHZ9uqs8AAAAC-PmvYg",
                "status": "QUEUED",
                "conclusion": null,
                "workflowRun": null,
                "checkRuns": {
                  "edges": []
                }
              }
            },
            {
              "node": {
                "id": "CS_kwDOHZ9uqs8AAAAC-Pm0GA",
                "status": "COMPLETED",
                "conclusion": "SUCCESS",
                "workflowRun": {
                  "id": "WFR_kwLOHZ9uqs8AAAABJXjfEg",
                  "databaseId": 4923645714,
                  "createdAt": "2023-05-09T07:46:31Z",
                  "workflow": {
                    "id": "W_kwDOHZ9uqs4BxDg_",
                    "databaseId": 29636671,
                    "name": "Itself",
                    "resourcePath": "/kachick/wait-other-jobs/actions/workflows/itself.yml",
                    "url": "https://github.com/kachick/wait-other-jobs/actions/workflows/itself.yml"
                  }
                },
                "checkRuns": {
                  "edges": [
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuI-WQ",
                        "databaseId": 13335936601,
                        "name": "equal_intervals",
                        "status": "COMPLETED",
                        "conclusion": "SUCCESS",
                        "startedAt": "2023-05-09T07:46:38Z",
                        "completedAt": "2023-05-09T07:47:01Z"
                      }
                    },
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuJoRw",
                        "databaseId": 13335947335,
                        "name": "default",
                        "status": "COMPLETED",
                        "conclusion": "SUCCESS",
                        "startedAt": "2023-05-09T07:47:10Z",
                        "completedAt": "2023-05-09T07:47:43Z"
                      }
                    }
                  ]
                }
              }
            },
            {
              "node": {
                "id": "CS_kwDOHZ9uqs8AAAAC-Pm0Gg",
                "status": "COMPLETED",
                "conclusion": "SUCCESS",
                "workflowRun": {
                  "id": "WFR_kwLOHZ9uqs8AAAABJXjfEA",
                  "databaseId": 4923645712,
                  "createdAt": "2023-05-09T07:46:31Z",
                  "workflow": {
                    "id": "W_kwDOHZ9uqs4BwmnU",
                    "databaseId": 29518292,
                    "name": "Format",
                    "resourcePath": "/kachick/wait-other-jobs/actions/workflows/format.yml",
                    "url": "https://github.com/kachick/wait-other-jobs/actions/workflows/format.yml"
                  }
                },
                "checkRuns": {
                  "edges": [
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuI-Yw",
                        "databaseId": 13335936611,
                        "name": "format",
                        "status": "COMPLETED",
                        "conclusion": "SUCCESS",
                        "startedAt": "2023-05-09T07:46:40Z",
                        "completedAt": "2023-05-09T07:46:51Z"
                      }
                    }
                  ]
                }
              }
            },
            {
              "node": {
                "id": "CS_kwDOHZ9uqs8AAAAC-Pm0KQ",
                "status": "COMPLETED",
                "conclusion": "SKIPPED",
                "workflowRun": {
                  "id": "WFR_kwLOHZ9uqs8AAAABJXjfGA",
                  "databaseId": 4923645720,
                  "createdAt": "2023-05-09T07:46:31Z",
                  "workflow": {
                    "id": "W_kwDOHZ9uqs4CVGGg",
                    "databaseId": 39084448,
                    "name": "Merge bot PR after CI",
                    "resourcePath": "/kachick/wait-other-jobs/actions/workflows/merge-bot-pr.yml",
                    "url": "https://github.com/kachick/wait-other-jobs/actions/workflows/merge-bot-pr.yml"
                  }
                },
                "checkRuns": {
                  "edges": [
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuI-ag",
                        "databaseId": 13335936618,
                        "name": "dependabot",
                        "status": "COMPLETED",
                        "conclusion": "NEUTRAL",
                        "startedAt": "2023-05-09T07:46:32Z",
                        "completedAt": "2023-05-09T07:46:32Z"
                      }
                    },
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuI_Tg",
                        "databaseId": 13335936846,
                        "name": "renovate",
                        "status": "COMPLETED",
                        "conclusion": "NEUTRAL",
                        "startedAt": "2023-05-09T07:46:33Z",
                        "completedAt": "2023-05-09T07:46:33Z"
                      }
                    }
                  ]
                }
              }
            },
            {
              "node": {
                "id": "CS_kwDOHZ9uqs8AAAAC-Pm0LA",
                "status": "COMPLETED",
                "conclusion": "SUCCESS",
                "workflowRun": {
                  "id": "WFR_kwLOHZ9uqs8AAAABJXjfFw",
                  "databaseId": 4923645719,
                  "createdAt": "2023-05-09T07:46:31Z",
                  "workflow": {
                    "id": "W_kwDOHZ9uqs4CuLDV",
                    "databaseId": 45658325,
                    "name": "CI",
                    "resourcePath": "/kachick/wait-other-jobs/actions/workflows/ci.yml",
                    "url": "https://github.com/kachick/wait-other-jobs/actions/workflows/ci.yml"
                  }
                },
                "checkRuns": {
                  "edges": [
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuI-Ww",
                        "databaseId": 13335936603,
                        "name": "typecheck",
                        "status": "COMPLETED",
                        "conclusion": "SUCCESS",
                        "startedAt": "2023-05-09T07:46:40Z",
                        "completedAt": "2023-05-09T07:47:01Z"
                      }
                    },
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuJnEQ",
                        "databaseId": 13335947025,
                        "name": "lint",
                        "status": "COMPLETED",
                        "conclusion": "SUCCESS",
                        "startedAt": "2023-05-09T07:47:09Z",
                        "completedAt": "2023-05-09T07:47:29Z"
                      }
                    },
                    {
                      "node": {
                        "id": "CR_kwDOHZ9uqs8AAAADGuJnuw",
                        "databaseId": 13335947195,
                        "name": "build",
                        "status": "COMPLETED",
                        "conclusion": "SUCCESS",
                        "startedAt": "2023-05-09T07:47:07Z",
                        "completedAt": "2023-05-09T07:47:26Z"
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  }
}

--

Below is the original response with 🤖

--

Write GraphQL query to get GitHub check run states and conclusions from given commit sha

Sure! Here's an example GraphQL query you can use to get GitHub check run states and conclusions from a given commit SHA:

query GetCheckRuns($commitSha: String!) {
  repository(owner: "owner_name", name: "repository_name") {
    object(expression: $commitSha) {
      ... on Commit {
        checkSuites(first: 10) {
          edges {
            node {
              id
              status
              conclusion
              checkRuns(first: 10) {
                edges {
                  node {
                    id
                    name
                    status
                    conclusion
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

In this query, you will need to replace "owner_name" and "repository_name" with the appropriate values for your repository. You will also need to pass the commit SHA as a variable called "commitSha" when executing the query.

The query uses the checkSuites field to get a list of check suites associated with the commit. Each check suite has a status field indicating the overall state of the suite (e.g., "queued", "in_progress", "completed"), as well as a conclusion field indicating the final conclusion of the suite (e.g., "success", "failure", "neutral").

Within each check suite, the query also uses the checkRuns field to get a list of individual check runs. Each check run has a name field indicating the name of the check, as well as a status field indicating the state of the check run (e.g., "queued", "in_progress", "completed"), and a conclusion field indicating the final conclusion of the check run (e.g., "success", "failure", "neutral").

Note that this query only retrieves the first 10 check suites and first 10 check runs for each suite. You can adjust these limits as needed by modifying the first argument in each case.

kachick added a commit that referenced this pull request Jun 5, 2023
It is annoy when I have long WIP PR as #475 ...
@kachick
Copy link
Owner Author

kachick commented Jul 26, 2023

I may continue this PR after GitHub Actions will work in Node.js 20.
Because using node16 required jest, jest required ts-node, ts-node can not allow tsconfig extended array in TS5, the ecosystem issues are pain for me 🙇‍♂️

kachick/action-typescript-template#387
actions/runner#2704
#549

## Why using nodejs16 instead of deno/bun/nodejs18?
They are not yet supported in JavaScript action engine.
- https://github.com/actions/runner/blob/5421fe3f7107f770c904ed4c7e506ae7a5cde2c2/src/Runner.Worker/ActionManifestManager.cs#L492
- https://github.com/kachick/wait-other-jobs/pull/273#issuecomment-1306058624
After bumped to nodejs18, I'd like to replace jest with [built-in test runner](https://github.com/nodejs/node/pull/42325).

@kachick kachick changed the title [WIP] Specifiable targets [WIP] Specifiable targets - waiting Node.js 20 - https://github.com/actions/runner/discussions/2704 Jul 26, 2023
@kachick kachick changed the title [WIP] Specifiable targets - waiting Node.js 20 - https://github.com/actions/runner/discussions/2704 [WIP] Specifiable targets Aug 28, 2023
@kachick kachick changed the title [WIP] Specifiable targets [WIP] Specifiable targets - graphql-codegen Aug 30, 2023
@kachick kachick closed this in #574 Oct 2, 2023
@kachick kachick deleted the specify-targets branch February 9, 2024 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Specify job(s) to wait for
1 participant