Sync Labels workflow (ruaan-deysel/ha-unraid)
The Sync Labels workflow from ruaan-deysel/ha-unraid, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Sync Labels workflow from the ruaan-deysel/ha-unraid repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Sync Labels
on:
push:
branches: [main]
paths:
- ".github/labels.yml"
workflow_dispatch:
permissions:
issues: write
jobs:
labeler:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install YAML parser
run: python3 -m pip install --user pyyaml
- name: Sync labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 <<'PY'
import json
import os
import urllib.error
import urllib.parse
import urllib.request
import yaml
token = os.environ["GITHUB_TOKEN"]
repository = os.environ["GITHUB_REPOSITORY"]
api_base = "https://api.github.com"
with open(".github/labels.yml", encoding="utf-8") as f:
labels = yaml.safe_load(f) or []
def request(method: str, path: str, payload: dict | None = None):
url = f"{api_base}{path}"
data = None
if payload is not None:
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(url, data=data, method=method)
req.add_header("Authorization", f"Bearer {token}")
req.add_header("Accept", "application/vnd.github+json")
req.add_header("X-GitHub-Api-Version", "2022-11-28")
if data is not None:
req.add_header("Content-Type", "application/json")
with urllib.request.urlopen(req) as resp:
body = resp.read().decode("utf-8")
return json.loads(body) if body else None
for label in labels:
name = label["name"]
payload = {
"name": name,
"color": label["color"],
"description": label.get("description", ""),
}
create_path = f"/repos/{repository}/labels"
try:
request("POST", create_path, payload)
print(f"Created label: {name}")
except urllib.error.HTTPError as err:
if err.code != 422:
raise
patch_path = (
f"/repos/{repository}/labels/"
f"{urllib.parse.quote(name, safe='')}"
)
request("PATCH", patch_path, payload)
print(f"Updated label: {name}")
print("Label sync complete (skip-delete behavior preserved).")
PY
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Sync Labels on: push: branches: [main] paths: - ".github/labels.yml" workflow_dispatch: permissions: issues: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: labeler: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - name: Install YAML parser run: python3 -m pip install --user pyyaml - name: Sync labels env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | python3 <<'PY' import json import os import urllib.error import urllib.parse import urllib.request import yaml token = os.environ["GITHUB_TOKEN"] repository = os.environ["GITHUB_REPOSITORY"] api_base = "https://api.github.com" with open(".github/labels.yml", encoding="utf-8") as f: labels = yaml.safe_load(f) or [] def request(method: str, path: str, payload: dict | None = None): url = f"{api_base}{path}" data = None if payload is not None: data = json.dumps(payload).encode("utf-8") req = urllib.request.Request(url, data=data, method=method) req.add_header("Authorization", f"Bearer {token}") req.add_header("Accept", "application/vnd.github+json") req.add_header("X-GitHub-Api-Version", "2022-11-28") if data is not None: req.add_header("Content-Type", "application/json") with urllib.request.urlopen(req) as resp: body = resp.read().decode("utf-8") return json.loads(body) if body else None for label in labels: name = label["name"] payload = { "name": name, "color": label["color"], "description": label.get("description", ""), } create_path = f"/repos/{repository}/labels" try: request("POST", create_path, payload) print(f"Created label: {name}") except urllib.error.HTTPError as err: if err.code != 422: raise patch_path = ( f"/repos/{repository}/labels/" f"{urllib.parse.quote(name, safe='')}" ) request("PATCH", patch_path, payload) print(f"Updated label: {name}") print("Label sync complete (skip-delete behavior preserved).") PY
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.
- Add a job timeout so a hung step cannot burn hours of runner time.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.