Compare commits
3 Commits
0.2.20
..
a039e6637e
| Author | SHA1 | Date | |
|---|---|---|---|
| a039e6637e | |||
| 0a9a9c88f1 | |||
| bfd0428a78 |
@@ -1,20 +0,0 @@
|
||||
.git/
|
||||
.gitignore
|
||||
node_modules/
|
||||
reports/
|
||||
coverage/
|
||||
.ai/
|
||||
.cursor/
|
||||
.vscode/
|
||||
tmp/
|
||||
.DS_Store
|
||||
*.md
|
||||
docs/
|
||||
guides/
|
||||
.simplecov
|
||||
cucumber.js
|
||||
package-lock.json
|
||||
package.json
|
||||
CURRENT_PROVIDER_VERSION
|
||||
README.md
|
||||
AGENTS.md
|
||||
@@ -41,14 +41,12 @@ jobs:
|
||||
TAG="${{ inputs.tag }}"
|
||||
|
||||
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
CONTEXT_DIR=$(dirname "${DOCKERFILE}")
|
||||
docker build \
|
||||
--label "git.commit=${{ github.sha }}" \
|
||||
--label "git.commitBy=${{ github.actor }}" \
|
||||
--label "build.date=${NOW}" \
|
||||
-f "${DOCKERFILE}" \
|
||||
-t "${IMAGE_NAME}:${TAG}" \
|
||||
"${CONTEXT_DIR}"
|
||||
-t "${IMAGE_NAME}:${TAG}" .
|
||||
|
||||
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${TAG}"
|
||||
echo "Pushing ${FULL_IMAGE} ..."
|
||||
|
||||
@@ -52,15 +52,13 @@ jobs:
|
||||
REGISTRY_HOST="${REGISTRY%%/*}"
|
||||
|
||||
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
CONTEXT_DIR=$(dirname "${DOCKERFILE}")
|
||||
docker build \
|
||||
--label "git.commit=${{ github.sha }}" \
|
||||
--label "git.commitBy=${{ github.actor }}" \
|
||||
--label "build.date=${NOW}" \
|
||||
-f "${DOCKERFILE}" \
|
||||
-t "${IMAGE}:${VERSION}" \
|
||||
-t "${IMAGE}:latest" \
|
||||
"${CONTEXT_DIR}"
|
||||
-t "${IMAGE}:latest" .
|
||||
|
||||
FULL_IMAGE="${REGISTRY}/${IMAGE}:${VERSION}"
|
||||
echo "Pushing ${FULL_IMAGE} ..."
|
||||
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
cucumber-node-image:
|
||||
required: false
|
||||
type: string
|
||||
default: gitea.app.keskikuja.site/niko/ci-cucumber:with-python
|
||||
default: gitea.app.keskikuja.site/niko/ci-cucumber:latest
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
|
||||
@@ -8,6 +8,10 @@ on:
|
||||
version:
|
||||
required: true
|
||||
type: string
|
||||
chart_path:
|
||||
required: false
|
||||
type: string
|
||||
default: '.'
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
@@ -22,7 +26,7 @@ env:
|
||||
HELM_REGISTRY: ${{ fromJson(inputs.env_json).HELM_REGISTRY || '' }}
|
||||
HELM_UI_URL: ${{ fromJson(inputs.env_json).HELM_UI_URL || '' }}
|
||||
GIT_TAG_PREFIX: ${{ fromJson(inputs.env_json).GIT_TAG_PREFIX || '' }}
|
||||
CHART_FILE: ${{ fromJson(inputs.env_json).VERSION_FILE || 'Chart.yaml' }}
|
||||
CHART_PATH: ${{ inputs.chart_path }}
|
||||
VERSION: ${{ inputs.version }}
|
||||
|
||||
concurrency:
|
||||
@@ -49,9 +53,8 @@ jobs:
|
||||
|
||||
- name: Package Helm chart
|
||||
run: |
|
||||
CHART_DIR=$(dirname "${CHART_FILE}")
|
||||
helm dependency update "${CHART_DIR}"
|
||||
helm package "${CHART_DIR}" \
|
||||
helm dependency update "${CHART_PATH}"
|
||||
helm package "${CHART_PATH}" \
|
||||
--version "${VERSION}" \
|
||||
--app-version "${VERSION}" \
|
||||
--destination /tmp/helm-packages
|
||||
@@ -71,7 +74,7 @@ jobs:
|
||||
- name: Report status with UI link
|
||||
if: success() && env.HELM_UI_URL != ''
|
||||
run: |
|
||||
CHART_NAME=$(grep '^name:' "${CHART_FILE}" | awk '{print $2}')
|
||||
CHART_NAME=$(grep '^name:' "${CHART_PATH}/Chart.yaml" | awk '{print $2}')
|
||||
UI_URL="${HELM_UI_URL}/${CHART_NAME}/${VERSION}"
|
||||
bash .ci/scripts/report-status.sh success "Helm chart ${VERSION}" ci-helm-build-push "" "$UI_URL"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FROM node:22
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -y -qq --no-install-recommends lsof jq python3 && \
|
||||
apt-get install -y -qq --no-install-recommends lsof jq && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
npm install -g @cucumber/cucumber
|
||||
|
||||
+1
-2
@@ -37,7 +37,7 @@ kuuluu `git-pages/docs/`-alle, ei juuren `docs/`-kansioon.
|
||||
| `git-pages/` | Raporttien hostaus (Helm-chartti) |
|
||||
| `tests/` | Bats-testit skripteille |
|
||||
|
||||
### Provider workflowt (6 kpl)
|
||||
### Provider workflowt (5 kpl)
|
||||
|
||||
| Workflow | Input | Output | Kuvaus |
|
||||
|---|---|---|---|
|
||||
@@ -46,7 +46,6 @@ kuuluu `git-pages/docs/`-alle, ei juuren `docs/`-kansioon.
|
||||
| `docker-build-push.yml` | `env_json`, `version` | — | Buildaa Docker-imagen, puskea rekisteriin, tagittaa commitin. |
|
||||
| `ci-container-build-push.yml` | `env_json`, `dockerfile_path`, `image_name`, `tag` | — | Buildaa CI-työkalukontin, puskea rekisteriin. Ei versiointia eikä git-tägäystä. |
|
||||
| `report-summary.yml` | `env_json`, `suites` | — | Generoi `GITHUB_STEP_SUMMARY`-taulukon raporttilinkeillä (Gitea 1.27+) |
|
||||
| `helm-build-push.yml` | `env_json`, `version` | — | Pakkaa + puskea Helm chartin OCI-registryyn, tagittaa commitin. **Tekninen velka:** asentaa node.js:n runtime-vaiheessa (`apk add --no-cache nodejs` ennen checkouttia) koska `alpine/helm`-kontissa ei ole nodea. Rikkoo Offline Container -periaatetta. Ratkaistaan myöhemmin: proper multi-tool CI-kontti (helm + nodejs + git) docker hubiin. Ei consumerin ongelma. |
|
||||
|
||||
### Example-tiedostot (consumer-referenssi)
|
||||
|
||||
|
||||
@@ -182,42 +182,6 @@ vain build-vaiheessa — `apk del curl` poistaa työkalun ennen runtimea.
|
||||
Tapa C pre-cacheaa kielikohtaiset riippuvuudet ja tuottaa täysin
|
||||
offline-runtime-kontin.
|
||||
|
||||
## Testaus ennen julkaisua
|
||||
|
||||
Konttia ei saa pushata registryyn ennen kuin se on validoitu.
|
||||
|
||||
### 1. Aja testit kontin sisällä
|
||||
|
||||
Testit on ajettava **kontin sisällä**, ei suoraan lokaalilla koneella.
|
||||
|
||||
```bash
|
||||
# OIKEIN — kontin sisällä
|
||||
docker build -t ci-tyokalu:test .
|
||||
docker run --rm -v "$(pwd):/repo" -w /repo ci-tyokalu:test bash -c 'bats tests/'
|
||||
|
||||
# VÄÄRIN — lokaalit binäärit vs kontti
|
||||
bats tests/ # eri bash/työkalut kuin kontissa
|
||||
bashcov -- bats tests/ # eri ruby-versio kuin kontissa
|
||||
```
|
||||
|
||||
Lokaali ympäristö (macOS, eri kirjastoversiot) poikkeaa aina kontista.
|
||||
Testi voi mennä läpi lokaalissa mutta failata CI:ssä, tai päinvastoin.
|
||||
|
||||
### 2. Fragile-testien seulonta (10x ajo)
|
||||
|
||||
Aja koko testipaketti **10 kertaa peräkkäin** kontin sisällä ennen pushausta:
|
||||
|
||||
```bash
|
||||
for i in $(seq 1 10); do
|
||||
echo "=== RUN $i ==="
|
||||
docker run --rm -v "$(pwd):/repo" -w /repo ci-tyokalu:test \
|
||||
bash -c 'bats tests/' || exit 1
|
||||
done
|
||||
```
|
||||
|
||||
Jos yksikin ajo failaa, kontissa on fragile testi — korjaa ennen pushausta.
|
||||
Fragile testit syövät devaukseen käytettyä aikaa turhilla uusinta-ajoilla.
|
||||
|
||||
## Mitä EI kannata tehdä
|
||||
|
||||
- Älä lisää `workflow_call`-triggariä — CI-konttia ei koskaan buildata automaattisesti
|
||||
|
||||
@@ -123,88 +123,6 @@ ajetaan kontin *sisällä* — myös `actions/checkout@v4`. Se on JavaScript-act
|
||||
joka vaatii sekä `nodejs` että `git`. Varmista että CI-kontin Dockerfilessä on
|
||||
molemmat — muuten checkout ei toimi ja pipeline failaa.
|
||||
|
||||
### 4.4 Build-konteksti, `.dockerignore` ja `COPY`
|
||||
|
||||
**Build-konteksti** on aina tiedoston (Dockerfile, Chart.yaml) oman hakemiston
|
||||
juuri (`dirname "${DOCKERFILE}"` / `dirname "${CHART_FILE}"`). Kaikki
|
||||
suhteelliset polut — ignore-tiedosto, `COPY`, `ADD` — ovat suhteessa tähän
|
||||
kontekstiin.
|
||||
|
||||
| Tiedosto | Konteksti | Ignore-tiedosto | Käyttö |
|
||||
|---|---|---|---|
|
||||
| `Dockerfile` | `.` | `./.dockerignore` | `docker build` / `COPY src/ src/` |
|
||||
| `api/Dockerfile` | `api/` | `api/.dockerignore` | `docker build` / `COPY src/ src/` |
|
||||
| `Chart.yaml` (`VERSION_FILE`) | `.` | `./.helmignore` | `helm package` |
|
||||
| `api/Chart.yaml` (`VERSION_FILE`) | `api/` | `api/.helmignore` | `helm package` |
|
||||
|
||||
Helm chartin polku luetaan confin `VERSION_FILE`-kentästä — sama rivi jota
|
||||
`check-version.yml` käyttää version lähteenä. Yksi conf-rivi ohjaa molempia:
|
||||
sekä versionlaskentaa että chartin sijaintia.
|
||||
|
||||
**Mitä ignore-tiedosto sisältää:** Kaikki mikä EI ole konttiin tai chart-pakettiin
|
||||
tarkoitettua koodia tai resurssia, ON oltava ignore-tiedostossa:
|
||||
|
||||
- Git- ja CI-historia (`.git/`, `.gitea/`, `.github/`)
|
||||
- Testikoodi, testidata, testiraportit (`tests/`, `reports/`, `coverage/`)
|
||||
- Dokumentaatio (`docs/`, `guides/`, `*.md`, `CHANGELOG`, `README`)
|
||||
- Editori- ja työkalukonfiguraatio (`.vscode/`, `.cursor/`, `.idea/`, `.DS_Store`)
|
||||
- Riippuvuudet jotka asennetaan Dockerfilessä (`node_modules/`)
|
||||
- Väliaikaistiedostot (`tmp/`, `*.log`)
|
||||
- Projektikohtaiset konfiguraatiot (`.env`, `*.conf`, `CURRENT_PROVIDER_VERSION`)
|
||||
|
||||
**Miksi:** Build-kontekstin koko vaikuttaa suoraan `docker build` -nopeuteen.
|
||||
Raskas konteksti (etenkin `.git/` ja `node_modules/`) hidastaa buildia ja
|
||||
kuluttaa runnerin resursseja turhaan. Ylimääräiset tiedostot kontissa ovat
|
||||
**tietoturvariski** — tokenit, `.env` ja sensitiivinen data voivat päätyä
|
||||
kontin layeriin jos `.dockerignore` ei ole kattava.
|
||||
|
||||
### 4.5 `COPY`-kuri — kopioi vain tarvittava
|
||||
|
||||
`COPY . .` on kielletty. Jokainen `COPY` kopioi vain tarvittavat tiedostot
|
||||
tai hakemistot:
|
||||
|
||||
```dockerfile
|
||||
# VÄÄRIN
|
||||
COPY . .
|
||||
|
||||
# OIKEIN
|
||||
COPY package.json package-lock.json ./
|
||||
COPY src/ src/
|
||||
COPY public/ public/
|
||||
```
|
||||
|
||||
**Miksi:**
|
||||
- Layer-cache: `COPY . .` rikkoo välimuistin — mikä tahansa muutos
|
||||
tiedostossa tyhjentää koko layerin
|
||||
- Tietoturva: konttiin voi päätyä ylimääräisiä tiedostoja vaikka
|
||||
`.dockerignore` olisi kattava (unohtunut ignore-rivi, uusi työkalu
|
||||
joka luo tiedostoja build-kontekstiin)
|
||||
- Luettavuus: `COPY . .` ei kerro mitä kontti todella sisältää
|
||||
- Kontin koko: eksplisiittinen `COPY` pitää image-koon kurissa
|
||||
|
||||
### 4.6 `.helmignore` — pidä chart-paketti siistinä
|
||||
|
||||
`helm package` käyttää `.helmignore`-tiedostoa samalla periaatteella kuin
|
||||
`docker build` käyttää `.dockerignore`a:
|
||||
|
||||
- Chart-hakemisto luetaan confin `VERSION_FILE`-kentästä (`dirname "${VERSION_FILE}"`)
|
||||
- ignore-tiedosto luetaan chart-hakemiston juuresta (sama konteksti kuin
|
||||
`Chart.yaml`, ks. 4.4)
|
||||
- Kaikki turha (testit, docs, git, CI-konffit, kuvat) on poissuljettava
|
||||
- Jos `.helmignore` puuttuu, `helm package` paketoi mukaan kaikki
|
||||
chart-hakemiston tiedostot — turhaa bulkkia registryyn
|
||||
|
||||
**`.helmignore` on pakollinen** jokaiselle chartille. Minimisisältö:
|
||||
|
||||
```
|
||||
.git/
|
||||
.gitignore
|
||||
tests/
|
||||
docs/
|
||||
*.md
|
||||
.DS_Store
|
||||
```
|
||||
|
||||
## 5. Raporttitasot
|
||||
|
||||
Testi tuottaa raportin `reports/<suite>/`-hakemistoon. Yksi `ci-report.sh`-kutsu hoitaa sekä
|
||||
@@ -339,7 +257,6 @@ Pakkaa ja pushee Helm-chartin OCI-registryyn. Käyttää `alpine/helm`-konttia.
|
||||
|
||||
```yaml
|
||||
HELM_REGISTRY: gitea.app.keskikuja.site/niko
|
||||
VERSION_FILE: platform-helm/Chart.yaml # chart-hakemisto + versionlähde
|
||||
```
|
||||
|
||||
**Käyttö reitittimessä:**
|
||||
@@ -353,163 +270,20 @@ helm-build-push:
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
# chart_path: '.' # oletus, vaihda jos Chart.yaml on alihakemistossa
|
||||
```
|
||||
|
||||
Chart-hakemisto johdetaan `VERSION_FILE`-polusta: `dirname "${VERSION_FILE}"`.
|
||||
Jos `VERSION_FILE` on `Chart.yaml`, konteksti on juuri. Jos `platform-helm/Chart.yaml`,
|
||||
konteksti on `platform-helm/`.
|
||||
**Vanhentunut käytäntö:** Nykyinen `helm-build-push.yml` asentaa node.js:n
|
||||
lennossa `apk add --no-cache nodejs` ennen checkouttia — tämä rikkoo
|
||||
Offline Container -vaatimusta (4.1).
|
||||
|
||||
**Korjaustoimenpide:** Rakenna custom CI-kontti `ci-container-build`-skillillä
|
||||
jossa on helm + nodejs + git (katso pre-cache-esimerkit `REFERENCE.md`:stä),
|
||||
päivitä workflow'n `container: image:` osoittamaan omaan konttiin, ja poista
|
||||
runtime-apk.
|
||||
|
||||
**Yksittäisten Helm-UI-linkkien raportointi:** `HELM_UI_URL` on
|
||||
tarkoitettu yleiselle registry UI:lle — provider muodostaa linkin
|
||||
`${HELM_UI_URL}/${CHART_NAME}/${VERSION}` automaattisesti.
|
||||
|
||||
Tarkka input/secret-lista: `docs/workflows.md`.
|
||||
|
||||
## 11. Multi-artifact monorepo -komponentti
|
||||
|
||||
Yksi monorepo-komponentti voi tuottaa useita artefakteja (esim. Docker image
|
||||
+ Helm chart). Kukin artefakti on **omassa reitittimessään** — ei yhtä
|
||||
monoliittista pipelinea. Tämä on tietoinen arkkitehtuurivalinta:
|
||||
|
||||
- Reitittimet ovat itsenäisiä: eri `paths:`-triggerit, eri tagit, eri confit
|
||||
- Yksi commit voi triggeröidä molemmat rinnakkain
|
||||
- Yhden artefaktin build tai testi ei estä toista
|
||||
|
||||
### Esimerkki: `platform-helm` joka tuottaa Docker-imagen ja Helm chartin
|
||||
|
||||
```
|
||||
.gitea/workflows/
|
||||
├── platform-helm.ci-main.yml # Docker build & push
|
||||
├── platform-helm.gitea-env.conf # Docker-konffi
|
||||
├── platform-helm.helm-ci-main.yml # Helm build & push
|
||||
├── platform-helm.helm-gitea-env.conf # Helm-konffi
|
||||
├── platform-helm.helm-chart-lint.yml # Chart-testi
|
||||
└── platform-helm.ci-container-build-helm.yml # CI-kontin build
|
||||
```
|
||||
|
||||
### `platform-helm.gitea-env.conf` (Docker)
|
||||
|
||||
```ini
|
||||
DOCKER_REGISTRY=gitea.app.keskikuja.site/niko
|
||||
DOCKER_IMAGE_NAME=platform-helm
|
||||
GIT_TAG_PREFIX=platform-helm/
|
||||
```
|
||||
|
||||
### `platform-helm.helm-gitea-env.conf` (Helm)
|
||||
|
||||
```ini
|
||||
HELM_REGISTRY=gitea.app.keskikuja.site/niko
|
||||
VERSION_FILE=platform-helm/Chart.yaml
|
||||
GIT_TAG_PREFIX=chart/
|
||||
```
|
||||
|
||||
### Reitittimet
|
||||
|
||||
**`platform-helm.ci-main.yml`** — Docker-buildi, testit, oma tagi:
|
||||
|
||||
```yaml
|
||||
name: platform-helm CI Main
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- platform-helm/**
|
||||
- .gitea/workflows/platform-helm.*
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/config-provider.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
config_path: .gitea/workflows/platform-helm.gitea-env.conf
|
||||
|
||||
check-version:
|
||||
needs: [load-config]
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/check-version.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
test:
|
||||
needs: [load-config, check-version]
|
||||
uses: ./.gitea/workflows/platform-helm.sbom-lint.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
build-push:
|
||||
needs: [load-config, check-version, test]
|
||||
if: needs.check-version.outputs.artifact_exists == 'false'
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/docker-build-push.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
|
||||
report-summary:
|
||||
needs: [load-config, test, build-push]
|
||||
if: always()
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/report-summary.yml@v1
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
suites: ''
|
||||
```
|
||||
|
||||
**`platform-helm.helm-ci-main.yml`** — Helm-buildi, chart-testi, oma tagi:
|
||||
|
||||
```yaml
|
||||
name: platform-helm Helm CI Main
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- platform-helm/**
|
||||
- .gitea/workflows/platform-helm.helm*
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/config-provider.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
config_path: .gitea/workflows/platform-helm.helm-gitea-env.conf
|
||||
|
||||
check-version:
|
||||
needs: [load-config]
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/check-version.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
chart-lint:
|
||||
needs: [load-config, check-version]
|
||||
uses: ./.gitea/workflows/platform-helm.helm-chart-lint.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
helm-build-push:
|
||||
needs: [load-config, check-version, chart-lint]
|
||||
if: needs.check-version.outputs.artifact_exists == 'false'
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/helm-build-push.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
|
||||
report-summary:
|
||||
needs: [load-config, chart-lint, helm-build-push]
|
||||
if: always()
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/report-summary.yml@v1
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
suites: ''
|
||||
```
|
||||
|
||||
### Säännöt
|
||||
|
||||
- Jokaisella artefaktilla on oma reititin, oma conf, omat testit
|
||||
- Conf-tiedoston nimi erottaa artefaktit: `<komponentti>.gitea-env.conf` vs
|
||||
`<komponentti>.helm-gitea-env.conf`
|
||||
- `<komponentti>.helm-`-prefiksi erottaa Helm-artefaktin tiedostot
|
||||
- `GIT_TAG_PREFIX` pitää tagit erillään: `platform-helm/1.2.3` vs `chart/1.2.3`
|
||||
- Molemmat reitittimet voivat triggeröityä samasta commitista
|
||||
|
||||
@@ -5,7 +5,6 @@ source "$BATS_TEST_DIRNAME/helpers/mock-api.sh"
|
||||
setup() {
|
||||
export GITEA_TOKEN=test-token
|
||||
export GIT_TAG_PREFIX=""
|
||||
export SERVER_URL="http://localhost:18080"
|
||||
export REPO="niko/test"
|
||||
export SHA="abc123"
|
||||
rm -rf /tmp/build-ctx
|
||||
|
||||
@@ -19,7 +19,7 @@ teardown() {
|
||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ teardown() {
|
||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ teardown() {
|
||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ teardown() {
|
||||
{"code":200,"body":{"id":1,"status":"running"}}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" "0.001"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123" "0.001"
|
||||
[ "$status" -eq 124 ]
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ teardown() {
|
||||
{"code":500}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ teardown() {
|
||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_first_request_path)
|
||||
[[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]]
|
||||
@@ -126,7 +126,7 @@ teardown() {
|
||||
{"code":200,"body":{"workflow_runs":[]}}
|
||||
]'
|
||||
mock_start
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{}' "http://localhost:18080" "test-token-abc123"
|
||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{}' "$GITEA_API_URL" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"ERROR"* ]]
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
MOCK_PORT=18080
|
||||
MOCK_PORT=""
|
||||
MOCK_PID=""
|
||||
MOCK_REQUEST_FILE=""
|
||||
MOCK_RESPONSE_CODE=201
|
||||
@@ -9,13 +9,17 @@ MOCK_STATE_FILE="/tmp/mock_api_state"
|
||||
MOCK_SEQUENCE_FILE=""
|
||||
MOCK_CONFIG_FILE=""
|
||||
|
||||
_free_port() {
|
||||
python3 -c "import socket; s=socket.socket(); s.bind(('',0)); print(s.getsockname()[1]); s.close()"
|
||||
}
|
||||
|
||||
_kill_port() {
|
||||
local pids
|
||||
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 $pids 2>/dev/null || true
|
||||
sleep 0.5
|
||||
fi
|
||||
[ -n "$pids" ] && kill $pids 2>/dev/null || true
|
||||
sleep 0.5
|
||||
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
|
||||
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true
|
||||
}
|
||||
|
||||
_wait_port_free() {
|
||||
@@ -28,10 +32,14 @@ _wait_port_free() {
|
||||
|
||||
_wait_port_ready() {
|
||||
local i=0
|
||||
while ! lsof -ti ":$MOCK_PORT" >/dev/null 2>&1 && [ $i -lt 30 ]; do
|
||||
while [ $i -lt 50 ]; do
|
||||
if nc -z localhost "$MOCK_PORT" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.2
|
||||
i=$((i + 1))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
mock_set_sequence() {
|
||||
@@ -45,6 +53,12 @@ mock_clear_sequence() {
|
||||
}
|
||||
|
||||
mock_start() {
|
||||
MOCK_PORT=$(_free_port)
|
||||
export MOCK_PORT
|
||||
MOCK_URL="http://localhost:${MOCK_PORT}"
|
||||
export SERVER_URL="$MOCK_URL"
|
||||
export GITEA_API_URL="$MOCK_URL"
|
||||
|
||||
MOCK_RESPONSE_CODE="${MOCK_RESPONSE_CODE:-201}"
|
||||
MOCK_REQUEST_FILE=$(mktemp)
|
||||
echo "$MOCK_REQUEST_FILE" > "$MOCK_STATE_FILE"
|
||||
|
||||
@@ -63,9 +63,10 @@ teardown() {
|
||||
{"code":200,"body":"published"}
|
||||
]'
|
||||
mock_start
|
||||
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
|
||||
run bash scripts/publish-git-pages.sh "unit-tests"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == "http://localhost:18080/test-owner/test-repo/reports/abc123de" ]]
|
||||
[[ "$output" == "${GIT_PAGES_URL}/test-owner/test-repo/reports/abc123de" ]]
|
||||
}
|
||||
|
||||
@test "publish with suite subpath" {
|
||||
@@ -75,9 +76,10 @@ teardown() {
|
||||
{"code":200,"body":"published"}
|
||||
]'
|
||||
mock_start
|
||||
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
|
||||
run bash scripts/publish-git-pages.sh "sub/suite"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == "http://localhost:18080/test-owner/test-repo/reports/abc123de" ]]
|
||||
[[ "$output" == "${GIT_PAGES_URL}/test-owner/test-repo/reports/abc123de" ]]
|
||||
}
|
||||
|
||||
@test "git-pages returns HTTP 500 → exit 1" {
|
||||
@@ -85,6 +87,7 @@ teardown() {
|
||||
{"code":500,"body":"internal error"}
|
||||
]'
|
||||
mock_start
|
||||
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
|
||||
run bash scripts/publish-git-pages.sh "unit-tests"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"500"* ]]
|
||||
|
||||
@@ -23,7 +23,8 @@ teardown() {
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"pending"'* ]]
|
||||
[[ "$body" == *'"description":"Building project"'* ]]
|
||||
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]]
|
||||
expected_url="${GITEA_API_URL}/test-owner/test-repo/actions/runs/42"
|
||||
[[ "$body" == *"\"target_url\":\"${expected_url}\""* ]]
|
||||
method=$(mock_get_request_method)
|
||||
[[ "$method" == "POST" ]]
|
||||
}
|
||||
@@ -44,7 +45,8 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"failure"'* ]]
|
||||
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]]
|
||||
expected_url="${GITEA_API_URL}/test-owner/test-repo/actions/runs/42"
|
||||
[[ "$body" == *"\"target_url\":\"${expected_url}\""* ]]
|
||||
}
|
||||
|
||||
@test "default key when not provided" {
|
||||
|
||||
Reference in New Issue
Block a user