Pull Request Title workflow (powerapi-ng/powerapi)
The Pull Request Title workflow from powerapi-ng/powerapi, explained and optimized by Latchkey.
A
CI health: A - excellent
Point runs-on at Latchkey and get run de-duplication, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Pull Request Title workflow from the powerapi-ng/powerapi repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: Pull Request Title
on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
permissions: {}
jobs:
semantic-title:
name: Validate semantic format
runs-on: ubuntu-latest
timeout-minutes: 2
concurrency:
group: pr-semantic-title-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- shell: python
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_VALID_TYPES: |
feat
fix
refactor
docs
test
build
ci
chore
run: |
import os
import re
import sys
pr_title = os.environ.get("PR_TITLE", "").strip()
if not pr_title:
print("ERROR: PR_TITLE environment variable is missing or empty.", file=sys.stderr)
sys.exit(1)
pr_valid_types = [
valid_type for raw_type in os.environ.get("PR_VALID_TYPES", "").splitlines()
if (valid_type := raw_type.strip()) and not valid_type.startswith("#")
]
if not pr_valid_types:
print("ERROR: PR_VALID_TYPES environment variable is missing or empty.", file=sys.stderr)
sys.exit(1)
title_pattern = re.compile(
r"^(?P<type>[A-Za-z0-9_-]+)(?:\((?P<scope>[A-Za-z0-9_.\-/]+)\))?(?P<breaking>!)?:\s(?P<subject>\S.*)$"
)
matches = title_pattern.fullmatch(pr_title)
if not matches:
print("ERROR: Pull request title format is invalid.", file=sys.stderr)
print("Expected format: <type>(<optional-scope>)<optional-!>: <subject>", file=sys.stderr)
sys.exit(1)
pr_type = matches.group("type")
if pr_type not in pr_valid_types:
print("ERROR: Pull request semantic type is invalid.", file=sys.stderr)
print(f"Expected one of: {', '.join(pr_valid_types)}", file=sys.stderr)
sys.exit(1)
print("Pull request title is valid.")
sys.exit(0)
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Pull Request Title on: pull_request: types: - opened - edited - synchronize - reopened permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: semantic-title: name: Validate semantic format runs-on: latchkey-small timeout-minutes: 2 concurrency: group: pr-semantic-title-${{ github.event.pull_request.number }} cancel-in-progress: true steps: - shell: python env: PR_TITLE: ${{ github.event.pull_request.title }} PR_VALID_TYPES: | feat fix refactor docs test build ci chore run: | import os import re import sys pr_title = os.environ.get("PR_TITLE", "").strip() if not pr_title: print("ERROR: PR_TITLE environment variable is missing or empty.", file=sys.stderr) sys.exit(1) pr_valid_types = [ valid_type for raw_type in os.environ.get("PR_VALID_TYPES", "").splitlines() if (valid_type := raw_type.strip()) and not valid_type.startswith("#") ] if not pr_valid_types: print("ERROR: PR_VALID_TYPES environment variable is missing or empty.", file=sys.stderr) sys.exit(1) title_pattern = re.compile( r"^(?P<type>[A-Za-z0-9_-]+)(?:\((?P<scope>[A-Za-z0-9_.\-/]+)\))?(?P<breaking>!)?:\s(?P<subject>\S.*)$" ) matches = title_pattern.fullmatch(pr_title) if not matches: print("ERROR: Pull request title format is invalid.", file=sys.stderr) print("Expected format: <type>(<optional-scope>)<optional-!>: <subject>", file=sys.stderr) sys.exit(1) pr_type = matches.group("type") if pr_type not in pr_valid_types: print("ERROR: Pull request semantic type is invalid.", file=sys.stderr) print(f"Expected one of: {', '.join(pr_valid_types)}", file=sys.stderr) sys.exit(1) print("Pull request title is valid.") sys.exit(0)
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.