diff --git a/.gitea/workflows/build-feature.yml b/.gitea/workflows/build-feature.yml index 4a6ce87..34590f0 100644 --- a/.gitea/workflows/build-feature.yml +++ b/.gitea/workflows/build-feature.yml @@ -2,23 +2,26 @@ name: Build Feature on: workflow_call: inputs: + env_json: + required: true + type: string bats-image: - required: false + required: true type: string - default: bats/bats:latest cucumber-node-image: - required: false + required: true type: string - default: node:22 + +env: + GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }} + PAGES_HOST: ${{ fromJson(inputs.env_json).PAGES_HOST }} + GIT_PAGES_PUBLISH_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_PUBLISH_URL }} jobs: bats: runs-on: ubuntu-latest env: - GITEA_API_URL: https://gitea.app.keskikuja.site GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - PAGES_HOST: ci-reports.helm-dev.keskikuja.site - GIT_PAGES_PUBLISH_URL: https://ci-reports.helm-dev.keskikuja.site GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }} steps: - uses: actions/checkout@v4 @@ -80,10 +83,7 @@ jobs: container: image: ${{ inputs.cucumber-node-image }} env: - GITEA_API_URL: https://gitea.app.keskikuja.site GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - PAGES_HOST: ci-reports.helm-dev.keskikuja.site - GIT_PAGES_PUBLISH_URL: https://ci-reports.helm-dev.keskikuja.site GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }} steps: - uses: actions/checkout@v4 @@ -153,10 +153,7 @@ jobs: runs-on: ubuntu-latest needs: [bats, cucumber] env: - GITEA_API_URL: https://gitea.app.keskikuja.site GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - PAGES_HOST: ci-reports.helm-dev.keskikuja.site - GIT_PAGES_PUBLISH_URL: https://ci-reports.helm-dev.keskikuja.site GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }} steps: - uses: actions/checkout@v4 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 095b40c..95d3b40 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -5,16 +5,27 @@ on: workflow_dispatch: jobs: + load-config: + uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@plan/0003-alkaa-käyttämään-itseään-commit-raportti + with: + config_path: feature-env.conf + feature: if: github.ref != 'refs/heads/main' - uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@main + needs: [load-config] + uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@plan/0003-alkaa-käyttämään-itseään-commit-raportti secrets: inherit with: + env_json: ${{ needs.load-config.outputs.env_json }} bats-image: bats/bats:latest + cucumber-node-image: node:22 main: if: github.ref == 'refs/heads/main' - uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@main + needs: [load-config] + uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@plan/0003-alkaa-käyttämään-itseään-commit-raportti secrets: inherit with: + env_json: ${{ needs.load-config.outputs.env_json }} bats-image: bats/bats:latest + cucumber-node-image: node:22 diff --git a/.gitea/workflows/config-provider.yml b/.gitea/workflows/config-provider.yml new file mode 100644 index 0000000..af4ad80 --- /dev/null +++ b/.gitea/workflows/config-provider.yml @@ -0,0 +1,31 @@ +name: Config Provider Library +on: + workflow_call: + inputs: + config_path: + required: true + type: string + outputs: + env_json: + value: ${{ jobs.parse-config.outputs.json_data }} + +jobs: + parse-config: + runs-on: ubuntu-latest + outputs: + json_data: ${{ steps.convert.outputs.JSON_OUT }} + steps: + - uses: actions/checkout@v4 + + - id: convert + run: | + JSON_STRING=$(jq -R -s ' + split("\n") + | map(select(length > 0 and (startswith("#") | not))) + | map(split("=")) + | map({(.[0]): .[1]}) + | add + ' "${{ inputs.config_path }}") + + CLEAN_JSON=$(echo "$JSON_STRING" | jq -c .) + echo "JSON_OUT=$CLEAN_JSON" >> "$GITHUB_OUTPUT" diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 56d23f8..0000000 --- a/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -GITEA_API_URL: https://gitea.app.keskikuja.site -PAGES_HOST: ci-reports.helm-dev.keskikuja.site -GIT_PAGES_PUBLISH_URL: https://ci-reports.helm-dev.keskikuja.site diff --git a/docs/ci-pipeline-practices.md b/docs/ci-pipeline-practices.md index 5c05661..fafc881 100644 --- a/docs/ci-pipeline-practices.md +++ b/docs/ci-pipeline-practices.md @@ -50,6 +50,27 @@ Käytäntö: - Jos `docker run` tarvitsee env-arvoja, välitä ne eksplisiittisesti `-e VAR`-lipulla - `GITHUB_ENV` on validi tapa välittää arvoja stepien välille samassa jobissa, mutta ei leviä `docker run`-kontteihin ilman `-e`-lippua +### Cross-job config propagation (validated 2026-06-13) + +Workflow `env:` on ainoa natiivi mekanismi, joka tekee arvoista näkyviä kaikissa jobeissa automaattisesti. Ketju: + +``` +feature-env.conf → config-provider.yml → env_json (single JSON string output) + ↓ + ci.yml with: env_json + ↓ + build-feature.yml workflow env: + fromJson(inputs.env_json).KEY + ↓ + kaikki jobit → $KEY +``` + +Avainkomponentit: +- **config-provider.yml** — reusable workflow, lukee conf-tiedoston → yksi JSON output +- **`needs` + `with:`** — `jobs..with` tukee `needs`-kontekstia, joten `${{ needs.load-config.outputs.env_json }}` toimii +- **workflow `env:`** — ainoa tapa jakaa arvot kaikkiin jobeihin. `fromJson(inputs.env_json).KEY` purkaa yksittäiset arvot +- **Per-job `env:`** — sisältää vain secretit (`GITEA_TOKEN`, `GIT_PAGES_PUBLISH_TOKEN`), ei config-arvoja + ## 5. Pipeline Provides All Dependencies - Ei luottamusta runnerin esiasennettuihin työkaluihin diff --git a/feature-env.conf b/feature-env.conf new file mode 100644 index 0000000..3349d01 --- /dev/null +++ b/feature-env.conf @@ -0,0 +1,3 @@ +GITEA_API_URL=https://gitea.app.keskikuja.site +PAGES_HOST=ci-reports.helm-dev.keskikuja.site +GIT_PAGES_PUBLISH_URL=https://ci-reports.helm-dev.keskikuja.site