00b99f3841
Add dispatch-workflow.sh script that dispatches a Gitea workflow in another repository and polls synchronously for completion. Refactor mock-api.sh to use Python3 HTTP server with sequence support, enabling stateful poll-response simulation in tests.
111 lines
3.1 KiB
Markdown
111 lines
3.1 KiB
Markdown
# Ticket 0001: `report-status.sh`
|
|
|
|
**Vaihe:** 1/12
|
|
**Status:** done
|
|
**Feature branch:** `feature/0001-report-status-sh`
|
|
**TDD required:** Yes
|
|
**Feature file required:** Yes
|
|
|
|
**Required context:**
|
|
- `docs/test-plan/tdd-guide.md`
|
|
- `tests/features/0001-report-status.feature`
|
|
- Skills: `tdd`, `implementation`, `clean-code`, `bash-script`
|
|
|
|
---
|
|
|
|
## TDD — Red-Green-Refactor
|
|
|
|
### Red
|
|
Kirjoita `tests/report-status.bats` ennen implementaatiota. Testi käyttää `tests/helpers/mock-api.sh` mock-Gitea API:a. Varmista:
|
|
- `pending`-status POSTautuu oikein
|
|
- `success`-status + `url` + `key`
|
|
- `failure`-status
|
|
- Cross-repo: `root_commit` + `root_repo` → status menee root-committiin
|
|
- Virhetilanne: API palauttaa 500 → exit 1
|
|
- Puuttuva `GITEA_API_URL` → exit 1 + virheviesti
|
|
|
|
```bash
|
|
bats tests/report-status.bats
|
|
# Kaikki testit FAIL: skriptiä ei ole vielä
|
|
```
|
|
|
|
### Green
|
|
Toteuta `scripts/report-status.sh`. Minimiversio: vain curl POST + virheenkäsittely.
|
|
|
|
```bash
|
|
bats tests/report-status.bats
|
|
# Kaikki testit PASS
|
|
```
|
|
|
|
### Refactor
|
|
Poista duplikaatio, paranna virheviestejä. Testit pysyvät vihreänä.
|
|
|
|
## DoD (Definition of Done)
|
|
- [ ] Cucumber: `@ticket-0001 and @mock` → kaikki skenaariot GREEN
|
|
- [ ] `tests/report-status.bats` kaikki testit menevät läpi
|
|
- [ ] `tests/helpers/mock-api.sh` palvelee mock-vastaukset
|
|
- [ ] `scripts/report-status.sh` toteuttaa kaikki parametrit
|
|
- [ ] Cross-repo-statusraportointi toimii
|
|
|
|
---
|
|
|
|
## Toiminto
|
|
|
|
POSTaa build-statuksen Gitea REST APIin. Jokainen workflow-steppi kutsuu tätä skriptiä raportoidakseen tilansa Git-committiin.
|
|
|
|
## Rajapinta
|
|
|
|
```bash
|
|
report-status.sh <state> <description> <url> [key] [root_commit] [root_repo]
|
|
```
|
|
|
|
| Parametri | Pakollinen | Kuvaus |
|
|
|-----------|------------|--------|
|
|
| `state` | Kyllä | `pending`, `success`, `failure`, `error` |
|
|
| `description` | Kyllä | Ihmisluettava kuvaus |
|
|
| `url` | Kyllä | Linkki buildiin tai raporttiin |
|
|
| `key` | Ei | Uniikki avain. Oletus: `commit-{sha_short}` |
|
|
| `root_commit` | Ei | Root-buildin commit (cross-repo-raportointi) |
|
|
| `root_repo` | Ei | Root-buildin repo (cross-repo-raportointi) |
|
|
|
|
## Gitea API -kutsu
|
|
|
|
```
|
|
POST /api/v1/repos/{owner}/{repo}/statuses/{sha}
|
|
Authorization: token {GITEA_TOKEN}
|
|
|
|
{
|
|
"state": "{state}",
|
|
"target_url": "{url}",
|
|
"description": "{description}",
|
|
"context": "{key}"
|
|
}
|
|
```
|
|
|
|
## Ympäristömuuttujat
|
|
|
|
- `GITEA_API_URL` — Org variable
|
|
- `GITEA_TOKEN` — Org secret
|
|
- `GITHUB_REPOSITORY` — Automaattinen
|
|
- `GITHUB_SHA` — Automaattinen
|
|
- `GITHUB_SERVER_URL` — Automaattinen
|
|
- `GITHUB_RUN_ID` — Automaattinen
|
|
|
|
## Verifiointi
|
|
|
|
`bash scripts/report-status.sh success "Test OK" "https://example.com"` → mock-API palauttaa 201
|
|
|
|
Kutsu cross-repo-parametreilla:
|
|
|
|
```bash
|
|
report-status.sh success "Deployed to staging" "https://gitea.example.com/helm-repo/commit/def456" "deploy-staging" "abc123" "services/temperature-store"
|
|
```
|
|
|
|
→ statusviesti ilmestyy root-committiin `abc123`
|
|
|
|
## Viitteet
|
|
|
|
- `docs/shared-scripts.md` — Rajapinnan määrittely
|
|
- `docs/architecture.md` — Tietovuo 1: Commit-statusraportointi
|
|
- `docs/design-rationale.md` — Periaate 1: Git-commit on universaali statusnäkymä
|