I made a CLI extension to get the Annotation list of GitHub Actions.

swfz

swfz

Posted on December 27, 2022

I made a CLI extension to get the Annotation list of GitHub Actions.

Background, Purpose

Some time ago, GitHub Actions started sending warnings to Annotation that actions using Node version 12 would be deprecated.

Image description

If the repository is well maintained, it's good to notice and respond, but I felt that there might be some omissions...

To find them, you can look at the summary on the web page of each Actions, but it takes time to go to the page every time when the number of repositories to manage increases.

That's why

I made a GitHub CLI extension to get the list of annotations of GitHub Actions.

swfz/gh-annotations: list of annotations from the recently executed Workflow

How it works

I'm trying to look at annotations from the latest execution of each Workflow in the repository, since I have to hit the API quite a bit.

So you can't get annotations from a specific Workflow that was executed a while ago.



gh annotations -repo swfz/til | jq
[
  {
    "repository": "swfz/til",
    "workflow_name": "slack notification",
    "workflow_event": "workflow_run",
    "workflow_path": ".github/workflows/slack.yml",
    "workflow_url": "https://github.com/swfz/til/actions/runs/3697438928",
    "job_name": "main",
    "job_conclusion": "success",
    "annotation_level": "warning",
    For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: swfz/slack-workflow-status@feature/follow-workflow-run"
  }
  {
    "repository": "swfz/til",
    "workflow_name": "ci",
    "workflow_event": "push",
    "workflow_path": ".github/workflows/ci.yml",
    "workflow_url": "https://github.com/swfz/til/actions/runs/3697430624",
    "job_name": "build",
    "job_conclusion": "failure",
    "annotation_level": "failure",
    "message": "Process completed with exit code 1."
  }
  {
    "repository": "swfz/til",
    "workflow_name": "lint content",
    "workflow_event": "push",
    "workflow_path": ".github/workflows/lint.yml",
    "workflow_url": "https://github.com/swfz/til/actions/runs/3694817234",
    "job_name": "run textlint",
    "job_conclusion": "failure",
    "annotation_level": "failure",
    "message": "Process completed with exit code 1."
  }
]


Enter fullscreen mode Exit fullscreen mode

install



gh extension install swfz/gh-annotations


Enter fullscreen mode Exit fullscreen mode

This is just because it's a GitHub CLI Extension, but you can use it with just the above command.

How to operate



gh annotations | jq


Enter fullscreen mode Exit fullscreen mode

Execute against the repository in your current directory.



gh annotations -repo swfz/sample | jq


Enter fullscreen mode Exit fullscreen mode

You can also specify a repository like gh annotations -repo

If you don't specify anything, it will target the directory you are in.

If you want to get information on all repositories maintained at the beginning, use

You can get a list of repositories and run gh annotations on each of them to output annotations for all repositories by using a one-liner.



gh repo list --limit 200 --json 'nameWithOwner' | jq -rc '. []|.nameWithOwner' | xargs -i sh -lc "gh annotations -repo {}" | tee -a annotations.json

Enter fullscreen mode Exit fullscreen mode




End

This was a story about creating a GitHub CLI extension to get the results of GitHub Actions annotations.

  • Catch and notify when any annotations occur by integrating it into CI.
  • Periodically output and check the results of all repositories you are managing.

I think it can be used for such purposes.

In development, I was going to implement list output in addition to JSON output, but I ran out of energy, so I decided to write the article in this state.

You can use it if you like!

swfz/gh-annotations: list of annotations from a recently executed Workflow

💖 💪 🙅 🚩
swfz
swfz

Posted on December 27, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related