Kosmos Actions

Reusable Actions for Kosmos repositories. Currently one:

required-labels

Fail a pull request unless it carries the required labels. It reads the current labels from the forge API with the workflow token, falling back to the event payload if the API is unavailable. It needs no special permissions and behaves the same on GitHub Actions and Gitea Actions.

Reading via the API matters on Gitea: the label_updated payload (fired for label add/remove) leaves pull_request.labels empty, so a payload-only check would not notice a label being added.

Draft ("WIP") pull requests pass by default, so the check only fails once a pull request is ready for review. Set draft-passes: "false" to enforce on drafts too.

Inputs

Input Description Default
labels Required labels, one per line or comma-separated. Each entry is a regular expression when use-regex is true. ""
mode any (at least one), all, or exactly. any
count Number of matches required when mode is exactly. 1
use-regex Treat each entry in labels as a regular expression. false
message Extra text appended to the failure output. ""
draft-passes Pass draft ("WIP") pull requests instead of failing them. true

Outputs: labels — the required entries that matched, comma-separated.

An empty labels input, or the literal disabled, makes the check pass. Matching is case-insensitive. Anchor regexes (^...$) when you need an exact match.

This repository is registered as a scoped workflow source for the kosmos org. .gitea/scoped_workflows/required-labels.yaml then runs on every org repository and, once marked required, gates merges.

The scoped workflow calls the action by absolute URL (https://gitea.kosmos.org/kosmos/actions/required-labels@v1). The self: prefix is documented as equivalent, but on this Gitea/runner combination a step-level uses: self:... failed before any job started, while the FQDN form works.

Rollout (one-off, UI-only — Gitea exposes no API for this):

  1. Org Settings → Actions → Scoped Workflows → add kosmos/actions.
  2. Leave it not required and soak: confirm the Required labels check runs on a test repository (e.g. kosmos/test-one-two).
  3. Mark required-labels.yaml required with status-check pattern kosmos/actions: Required labels / *. Note: a required check only gates target branches that have a branch-protection rule.

Configuration is done with Actions variables (org default, per-repo override):

  • REQUIRED_PR_LABELS — the required labels/regexes. Org default: ^kredits(-[123]|/(small|medium|large))$.
  • REQUIRED_PR_LABELS_MODE — any, all, or exactly. Default any.
  • REQUIRED_PR_LABELS_DRAFT_PASSES — set to false to enforce on drafts too. Default (unset) is true.

A repository opts out by setting REQUIRED_PR_LABELS to disabled.

The check is fail-open: an empty REQUIRED_PR_LABELS passes. The repo's own test workflow asserts the org variable is non-empty so an accidental wipe is noticed.

GitHub (per-repo)

name: Required labels
on:
  pull_request:
    types: [opened, reopened, labeled, unlabeled, synchronize, edited, ready_for_review, converted_to_draft]
jobs:
  required-labels:
    name: Required labels
    runs-on: ubuntu-latest
    steps:
      - uses: 67P/actions/required-labels@v1
        with:
          labels: '^kredits(-[123]|/(small|medium|large))$'
          use-regex: "true"
          mode: any

Then require the Required labels / required-labels check in the repository's branch protection or ruleset.

Development

bash test/run-tests.sh

kosmos/actions (Gitea) is canonical; 67P/actions (GitHub) is a mirror. Tag a release on both so @v1 resolves.

S
Description
Reusable Actions for Kosmos repositories (required-labels)
Readme
73 KiB
0 Stars 8 Watchers 0 Forks
Languages
Shell 100%