Skip to content

Record and expose the PR number for GitHub jobs #71

@emilyalbini

Description

@emilyalbini

Right now buildomat tracks some metadata through tags in GitHub jobs (for example gong.run.github_id or gong.head.branch).

I'm working on the Omicron integration with Trunk, which requires running their CLI with a secret token to upload JUnit XML reports to their platform. As Buildomat doesn't support secrets, I created a GitHub Actions workflow with the secret that calls a script responsible for fetching all the metadata Trunk requires, the JUnit XML report, and uploading it to their platform.

This works for the most part, except with PRs coming from forks of omicron outside our organization (which some of our colleagues use). This is because the GitHub API (and the API only, not the web UI) doesn't attach PRs coming from forks to a commit (example check run):

$ gh api repos/oxidecomputer/omicron/check-runs/49281946346 | jq '.head_sha, .pull_requests'
"29f079bdce96a0c4ba328c7e5155c7cd2123bee9"
[]
$ gh api repos/oxidecomputer/omicron/commits/29f079bdce96a0c4ba328c7e5155c7cd2123bee9/pulls
[]

GitHub does return the information if I look directly in the fork, but there is also no way to reliably know which fork the commit comes from:

$ gh api repos/karencfv/omicron/commits/cd38f25aafc93560877f7ec4aa8f21ec81488bd6/pulls | jq '.[].number'
8846

On the other hand, Buildomat does receive the PR number attached to a workflow run in the pull_request event. Exposing the PR number in a machine-readable information would make the script more reliable. A possible implementation would be to add a gong.pr.number tag when the pull_request event is received, and returning a JSON representation of a subset of the details page when Accept is not text/html:

$ curl https://buildomat.eng.oxide.computer/wg/0/details/01K5DJN34XQB9MKG2DPV4X4MAS/GolsAfx7CS23Y9l5J9miocea0lK1p0dQdYoQii1LPXrdxXSR/01K5DJNDHFNE5HV56PE56FBJS0
{
    "tags": {
        "gong.run.id": 12345,
        "gong.pr.number": 234,
        # ...
    },
    "artefacts": [
        {
            "name": "path/to/junit.xml",
            "downlaod": "https://..."
        }
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions