Skip to content

cssnr/label-creator-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub Tag Major GitHub Tag Minor GitHub Release Version GitHub Dist Size Workflow Release Workflow Test Workflow Lint Quality Gate Status GitHub Last Commit Codeberg Last Commit GitHub Contributors GitHub Repo Size GitHub Top Language GitHub Forks GitHub Repo Stars GitHub Org Stars Discord Ko-fi

Label Creator Action

Automatically Create or Update Labels to ensure they exist and are synchronized. Works from a centralized remote configuration file/url, local file or inline config.

This works by fetching the configuration file and current repository labels. It loops through the configuration and checks if the provided labels exist. If the label does not exist, it creates a new label with the name, color and description. If the label exist, it makes sure the color and description matches, otherwise updates them. You can also enable delete which will delete any labels not in the configuration file.

- name: 'Label Creator'
  uses: cssnr/label-creator-action@v1

Features

Configuration

The configuration file can be remote file, local file, or inline JSON string. In all cases the same format is used.

source:
  color: fbca04
  description: Source modification
documentation:
  color: 0075ca
  description: Documentation updates

Both color and description are optional; however, I assume you are using this action because you want to set one of them. If you are using actions/labeler it will create the labels, but not set the description or color.

By default, the file is sourced from .github/labels.yaml but can be placed anywhere.

This includes remote files.
Example: https://raw.githubusercontent.com/cssnr/label-creator-action/refs/heads/master/.github/labels.yaml

Inputs

All inputs are optional.

Input Default Value Description of Input
file .github/labels.yaml Configuration file path
url - Configuration file URL
json - Configuration JSON string
delete false Delete labels not in config
summary true Add Summary to Job
dry-run false Dry Run, only output results
token ${{ github.token }} GitHub Access Token PAT 1

This action is designed to work on the pull_request_target trigger.
Example workflow: .github/workflows/labeler.yaml

- name: 'Label Creator'
  uses: cssnr/label-creator-action@v1

See the Examples for usage options.

Permissions

This action requires the following permissions:

permissions:
  pull-requests: write

Permissions documentation for Workflows and Actions.

Outputs

Output Description
created Labels Created
updated Labels Updated
deleted Labels Deleted

Note: These are JSON Arrays.

- name: 'Label Creator'
  id: label
  uses: cssnr/label-creator-action@v1

- name: 'Echo Output'
  run: |
    echo "created: ${{ steps.label.outputs.created }}"
    echo "updated: ${{ steps.label.outputs.updated }}"
    echo "deleted: ${{ steps.label.outputs.deleted }}"

Examples

💡 Click on an example heading to expand or collapse the example.

With a local file.

- name: 'Label Creator'
  uses: cssnr/label-creator-action@v1
  with:
    file: .github/labels.yaml

With a remote file.

- name: 'Label Creator'
  uses: cssnr/label-creator-action@v1
  with:
    url: https://raw.githubusercontent.com/cssnr/label-creator-action/refs/heads/master/.github/labels.yaml

With an inline JSON string.

- name: 'Label Creator'
  uses: cssnr/label-creator-action@v1
  with:
    json: |
      {
        "workflows": {"color": "ffffff", "description": "Workflows modification"},
        "documentation": {"color": "0075ca", "description": "Documentation updates"},
        "source": {"color": "fbca04", "description": "Source modification"}
      }
Full Workflow

This is the workflow I use to pull centralized configuration files from a repository.

name: 'PR Labeler'

on:
  pull_request_target:

permissions:
  pull-requests: write

jobs:
  labeler:
    name: 'Labeler'
    runs-on: ubuntu-latest
    timeout-minutes: 5

    steps:
      - name: 'Checkout Configs'
        uses: actions/checkout@v4
        with:
          repository: cssnr/configs
          ref: master
          path: .configs
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            labels/**

      - name: 'Debug'
        continue-on-error: true
        run: |
          echo "::group::labels.yaml"
          cat .configs/labels/labels.yaml
          echo "::endgroup::"

          echo "::group::labeler.yaml"
          cat .configs/labels/labeler.yaml
          echo "::endgroup::"

      - name: 'Label Creator'
        continue-on-error: true
        uses: cssnr/label-creator-action@v1
        with:
          file: .configs/labels/labels.yaml

      - name: 'Labeler'
        uses: actions/labeler@v6
        with:
          sync-labels: true
          configuration-path: .configs/labels/labeler.yaml

Note: Steps with continue-on-error: true will fail silently.

For more examples, you can check out other projects using this action:
https://github.com/cssnr/label-creator-action/network/dependents

Tags

The following rolling tags are maintained.

Version Tag Rolling Bugs Feat. Name Target Example
GitHub Tag Major Major vN.x.x vN
GitHub Tag Minor Minor vN.N.x vN.N
GitHub Release Micro vN.N.N vN.N.N

You can view the release notes for each version on the releases page.

The Major tag is recommended. It is the most up-to-date and always backwards compatible. Breaking changes would result in a Major version bump. At a minimum you should use a Minor tag.

Support

For general help or to request a feature, see:

If you are experiencing an issue/bug or getting unexpected results, you can:

For more information, see the CSSNR SUPPORT.md.

Contributing

Please consider making a donation to support the development of this project and additional open source projects.

Ko-fi

If you would like to submit a PR, please review the CONTRIBUTING.md.

Additionally, you can support other GitHub Actions I have published:

For a full list of current projects visit: https://cssnr.github.io/

Footnotes

  1. The ${{ github.token }} / {{ secrets.GITHUB_TOKEN }} is automatically passed, there is no need to manually pass these! This is only available to allow users to pass a different token they have created and defined in their secrets.

About

Automatically Create or Update Labels to ensure they exist and are synchronized.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project