consumer project käyttöönotossa tulleitea muutoksia (#12)
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 18s
CI Main / Check existing artifact (push) Successful in 12s
unit-tests Link to Bats reports
CI Main / Bats tests (push) Successful in 1m41s
acc-tests Link to Cucumber reports
CI Main / Cucumber tests (push) Successful in 1m7s
ci-docker-build-push Docker build & push 0.2.1 OK
CI Main / Build & Push Docker (push) Successful in 34s
CI Main / Report Summary (push) Successful in 4s
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 18s
CI Main / Check existing artifact (push) Successful in 12s
unit-tests Link to Bats reports
CI Main / Bats tests (push) Successful in 1m41s
acc-tests Link to Cucumber reports
CI Main / Cucumber tests (push) Successful in 1m7s
ci-docker-build-push Docker build & push 0.2.1 OK
CI Main / Build & Push Docker (push) Successful in 34s
CI Main / Report Summary (push) Successful in 4s
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
+89
-145
@@ -1,197 +1,141 @@
|
||||
# Jaetut skriptit
|
||||
|
||||
> ⚠️ **POC-vaihe.** Osa kuvatuista skripteistä (push-reports.sh, tag-commit.sh)
|
||||
> on suunniteltu mutta ei toteutettu. Toteutetut: `publish-git-pages.sh`,
|
||||
> `report-status.sh`, `dispatch-workflow.sh` (POC-taso).
|
||||
>
|
||||
> Uudelleenkirjoitus odottaa: skriptien määrä ja rajapinnat voivat muuttua.
|
||||
|
||||
Skriptit asuvat `gitea-ci-library/scripts/`-hakemistossa.
|
||||
> Provider-skriptit asuvat `scripts/`-hakemistossa. Consumer-skriptit
|
||||
> asuvat `.gitea/scripts/`-hakemistossa. ADR 0006.
|
||||
|
||||
---
|
||||
|
||||
## `report-status.sh`
|
||||
|
||||
POSTaa build-statuksen Gitea-commitin REST APIin.
|
||||
POSTaa commit-statuksen Gitea REST APIin. Käytetään **vain** kun tarvitaan
|
||||
custom-linkki (testiraportti, Docker registry). Tool-jobit luottavat
|
||||
Gitean natiiviin job-statukseen. ADR 0007.
|
||||
|
||||
### Rajapinta
|
||||
|
||||
```bash
|
||||
report-status.sh <state> <description> <url> [key] [root_commit] [root_repo]
|
||||
report-status.sh <state> <description> <context> [suite] [custom_url]
|
||||
```
|
||||
|
||||
| Parametri | Pakollinen | Kuvaus |
|
||||
|-----------|------------|--------|
|
||||
| `state` | Kyllä | `pending`, `success`, `failure`, `error` |
|
||||
| `description` | Kyllä | Ihmisluettava kuvaus (esim. "Unit tests passed") |
|
||||
| `url` | Kyllä | Linkki buildiin tai raporttiin |
|
||||
| `key` | Ei | Uniikki avain. Oletus: `commit-{sha_short}` |
|
||||
| `root_commit` | Ei | Root-buildin commit-hash (cross-repo-raportointia varten) |
|
||||
| `root_repo` | Ei | Root-buildin repo (cross-repo-raportointia varten) |
|
||||
|---|---|---|
|
||||
| `state` | Kyllä | `pending`, `success`, `failure` |
|
||||
| `description` | Kyllä | Ihmisluettava kuvaus |
|
||||
| `context` | Kyllä | Uniikki avain (`unit-tests`, `acc-tests`, `ci-docker-build-push`) |
|
||||
| `suite` | Ei | Julkaistun raportin suite-nimi → linkki git-pagesiin |
|
||||
| `custom_url` | Ei | Oma URL (ohittaa oletus-URL:n generoinnin) |
|
||||
|
||||
### Kutsuesimerkkejä
|
||||
|
||||
```bash
|
||||
# Buildin aloitus
|
||||
report-status.sh pending "Building..." "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
|
||||
# Testijobi, linkki git-pages-raporttiin
|
||||
report-status.sh success "Link to Bats reports" unit-tests bats
|
||||
|
||||
# Testivaihe valmis, linkki raporttiin
|
||||
report-status.sh success "Unit tests OK" "$MINIO_BASE_URL/$GITHUB_REPOSITORY/${GITHUB_SHA::8}/cucumber/overview-features.html" "unit-test"
|
||||
|
||||
# Deployment valmis, cross-repo: raportoi takaisin mikropalvelun committiin
|
||||
report-status.sh success "Deployed to staging" "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" "deploy-staging" "$ROOT_COMMIT" "$ROOT_REPO"
|
||||
# Docker build, custom URL registryyn
|
||||
report-status.sh success "Docker build & push 1.2.0 OK" ci-docker-build-push "" \
|
||||
"https://gitea.example.com/org/-/packages/container/app/1.2.0"
|
||||
```
|
||||
|
||||
### URL-generointi
|
||||
|
||||
- Jos `suite` annettu → URL: `${GIT_PAGES_URL}/${repo}/reports/${sha8}/${suite}/`
|
||||
- Jos `custom_url` annettu → käytetään sellaisenaan
|
||||
- Muuten → URL: `${GITEA_API_URL}/${repo}/actions/runs/${run_id}` (Gitea Actions -loki)
|
||||
|
||||
### Gitea API -kutsu
|
||||
|
||||
```bash
|
||||
curl -X POST "$GITEA_API_URL/api/v1/repos/$REPO/statuses/$COMMIT" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"state\": \"$STATE\",
|
||||
\"target_url\": \"$URL\",
|
||||
\"description\": \"$DESCRIPTION\",
|
||||
\"context\": \"$KEY\"
|
||||
}"
|
||||
-d "{\"state\":\"$STATE\",\"target_url\":\"$URL\",\"description\":\"$DESCRIPTION\",\"context\":\"$CONTEXT\"}"
|
||||
```
|
||||
|
||||
Status-arvot mapataan Gitean skeemaan: `pending` (INPROGRESS), `success` (SUCCESS), `failure` (FAILURE), `error` (STOPPED).
|
||||
---
|
||||
|
||||
## `publish-git-pages.sh`
|
||||
|
||||
Julkaisee raporttihakemiston git-pages-palveluun PATCH-tar:na.
|
||||
|
||||
### Rajapinta
|
||||
|
||||
```bash
|
||||
publish-git-pages.sh <suite>
|
||||
```
|
||||
|
||||
| Parametri | Pakollinen | Kuvaus |
|
||||
|---|---|---|
|
||||
| `suite` | Kyllä | Raporttihakemiston nimi (`bats`, `cucumber`, `junit`, ...) |
|
||||
|
||||
### Toiminta
|
||||
|
||||
1. Lukee raportit hakemistosta `reports/${SHA8}/${suite}/`
|
||||
2. Pakkaa tar:ksi ja PATCHaa git-pagesiin BasicAuthilla
|
||||
3. Tulostaa raportin base-URL:n stdoutiin
|
||||
|
||||
### Vaaditut env-muuttujat
|
||||
|
||||
| Muuttuja | Lähde |
|
||||
|---|---|
|
||||
| `GITEA_API_URL` | `env_json` → workflow `env:` |
|
||||
| `GIT_PAGES_URL` | `env_json` → workflow `env:` |
|
||||
| `GIT_PAGES_PUBLISH_TOKEN` | Gitea secret → `env:` |
|
||||
| `GITHUB_REPOSITORY` | Automaattinen |
|
||||
| `GITHUB_SHA` | Automaattinen |
|
||||
|
||||
---
|
||||
|
||||
## `ci-validate.sh`
|
||||
|
||||
Validoi `.conf`-tiedoston ja tarkistaa että pakolliset secretit on asetettu.
|
||||
Kutsutaan `config-provider.yml`:stä osana konfiguraation latausta.
|
||||
|
||||
### Rajapinta
|
||||
|
||||
```bash
|
||||
ci-validate.sh
|
||||
```
|
||||
|
||||
Lukee tiedoston polun `CI_CONF_FILE`-env-muuttujasta (oletus: `.gitea/workflows/gitea-env.conf`).
|
||||
|
||||
### Validointisäännöt
|
||||
|
||||
- `.conf`-tiedosto on olemassa
|
||||
- Jokaisella `KEY=VALUE`-rivillä on arvo (ei tyhjää)
|
||||
- URL-tyyppiset avaimet alkavat `http://` tai `https://`
|
||||
- `GITEA_TOKEN` on asetettu
|
||||
- `GIT_PAGES_PUBLISH_TOKEN` on asetettu
|
||||
|
||||
---
|
||||
|
||||
## `dispatch-workflow.sh`
|
||||
|
||||
Dispatchaa workflow'n toisessa repossa ja pollaa sen valmistumista synkronisesti.
|
||||
Käytetään GitOps-deploymentissa ja klusteritestien ketjutuksessa (tuleva).
|
||||
|
||||
### Rajapinta
|
||||
|
||||
```bash
|
||||
dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> <gitea_api_url> <gitea_token> [timeout_minutes]
|
||||
dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_minutes]
|
||||
```
|
||||
|
||||
| Parametri | Pakollinen | Kuvaus |
|
||||
|-----------|------------|--------|
|
||||
| `target_repo` | Kyllä | `owner/repo` |
|
||||
| `workflow_file` | Kyllä | Workflow-tiedoston nimi (esim. `test.yml`) |
|
||||
| `ref` | Kyllä | Branch |
|
||||
| `inputs_json` | Kyllä | JSON-objekti input-parametreina |
|
||||
| `gitea_api_url` | Kyllä | Gitean API-URL (esim. `https://gitea.example.com`) |
|
||||
| `gitea_token` | Kyllä | Gitea API -token |
|
||||
| `timeout_minutes` | Ei | Oletus: 360 (6 tuntia) |
|
||||
|
||||
### Toiminta
|
||||
|
||||
1. **Dispatch:** `POST /api/v1/repos/{target_repo}/actions/workflows/{workflow_file}/dispatches`
|
||||
2. **Etsi run:** `GET /api/v1/repos/{target_repo}/actions/runs?status=running` → etsi uusin (aikaleimasta)
|
||||
3. **Poll:** `GET /api/v1/repos/{target_repo}/actions/runs/{run_id}` 10s välein
|
||||
4. **Lopeta:** Kun `status == "completed"` → palauta `conclusion` (`success`/`failure`/`cancelled`)
|
||||
5. **Timeout:** Jos kestää yli `timeout_minutes` → palauta `timeout`
|
||||
|
||||
### Kutsuesimerkki
|
||||
|
||||
```bash
|
||||
dispatch-workflow.sh "tests/integration" "test.yml" "main" \
|
||||
'{"version":"1.2.3","tags":"@smoke","root_commit":"abc123","root_repo":"services/temperature-store"}' \
|
||||
"https://gitea.example.com" "gtp_abc123"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## `push-reports.sh` (vanhentunut — korvattu `publish-git-pages.sh`:lla)
|
||||
|
||||
Puskaa raporttihakemiston git-pagesiin.
|
||||
|
||||
### Rajapinta
|
||||
|
||||
```bash
|
||||
push-reports.sh <report_type> <source_dir> [index_title]
|
||||
```
|
||||
|
||||
| Parametri | Pakollinen | Kuvaus |
|
||||
|-----------|------------|--------|
|
||||
| `report_type` | Kyllä | Raportin tyyppi (`cucumber`, `jacoco`, `junit`, `site`) |
|
||||
| `source_dir` | Kyllä | Paikallinen hakemisto, jossa raporttitiedostot |
|
||||
| `index_title` | Ei | Näkyvä nimi indeksisivulla (esim. "Cucumber Reports") |
|
||||
|
||||
### Toiminta
|
||||
|
||||
1. Kopioi raportit: `mc cp --recursive {source_dir} minio/reports/{repo}/{commit_short}/{report_type}/`
|
||||
2. Päivitä `/reports/{repo}/{commit_short}/index.html` — lisää linkki tähän raporttiin
|
||||
3. Päivitä `/reports/{repo}/index.html` — varmista että tämä build on listalla
|
||||
4. Palauta URL: `{MINIO_BASE_URL}/{repo}/{commit_short}/{report_type}/index.html`
|
||||
|
||||
### Indeksisivut
|
||||
|
||||
**Projektin build-indeksi** (`/reports/{repo}/index.html`):
|
||||
- Lista buildeista aikajärjestyksessä (uusin ensin)
|
||||
- Jokainen rivi: commit hash (linkki), päivämäärä, status (✅/❌), branch
|
||||
|
||||
**Buildin raportti-indeksi** (`/reports/{repo}/{commit_short}/index.html`):
|
||||
- Lista raporteista linkkeinä
|
||||
- Linkki "← Back to builds" → projektin build-indeksiin
|
||||
|
||||
Molemmat generoidaan uudestaan jokaisen pushauksen yhteydessä. Staattinen HTML, ei vaadi palvelinpuolen logiikkaa.
|
||||
|
||||
### Kutsuesimerkki
|
||||
|
||||
```bash
|
||||
push-reports.sh cucumber target/cucumber-report "Cucumber Reports"
|
||||
# → https://reports.example.com/temperature-store/abc12345/cucumber/overview-features.html
|
||||
|
||||
push-reports.sh jacoco target/jacoco-report "JaCoCo Coverage"
|
||||
# → https://reports.example.com/temperature-store/abc12345/jacoco/index.html
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## `tag-commit.sh`
|
||||
|
||||
Tagittaa commitin versiolla Gitea REST API:n kautta.
|
||||
|
||||
### Rajapinta
|
||||
|
||||
```bash
|
||||
tag-commit.sh <version>
|
||||
```
|
||||
|
||||
### Toiminta
|
||||
|
||||
```bash
|
||||
curl -X POST "$GITEA_API_URL/api/v1/repos/$GITHUB_REPOSITORY/tags" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"tag_name\": \"$VERSION\",
|
||||
\"message\": \"Build #$GITHUB_RUN_NUMBER\",
|
||||
\"target\": \"$GITHUB_SHA\"
|
||||
}"
|
||||
```
|
||||
|
||||
### Kutsu
|
||||
|
||||
```bash
|
||||
tag-commit.sh "1.2.3.$GITHUB_RUN_NUMBER"
|
||||
```
|
||||
|
||||
Tagataan vain onnistuneen buildin ja pushin jälkeen. Tämän jälkeen `isContainerBuilt()` palauttaa `true` samalle commitille.
|
||||
2. **Poll:** `GET /api/v1/repos/{target_repo}/actions/runs` → odota valmistumista
|
||||
3. **Palauta:** `conclusion` (`success`/`failure`/`timeout`)
|
||||
|
||||
---
|
||||
|
||||
## Muuttujat, joita skriptit olettavat
|
||||
|
||||
Skriptit lukevat nämä Gitea Actionsin ympäristömuuttujat:
|
||||
|
||||
| Muuttuja | Lähde | Käyttäjä |
|
||||
|----------|-------|----------|
|
||||
| `GITEA_API_URL` | Org variable | `report-status.sh` |
|
||||
| `GITEA_TOKEN` | Org secret | `report-status.sh`, `tag-commit.sh` |
|
||||
| `MINIO_BASE_URL` | Org variable | `push-reports.sh` |
|
||||
| `MINIO_ACCESS_KEY` | Org secret | `push-reports.sh` |
|
||||
| `MINIO_SECRET_KEY` | Org secret | `push-reports.sh` |
|
||||
|---|---|---|
|
||||
| `GITEA_API_URL` | `env_json` | `report-status.sh`, `ci-validate.sh` |
|
||||
| `GIT_PAGES_URL` | `env_json` | `publish-git-pages.sh`, `report-status.sh` |
|
||||
| `GITEA_TOKEN` | Gitea secret | `report-status.sh`, `check-version.yml`, `docker-build-push.yml` |
|
||||
| `GIT_PAGES_PUBLISH_TOKEN` | Gitea secret | `publish-git-pages.sh` |
|
||||
| `GITHUB_REPOSITORY` | Automaattinen | Kaikki skriptit |
|
||||
| `GITHUB_SHA` | Automaattinen | Kaikki skriptit |
|
||||
| `GITHUB_SERVER_URL` | Automaattinen | `report-status.sh` |
|
||||
| `GITHUB_RUN_ID` | Automaattinen | `report-status.sh`, `tag-commit.sh` |
|
||||
| `GITHUB_RUN_NUMBER` | Automaattinen | `tag-commit.sh` |
|
||||
| `GITHUB_ACTOR` | Automaattinen | Docker-labelit |
|
||||
| `GITHUB_RUN_ID` | Automaattinen | `report-status.sh` |
|
||||
| `GITHUB_RUN_NUMBER` | Automaattinen | `docker-build-push.yml` (tag-commit) |
|
||||
|
||||
Reference in New Issue
Block a user