|
| 1 | +# How to Sync GitHub Labels |
| 2 | + |
| 3 | +This guide explains how to manage GitHub labels across SmartEM repositories using the label sync tool. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The SmartEM ecosystem uses a standardised set of GitHub labels across four repositories: |
| 8 | + |
| 9 | +- `DiamondLightSource/smartem-decisions` |
| 10 | +- `DiamondLightSource/smartem-frontend` |
| 11 | +- `DiamondLightSource/smartem-devtools` |
| 12 | +- `DiamondLightSource/fandanGO-cryoem-dls` |
| 13 | + |
| 14 | +Labels are defined in `core/github-tags-config.ts` and synced using `tools/github/sync-labels.ts`. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- Node.js 18+ |
| 19 | +- GitHub CLI (`gh`) installed and authenticated |
| 20 | +- For sync operations: write access to target repositories |
| 21 | + |
| 22 | +## Label Categories |
| 23 | + |
| 24 | +### Types of Work |
| 25 | + |
| 26 | +Labels that categorise the nature of work being done: |
| 27 | + |
| 28 | +| Label | Colour | Purpose | |
| 29 | +|-------|--------|---------| |
| 30 | +| documentation | teal | Improvements or additions to project documentation | |
| 31 | +| testing | green | Writing, updating, or fixing automated tests | |
| 32 | +| bugfixing | red | Fixing defects or unexpected behavior | |
| 33 | +| development | purple | New features or functionality implementation | |
| 34 | +| refactoring | orange | Code restructuring without changing behavior | |
| 35 | +| research | cyan | Investigation, spikes, or proof-of-concept work | |
| 36 | +| devops | slate | CI/CD, deployment, infrastructure, or tooling | |
| 37 | +| security | maroon | Security fixes, audits, or vulnerability remediation | |
| 38 | +| admin | brown | Project maintenance, dependency updates | |
| 39 | +| enhancement | dark cyan | Minor improvements to existing functionality | |
| 40 | + |
| 41 | +### System Components |
| 42 | + |
| 43 | +Labels that identify which part of the system is affected: |
| 44 | + |
| 45 | +| Label | Colour Family | Purpose | |
| 46 | +|-------|---------------|---------| |
| 47 | +| smartem-backend | Blue (dark) | Core backend services | |
| 48 | +| smartem-backend:db | Blue (mid) | Database and data layer | |
| 49 | +| smartem-backend:api | Blue (light) | REST API endpoints | |
| 50 | +| smartem-agent | Gold | EPU workstation agent | |
| 51 | +| smartem-frontend | Green | User-facing web UI | |
| 52 | +| smartem-aria-connector | Purple | ARIA/FandanGO integration | |
| 53 | +| smartem-devtools | Pink (dark) | Developer tooling | |
| 54 | +| smartem-devtools:webui | Pink (mid) | Developer dashboard | |
| 55 | +| smartem-devtools:claude | Pink (light) | Claude Code configuration | |
| 56 | +| smartem-devtools:e2e-test | Pink (lightest) | E2E testing infrastructure | |
| 57 | + |
| 58 | +## Usage |
| 59 | + |
| 60 | +### Check Label Conformity |
| 61 | + |
| 62 | +To check if all repositories have the correct labels without making changes: |
| 63 | + |
| 64 | +```bash |
| 65 | +npm run labels:check |
| 66 | +``` |
| 67 | + |
| 68 | +Or directly: |
| 69 | + |
| 70 | +```bash |
| 71 | +npx tsx tools/github/sync-labels.ts --check |
| 72 | +``` |
| 73 | + |
| 74 | +This will: |
| 75 | +1. Fetch existing labels from each repository |
| 76 | +2. Compare against the defined labels in `core/github-tags-config.ts` |
| 77 | +3. Report any discrepancies (missing, extra, or outdated labels) |
| 78 | +4. Exit with code 1 if any repository is non-conforming |
| 79 | + |
| 80 | +### Sync Labels |
| 81 | + |
| 82 | +To synchronise labels across all repositories: |
| 83 | + |
| 84 | +```bash |
| 85 | +npm run labels:sync |
| 86 | +``` |
| 87 | + |
| 88 | +Or directly: |
| 89 | + |
| 90 | +```bash |
| 91 | +npx tsx tools/github/sync-labels.ts --sync |
| 92 | +``` |
| 93 | + |
| 94 | +This will: |
| 95 | +1. Delete labels not in the definition (extra labels) |
| 96 | +2. Create labels that are missing |
| 97 | +3. Update labels where description or colour has changed |
| 98 | + |
| 99 | +### Target Specific Repositories |
| 100 | + |
| 101 | +To sync only specific repositories: |
| 102 | + |
| 103 | +```bash |
| 104 | +npx tsx tools/github/sync-labels.ts --sync --repo smartem-decisions |
| 105 | +npx tsx tools/github/sync-labels.ts --sync --repo smartem-frontend --repo smartem-devtools |
| 106 | +``` |
| 107 | + |
| 108 | +### Verbose Output |
| 109 | + |
| 110 | +For detailed output including conforming labels: |
| 111 | + |
| 112 | +```bash |
| 113 | +npx tsx tools/github/sync-labels.ts --check --verbose |
| 114 | +``` |
| 115 | + |
| 116 | +## CI/CD Integration |
| 117 | + |
| 118 | +The `gitflow.yml` workflow automates label management: |
| 119 | + |
| 120 | +- **On push to main**: Runs `--check` mode when `core/github-tags-config.ts` or `tools/github/**` changes |
| 121 | +- **Manual dispatch**: Can trigger `--sync` mode via GitHub Actions UI |
| 122 | + |
| 123 | +### Running Sync via CI/CD |
| 124 | + |
| 125 | +1. Go to Actions tab in smartem-devtools repository |
| 126 | +2. Select "Gitflow" workflow |
| 127 | +3. Click "Run workflow" |
| 128 | +4. Select `sync` mode |
| 129 | +5. Click "Run workflow" |
| 130 | + |
| 131 | +## Modifying Labels |
| 132 | + |
| 133 | +To add, remove, or modify labels: |
| 134 | + |
| 135 | +1. Edit `core/github-tags-config.ts` |
| 136 | +2. Run `npm run labels:check` to verify changes |
| 137 | +3. Run `npm run labels:sync` to apply changes |
| 138 | +4. Commit and push changes |
| 139 | + |
| 140 | +The CI/CD workflow will verify conformity on push. |
| 141 | + |
| 142 | +## Troubleshooting |
| 143 | + |
| 144 | +### Authentication Errors |
| 145 | + |
| 146 | +Ensure `gh` CLI is authenticated: |
| 147 | + |
| 148 | +```bash |
| 149 | +gh auth status |
| 150 | +gh auth login # if not authenticated |
| 151 | +``` |
| 152 | + |
| 153 | +### Permission Denied |
| 154 | + |
| 155 | +For sync operations, you need write access to all target repositories. The CI/CD workflow uses a PAT stored as `LABEL_SYNC_TOKEN` secret. |
| 156 | + |
| 157 | +### Label Already Exists |
| 158 | + |
| 159 | +If a label creation fails because it already exists, the script will continue. Run with `--verbose` to see details. |
0 commit comments