From fa4af7787723379d4c1ddcd49d77c4c1ff99b5d7 Mon Sep 17 00:00:00 2001 From: moilanik Date: Sat, 13 Jun 2026 15:18:02 +0300 Subject: [PATCH] feat: refactor config flow and directory structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create config-provider.yml (reusable workflow, conf→JSON) - Replace duplicated job env blocks with workflow env + fromJson - Move provider workflows to workflows/ directory - Move consumer scripts to .gitea/scripts/ - Move feature-env.conf to .gitea/workflows/ - Add bats-report.sh for TAP→HTML conversion - Update ci.yml with setup→needs→with pattern - Add ADR 0006 directory ownership - Document cross-job config propagation in ci-pipeline-practices.md - Remove config.yaml, scripts/load-config.sh unused --- .gitea/scripts/bats-report.sh | 36 +++++++++ .gitea/workflows/build-feature.yml | 12 +-- .gitea/workflows/ci.yml | 4 +- .../workflows/feature-env.conf | 0 docs/adr/0006-directory-ownership.md | 80 +++++++++++++++++++ {.gitea/workflows => workflows}/ci-engine.yml | 0 .../config-provider.yml | 0 7 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 .gitea/scripts/bats-report.sh rename feature-env.conf => .gitea/workflows/feature-env.conf (100%) create mode 100644 docs/adr/0006-directory-ownership.md rename {.gitea/workflows => workflows}/ci-engine.yml (100%) rename {.gitea/workflows => workflows}/config-provider.yml (100%) diff --git a/.gitea/scripts/bats-report.sh b/.gitea/scripts/bats-report.sh new file mode 100644 index 0000000..fbebbfb --- /dev/null +++ b/.gitea/scripts/bats-report.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail + +REPORT_DIR="${1:-reports/bats}" +INPUT="$REPORT_DIR/results.txt" +OUTPUT="$REPORT_DIR/index.html" + +[ -f "$INPUT" ] || { echo "ERROR: $INPUT not found" >&2; exit 1; } + +TOTAL=$(grep -cE '^(ok|not ok) ' "$INPUT" 2>/dev/null || echo 0) +PASS=$(grep -c '^ok ' "$INPUT" 2>/dev/null || echo 0) +FAIL=$((TOTAL - PASS)) + +{ + echo '' + echo "Bats test report ${GITHUB_SHA:0:8}" + echo '' + echo "

Bats test report ${GITHUB_SHA:0:8}

" + echo "

Total: ${TOTAL} | Passed: ${PASS} | Failed: ${FAIL}

" + echo '' + + while IFS=' ' read -r status num rest; do + case "$status" in + ok) echo "" ;; + not) echo "" ;; + esac + done < <(grep -E '^(ok|not ok) ' "$INPUT") + + echo '
#StatusTest
${num}PASS${rest}
${num}FAIL${rest}
' +} > "$OUTPUT" + +echo "$OUTPUT" diff --git a/.gitea/workflows/build-feature.yml b/.gitea/workflows/build-feature.yml index 34590f0..19b3144 100644 --- a/.gitea/workflows/build-feature.yml +++ b/.gitea/workflows/build-feature.yml @@ -45,15 +45,7 @@ jobs: > "reports/${GITHUB_SHA:0:8}/bats/results.txt" 2>&1 BATS_EXIT=$? docker volume rm bats-workspace > /dev/null 2>&1 - { - echo "

Bats tests

" - } > "reports/${GITHUB_SHA:0:8}/bats/index.html" + bash .ci/.gitea/scripts/bats-report.sh "reports/${GITHUB_SHA:0:8}/bats" echo "BATS_EXIT=${BATS_EXIT}" >> "${GITHUB_ENV}" exit ${BATS_EXIT} @@ -137,7 +129,7 @@ jobs: if [ "${TOOL_OK}" != "true" ]; then STATUS="failure" DESC="Cucumber tool unavailable" - URL="https://gitea.app.keskikuja.site/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" + URL="${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" elif [ "${CUCUMBER_EXIT}" = "0" ]; then STATUS="success" DESC="Cucumber tests passed" diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index b81e670..4d80a48 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -6,9 +6,9 @@ on: jobs: load-config: - uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@feature/pipeline-cleanup + uses: niko/gitea-ci-library/workflows/config-provider.yml@feature/pipeline-cleanup with: - config_path: feature-env.conf + config_path: .gitea/workflows/feature-env.conf feature: if: github.ref != 'refs/heads/main' diff --git a/feature-env.conf b/.gitea/workflows/feature-env.conf similarity index 100% rename from feature-env.conf rename to .gitea/workflows/feature-env.conf diff --git a/docs/adr/0006-directory-ownership.md b/docs/adr/0006-directory-ownership.md new file mode 100644 index 0000000..e124cb5 --- /dev/null +++ b/docs/adr/0006-directory-ownership.md @@ -0,0 +1,80 @@ +# 6. Directory ownership — provider vs consumer + +## Päätös + +Provider-repossa (`gitea-ci-library`) on seuraavat kansiot ja tiedostot, +joilla on eri omistajuus- ja näkyvyyssäännöt: + +| Kansio | Omistaja | Näkyvyys | Tyyppi | +|--------|----------|----------|--------| +| `workflows/` | Provider | Consumer kutsuu `uses:` | Reusable workflowt | +| `scripts/` | Provider | Vain providerin sisäinen | Bash-skriptit | +| `.gitea/workflows/` | Consumer | Consumerin oma pipeline | Pipeline-logiikka | +| `.gitea/scripts/` | Consumer | Consumerin oma | Consumer-skriptit | +| `.gitea/workflows/feature-env.conf` | Consumer | Consumerin konffi | KEY=VALUE config | + +## Perustelu + +### Providerin `workflows/` (juuressa) + +Providerin reusable workflow -tiedostot, joita consumer kutsuu +`uses:`-direktiivillä. Consumerilla on lukunäkyvyys mutta ei +muokkausvastuuta. Esimerkki: + +```yaml +uses: niko/gitea-ci-library/workflows/config-provider.yml@v1 +``` + +Tämä on providerin julkinen rajapinta. Sijainti `workflows/` (juuressa) +eikä `.gitea/workflows/` korostaa, että kyseessä on providerin tarjoama +palvelu, ei consumerin oma pipeline. + +### Providerin `scripts/` (juuressa) + +Providerin sisäiset työkalut. Consumer ei koskaan kutsu näitä suoraan — +vain providerin workflowt kutsuvat tupla checkoutin kautta: +`.ci/scripts/publish-git-pages.sh`. + +Consumerilla ei ole suoraa polkua näihin tiedostoihin — ne saavuttaa +vain providerin workflowjen kautta, jotka tupla checkouttaa providerin. + +### Consumerin `.gitea/workflows/` + +Consumerin oma pipeline-logiikka. Consumer omistaa ja muokkaa. +Provider ei koskaan ohita tätä kansiota — ADR 0005. + +Tässä repossa (dogfood) consumer on sama repo, joten `.gitea/workflows/` +näyttää providerin tiedostojen rinnalla. Arkkitehtuurisesti ne ovat +erillisiä: jos consumer olisi eri repo, `.gitea/workflows/` olisi siellä. + +### Consumerin `.gitea/scripts/` + +Consumerin omat skriptit, jotka ovat osa consumerin pipeline-logiikkaa. +Provider ei omista eikä ylläpidä näitä. + +Consumer-skriptit kutsutaan consumerin workflowista ilman tupla +checkouttia: `.gitea/scripts/bats-report.sh`. + +### Consumerin `.gitea/workflows/feature-env.conf` + +Consumerin konfiguraatiotiedosto consumerin omassa kansiossa. +Providerin `config-provider.yml` lukee tämän ja muuntaa JSONiksi, mutta +consumer omistaa sisällön. + +## Vaikutukset + +- Provider voi muuttaa `workflows/` ja `scripts/` -kansioiden sisältöä + ilman consumerin hyväksyntää (versiovaihdon yhteydessä) +- Consumer voi muuttaa `.gitea/workflows/` ja `.gitea/scripts/` -kansioiden + sisältöä ilman providerin muutoksia +- Providerin workflowt käyttävät `.ci/scripts/...` -polkua (tupla checkout) +- Consumerin workflowt käyttävät `.gitea/scripts/...` -polkua (natiivi checkout) +- Config-tiedoston muoto on consumerin päätettävissä — provider vain lukee + +## Vertailu vanhaan rakenteeseen + +| Entinen sijainti | Uusi sijainti | Peruste | +|------------------|---------------|---------| +| `.gitea/workflows/config-provider.yml` | `workflows/config-provider.yml` | Providerin julkinen rajapinta pois consumer-kansiosta | +| `.gitea/workflows/ci-engine.yml` | `workflows/ci-engine.yml` | Sama peruste | +| `scripts/bats-report.sh` | `.gitea/scripts/bats-report.sh` | Consumerin oma skripti | diff --git a/.gitea/workflows/ci-engine.yml b/workflows/ci-engine.yml similarity index 100% rename from .gitea/workflows/ci-engine.yml rename to workflows/ci-engine.yml diff --git a/.gitea/workflows/config-provider.yml b/workflows/config-provider.yml similarity index 100% rename from .gitea/workflows/config-provider.yml rename to workflows/config-provider.yml