Skip to content

Find the owners from CODEOWNERS in GitHub Actions

License

Notifications You must be signed in to change notification settings

int128/find-codeowners-action

Repository files navigation

find-codeowners-action ts

This action finds the owners from CODEOWNERS.

Getting Started

To find the owners of a file,

steps:
  - uses: actions/checkout@v4
  - id: codeowners
    uses: int128/find-codeowners-action@v0
    with:
      codeowners: CODEOWNERS
      path: src/index.ts

This action reads CODEOWNERS file in the working directory, and finds the owners of src/index.ts.

If no owner is found, this action returns an empty string.

Examples

Notify a workflow run event to the owners

To notify an event to the corresponding owners,

on:
  workflow_run:
    types:
      - completed

jobs:
  notify-workflow-run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - id: codeowners
        uses: int128/find-codeowners-action@v0
        with:
          codeowners: CODEOWNERS
          path: ${{ github.event.workflow.path }}

      # Something to notify
      - uses: slackapi/slack-github-action@v1
        with:
          channel-id: example
          slack-message: |
            Hey ${{ steps.codeowners.outputs.owners-without-organization }}, done!

Test the coverage of CODEOWNERS

To ensure the all workflows are owned by anyone,

jobs:
  validate-coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - id: codeowners
        uses: int128/find-codeowners-action@v0
        with:
          codeowners: CODEOWNERS
          path: .github/workflows/*
          path-glob: true
      - if: steps.codeowners.outputs.orphan-files
        run: exit 1

If a file is not owned in CODEOWNERS, this action shows the message.

Warning: File .github/workflows/build.yaml is not owned by anyone

Specification

Inputs

Name Default Description
codeowners (required) Path of CODEOWNERS
path (required) Path(s) to find the owners (multiline)
path-glob false If true, evaluate path as glob pattern(s)

Outputs

Name Description
owners List of owners, separated by space
owners-without-organization List of owners in the form of @user or @team, separated by space
orphan-files List of files which are not owned in CODEOWNERS, separated by new line