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.
Gitea
There are three ways to run the check on Gitea. All use the same action and the same Actions variables; pick whichever fits the set of repositories you want to gate.
1. Org-wide (org-defined scoped workflow, required)
Register kosmos/actions once as a scoped workflow source (Org Settings →
Actions → Scoped Workflows) and mark .gitea/scoped_workflows/required-labels.yaml
required with the status-check pattern kosmos/actions: Required labels / *.
- Gates every org repository that has a branch-protection rule (a required check is only enforced on protected branches).
- Cannot be opted out of by repositories — that is the point.
- One centrally maintained workflow definition.
Rollout (one-off, UI-only — Gitea exposes no API for this): add the source, soak
with it not required (e.g. on kosmos/test-one-two), then mark it required.
2. Selected repos (org-defined scoped workflow, required per repo)
The same registration, but leave the workflow not required and require its
context per repository under branch protection → status checks with the
pattern kosmos/actions: Required labels / *.
- Only the repositories you configure are gated.
- The workflow still runs on every Actions-enabled repository and posts a green status where it is not enforced; a repository that does not want it can disable it from its Actions page.
- Central definition, per-repository enforcement. (Don't both disable it and require its pattern — that blocks the repo.)
3. Per-repo (repository workflow file)
Add .gitea/workflows/required-labels.yaml to each repository you want to gate
and require its check in that repository's branch protection.
- No runs on other repositories at all, and the check name is repository-local.
- One small file per gated repository.
name: Required labels
on:
pull_request:
types: [opened, reopened, labeled, unlabeled, synchronize, edited, ready_for_review, converted_to_draft]
jobs:
required-labels:
name: check
runs-on: ubuntu-latest
steps:
- uses: https://gitea.kosmos.org/kosmos/actions/required-labels@v1
with:
labels: ${{ vars.REQUIRED_PR_LABELS }}
mode: ${{ vars.REQUIRED_PR_LABELS_MODE }}
draft-passes: ${{ vars.REQUIRED_PR_LABELS_DRAFT_PASSES }}
use-regex: "true"
Check names
A scoped run posts <source>: <workflow name> / <job> (<event>), e.g.
kosmos/actions: Required labels / check (pull_request); a repository-level run
posts <workflow name> / <job> (<event>), e.g.
Required labels / check (pull_request). Status-check patterns are globs, so
kosmos/actions: Required labels / * matches whatever the job is named.
Configuration (all options)
Actions variables, org default with per-repository override:
REQUIRED_PR_LABELS— the required labels/regexes. Example:^kredits(-[123]|/(small|medium|large))$.REQUIRED_PR_LABELS_MODE—any,all, orexactly. Defaultany.REQUIRED_PR_LABELS_DRAFT_PASSES— set tofalseto enforce on drafts too. Default (unset) istrue.
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.
The examples call the action by absolute URL
(https://gitea.kosmos.org/kosmos/actions/required-labels@v1). The self:
prefix is documented as equivalent for scoped workflows, but on this Gitea/runner
combination a step-level uses: self:... failed before any job started, while
the FQDN form works.
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: check
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 / check 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.