Compare commits
2 Commits
bfd0428a78
...
a039e6637e
| Author | SHA1 | Date | |
|---|---|---|---|
| a039e6637e | |||
| 0a9a9c88f1 |
@@ -32,6 +32,31 @@ Kun kontti on pushattu registryyn, se on muiden pipeline-jobien käytettävissä
|
|||||||
`latest`-tägillä — rebuild = käyttöönotto. Mitään versioviittauksia ei tarvitse
|
`latest`-tägillä — rebuild = käyttöönotto. Mitään versioviittauksia ei tarvitse
|
||||||
päivittää.
|
päivittää.
|
||||||
|
|
||||||
|
## Offline-periaate (DoD)
|
||||||
|
|
||||||
|
CI-kontin **Definition of Done**:
|
||||||
|
|
||||||
|
> Kontti ei lataa mitään pipeline-vaiheessa (`workflow run` -stepit) eikä kontin
|
||||||
|
> runtime-prosessissa (`container:` / `docker run`). Kaikki riippuvuudet
|
||||||
|
> (kielikohtaiset paketit, työkalut, binäärit) on joko:
|
||||||
|
> - Pre-cachattu kontin **build-vaiheessa** Dockerfilessä, TAI
|
||||||
|
> - Kopioitu multi-stage buildilla toisesta imagesta (`COPY --from`)
|
||||||
|
>
|
||||||
|
> Ainoa sallittu lataushetki on `docker build`. Sen jälkeen kontti toimii
|
||||||
|
> ilman verkkoyhteyttä.
|
||||||
|
|
||||||
|
**Miksi:** Toistettavuus, air gap -yhteensopivuus, nopeus. Pipeline ei saa
|
||||||
|
epäonnistua sen takia että ulkoinen registry on alhaalla tai että `go mod download`
|
||||||
|
joutuu latamaan 100 modulia jokaisella testiajolla.
|
||||||
|
|
||||||
|
**Kielikohtaiset pre-cachet:** Jos kontissa ajetaan kielikohtaista testiä
|
||||||
|
(Go, Java, Node, Python, ...), kaikki kielikohtaiset riippuvuudet on
|
||||||
|
pre-cachattava Dockerfilessä build-vaiheessa:
|
||||||
|
- Go: `COPY go.mod go.sum ./` → `RUN go mod download`
|
||||||
|
- Java/Maven: `COPY pom.xml ./` → `RUN mvn dependency:go-offline`
|
||||||
|
- Node: `COPY package.json package-lock.json ./` → `RUN npm ci --omit=dev`
|
||||||
|
- Python: `COPY requirements.txt ./` → `RUN pip wheel --wheel-dir=/wheels -r requirements.txt` → `COPY --from` käyttöön
|
||||||
|
|
||||||
## Nimeäminen
|
## Nimeäminen
|
||||||
|
|
||||||
CI-kontin build-workflow noudattaa samaa nimeämiskonventiota kuin muutkin
|
CI-kontin build-workflow noudattaa samaa nimeämiskonventiota kuin muutkin
|
||||||
@@ -123,27 +148,44 @@ tag: latest
|
|||||||
|
|
||||||
### Dockerfile
|
### Dockerfile
|
||||||
|
|
||||||
Dockerfile yhdistää tarvitut työkalut yhteen konttiin. Molemmat tavat kelpaavat:
|
Dockerfile yhdistää tarvitut työkalut yhteen konttiin.
|
||||||
|
**Kaikki riippuvuudet ladataan build-vaiheessa — kontti on täysin itseriittoinen.**
|
||||||
|
|
||||||
```dockerfile
|
```dockerfile
|
||||||
# Tapa A: COPY --from toisesta imagesta
|
# Tapa A: COPY --from toisesta imagesta
|
||||||
FROM __BASE_IMAGE__:__VERSION__
|
FROM __BASE_IMAGE__:__VERSION__
|
||||||
COPY --from=__SOURCE_IMAGE__:__VERSION__ /path/to/binary /usr/local/bin/
|
COPY --from=__SOURCE_IMAGE__:__VERSION__ /path/to/binary /usr/local/bin/
|
||||||
RUN apk add --no-cache __PAKETIT__ # Ei koskaan git:iä — kloonaus kuuluu pipelinelle
|
RUN apk add --no-cache __PAKETIT__
|
||||||
|
|
||||||
# Tapa B: curl-lataus (normaali Dockerfilessa)
|
# Tapa B: Build-vaiheen curl-lataus
|
||||||
FROM __BASE_IMAGE__:__VERSION__
|
FROM __BASE_IMAGE__:__VERSION__
|
||||||
RUN apk add --no-cache curl __PAKETIT__ && \
|
RUN apk add --no-cache curl __PAKETIT__ && \
|
||||||
curl -fsSL __URL__/__BINARY__.tar.gz | tar xz -C /usr/local/bin && \
|
curl -fsSL __URL__/__BINARY__.tar.gz | tar xz -C /usr/local/bin && \
|
||||||
apk del curl
|
apk del curl
|
||||||
|
|
||||||
|
# Tapa C: Multi-stage + kielikohtainen pre-cache
|
||||||
|
FROM __BASE_IMAGE__:__VERSION__ AS deps
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
FROM deps AS build
|
||||||
|
COPY . .
|
||||||
|
RUN go test -c -o /tmp/test.bin ./...
|
||||||
|
|
||||||
|
FROM __BASE_IMAGE__:__VERSION__
|
||||||
|
COPY --from=deps /go/pkg/mod /go/pkg/mod
|
||||||
|
COPY --from=build /tmp/test.bin /usr/local/bin/test
|
||||||
```
|
```
|
||||||
|
|
||||||
`COPY --from` on kevyempi (ei curl-asennusta). `curl` on selkeämpi kun binääri
|
`COPY --from` on kevyempi (ei curl-asennusta). `curl` (Tapa B) on sallittu
|
||||||
tulee suoraan GitHub Releasesista tai vastaavasta.
|
vain build-vaiheessa — `apk del curl` poistaa työkalun ennen runtimea.
|
||||||
|
Tapa C pre-cacheaa kielikohtaiset riippuvuudet ja tuottaa täysin
|
||||||
|
offline-runtime-kontin.
|
||||||
|
|
||||||
## Mitä EI kannata tehdä
|
## Mitä EI kannata tehdä
|
||||||
|
|
||||||
- Älä lisää `workflow_call`-triggariä — CI-konttia ei koskaan buildata automaattisesti
|
- Älä lisää `workflow_call`-triggariä — CI-konttia ei koskaan buildata automaattisesti
|
||||||
- Älä poista `<komponentti>.`-prefiksiä olemassaolevista tiedostoista — ne kuuluvat monorepo-nimeämiskonventioon
|
- Älä poista `<komponentti>.`-prefiksiä olemassaolevista tiedostoista — ne kuuluvat monorepo-nimeämiskonventioon
|
||||||
- Älä sisällytä CI-konttiin mitään sovelluskoodia — vain työkalut
|
- Älä sisällytä CI-konttiin mitään sovelluskoodia — vain työkalut
|
||||||
- Älä koskaan asenna `git`:iä CI-konttiin — repon kloonaus ja checkout ovat Gitea Actionsin natiiveja operaatioita, eivät kontin vastuulla. Git paisuttaa konttia turhaan ja luo harhan että kontti hallitsee repoa
|
- Älä koskaan lataa mitään pipeline- tai runtime-vaiheessa — kaikki lataukset kuuluvat `docker build` -vaiheeseen (Offline-periaate)
|
||||||
|
- Älä jätä kielikohtaisia riippuvuuksia pre-cachaamatta — `go mod download`, `npm install`, `mvn dependency:go-offline` jne. ajetaan Dockerfilessä, ei pipelinessä
|
||||||
|
|||||||
@@ -2,6 +2,93 @@
|
|||||||
|
|
||||||
Mallipohjat, esimerkit ja konfiguraatiot. Katso säännöt `SKILL.md`:stä.
|
Mallipohjat, esimerkit ja konfiguraatiot. Katso säännöt `SKILL.md`:stä.
|
||||||
|
|
||||||
|
## Pre-cache-esimerkit (Offline Container)
|
||||||
|
|
||||||
|
Alla Dockerfile-esimerkit kielikohtaisista pre-cacheista. Kaikki ajetaan
|
||||||
|
build-vaiheessa — kontti on täysin itseriittoinen eikä lataa mitään
|
||||||
|
pipeline- tai runtime-vaiheessa.
|
||||||
|
|
||||||
|
### Go
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
FROM golang:1.24-alpine AS deps
|
||||||
|
WORKDIR /build
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
FROM deps AS test-build
|
||||||
|
COPY . .
|
||||||
|
RUN go test -c -o /tmp/test.bin ./...
|
||||||
|
|
||||||
|
FROM alpine:3.21
|
||||||
|
RUN apk add --no-cache git nodejs
|
||||||
|
COPY --from=deps /go/pkg/mod /go/pkg/mod
|
||||||
|
COPY --from=test-build /tmp/test.bin /usr/local/bin/test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Node.js
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
FROM node:22-alpine AS deps
|
||||||
|
WORKDIR /build
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
FROM node:22-alpine
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
COPY --from=deps /build/node_modules /app/node_modules
|
||||||
|
COPY . /app
|
||||||
|
WORKDIR /app
|
||||||
|
```
|
||||||
|
|
||||||
|
### Java / Maven
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
FROM maven:3.9-eclipse-temurin-21 AS deps
|
||||||
|
WORKDIR /build
|
||||||
|
COPY pom.xml ./
|
||||||
|
RUN mvn dependency:go-offline -B
|
||||||
|
|
||||||
|
FROM maven:3.9-eclipse-temurin-21 AS build
|
||||||
|
COPY --from=deps /root/.m2 /root/.m2
|
||||||
|
COPY . .
|
||||||
|
RUN mvn package -B -DskipTests
|
||||||
|
|
||||||
|
FROM eclipse-temurin:21-jre
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY --from=build /build/target/*.jar /app/app.jar
|
||||||
|
WORKDIR /app
|
||||||
|
```
|
||||||
|
|
||||||
|
### Python
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
FROM python:3.12-alpine AS deps
|
||||||
|
WORKDIR /build
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip wheel --wheel-dir=/wheels -r requirements.txt
|
||||||
|
|
||||||
|
FROM python:3.12-alpine
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
COPY --from=deps /build/wheels /wheels
|
||||||
|
COPY --from=deps /build/requirements.txt /
|
||||||
|
RUN pip install --no-index --find-links=/wheels -r /requirements.txt && rm -rf /wheels
|
||||||
|
COPY . /app
|
||||||
|
WORKDIR /app
|
||||||
|
```
|
||||||
|
|
||||||
|
### Helm + Node.js (korvaa helm-build-push.yml:n runtime-apk)
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
FROM alpine/helm:3.16.0 AS helm-bin
|
||||||
|
FROM node:22-alpine
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
COPY --from=helm-bin /usr/bin/helm /usr/local/bin/helm
|
||||||
|
```
|
||||||
|
|
||||||
|
Tämä kontti korvaa `helm-build-push.yml`:n `alpine/helm:3.19.0`-image-riippuvuuden
|
||||||
|
ja poistaa tarpeen asentaa node.js runtime-vaiheessa.
|
||||||
|
|
||||||
## Reititin — täydellinen esimerkki
|
## Reititin — täydellinen esimerkki
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
@@ -82,7 +82,36 @@ koko stepin ensimmäisellä failaavalla komennolla, ja loput jäävät ajamatta.
|
|||||||
|
|
||||||
CI-kontin build-workflow'n template: `skills/ci-container-build/SKILL.md`.
|
CI-kontin build-workflow'n template: `skills/ci-container-build/SKILL.md`.
|
||||||
|
|
||||||
### 4.1 CI-kontin ajaminen jobissa
|
### 4.1 Offline Container -vaatimus (DoD)
|
||||||
|
|
||||||
|
CI-kontin (ja kaikkien pipeline-konttien) on oltava täysin itseriittoisia:
|
||||||
|
|
||||||
|
> Kontti ei lataa mitään pipeline-vaiheessa (`workflow run` -stepit) eikä
|
||||||
|
> kontin runtime-prosessissa (`container:` / `docker run`). Kaikki
|
||||||
|
> riippuvuudet pre-cachataan `docker build` -vaiheessa.
|
||||||
|
> Ainoa sallittu lataushetki on `docker build`.
|
||||||
|
|
||||||
|
**Esimerkkejä rikkomuksista:**
|
||||||
|
- `apk add`, `apt-get install`, `npm install`, `go mod download`, `pip install`
|
||||||
|
pipeline-stepissä
|
||||||
|
- `curl <url> | tar xz` runtime-vaiheessa
|
||||||
|
- Node.js-konttikuva ilman nodea (joudutaan asentamaan lennossa)
|
||||||
|
|
||||||
|
### 4.2 Kielikohtainen pre-cache
|
||||||
|
|
||||||
|
Kun kontissa testataan kielikohtaista koodia, kaikki riippuvuudet on
|
||||||
|
pre-cachattava Dockerfilessä, ei pipeline-stepissä:
|
||||||
|
|
||||||
|
| Kieli | Pre-cache Dockerfilessä |
|
||||||
|
|---|---|
|
||||||
|
| Go | `COPY go.mod go.sum ./` → `RUN go mod download` |
|
||||||
|
| Java/Maven | `COPY pom.xml ./` → `RUN mvn dependency:go-offline` |
|
||||||
|
| Node | `COPY package.json package-lock.json ./` → `RUN npm ci --omit=dev` |
|
||||||
|
| Python | `COPY requirements.txt ./` → `RUN pip install -r requirements.txt` |
|
||||||
|
|
||||||
|
Katso tarkat Dockerfile-esimerkit `REFERENCE.md`:stä.
|
||||||
|
|
||||||
|
### 4.3 CI-kontin ajaminen jobissa
|
||||||
|
|
||||||
Ainoa sallittu tapa on `container:`-direktiivi. `docker run` komennolla kontin
|
Ainoa sallittu tapa on `container:`-direktiivi. `docker run` komennolla kontin
|
||||||
käynnistäminen stepin sisällä on anti-pattern.
|
käynnistäminen stepin sisällä on anti-pattern.
|
||||||
@@ -91,7 +120,8 @@ Katso CI-kontin template `REFERENCE.md`:stä.
|
|||||||
|
|
||||||
**Huomio `actions/checkout@v4`:stä:** `container:`-direktiivillä kaikki stepit
|
**Huomio `actions/checkout@v4`:stä:** `container:`-direktiivillä kaikki stepit
|
||||||
ajetaan kontin *sisällä* — myös `actions/checkout@v4`. Se on JavaScript-action
|
ajetaan kontin *sisällä* — myös `actions/checkout@v4`. Se on JavaScript-action
|
||||||
joka vaatii sekä `nodejs` että `git`. Varmista että CI-kontin Dockerfilessä on molemmat.
|
joka vaatii sekä `nodejs` että `git`. Varmista että CI-kontin Dockerfilessä on
|
||||||
|
molemmat — muuten checkout ei toimi ja pipeline failaa.
|
||||||
|
|
||||||
## 5. Raporttitasot
|
## 5. Raporttitasot
|
||||||
|
|
||||||
@@ -243,15 +273,14 @@ helm-build-push:
|
|||||||
# chart_path: '.' # oletus, vaihda jos Chart.yaml on alihakemistossa
|
# chart_path: '.' # oletus, vaihda jos Chart.yaml on alihakemistossa
|
||||||
```
|
```
|
||||||
|
|
||||||
**Node.js-kompromissi:** `actions/checkout@v4` on JavaScript-action.
|
**Vanhentunut käytäntö:** Nykyinen `helm-build-push.yml` asentaa node.js:n
|
||||||
Kontissa `alpine/helm` ei ole node.js:ää, joten se asennetaan lennossa
|
lennossa `apk add --no-cache nodejs` ennen checkouttia — tämä rikkoo
|
||||||
`apk add --no-cache nodejs` ennen checkouttia.
|
Offline Container -vaatimusta (4.1).
|
||||||
|
|
||||||
- Vaatii internet-yhteyden
|
**Korjaustoimenpide:** Rakenna custom CI-kontti `ci-container-build`-skillillä
|
||||||
- Ei toimi air gap -ympäristössä
|
jossa on helm + nodejs + git (katso pre-cache-esimerkit `REFERENCE.md`:stä),
|
||||||
- Korvaa tarvittaessa custom-kontilla (helm + nodejs):
|
päivitä workflow'n `container: image:` osoittamaan omaan konttiin, ja poista
|
||||||
rakenna `ci-container-build`-skillillä ja päivitä workflow'n
|
runtime-apk.
|
||||||
`container: image:` osoittamaan omaan konttiin
|
|
||||||
|
|
||||||
**Yksittäisten Helm-UI-linkkien raportointi:** `HELM_UI_URL` on
|
**Yksittäisten Helm-UI-linkkien raportointi:** `HELM_UI_URL` on
|
||||||
tarkoitettu yleiselle registry UI:lle — provider muodostaa linkin
|
tarkoitettu yleiselle registry UI:lle — provider muodostaa linkin
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ source "$BATS_TEST_DIRNAME/helpers/mock-api.sh"
|
|||||||
setup() {
|
setup() {
|
||||||
export GITEA_TOKEN=test-token
|
export GITEA_TOKEN=test-token
|
||||||
export GIT_TAG_PREFIX=""
|
export GIT_TAG_PREFIX=""
|
||||||
export SERVER_URL="http://localhost:18080"
|
|
||||||
export REPO="niko/test"
|
export REPO="niko/test"
|
||||||
export SHA="abc123"
|
export SHA="abc123"
|
||||||
rm -rf /tmp/build-ctx
|
rm -rf /tmp/build-ctx
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"running"}}
|
{"code":200,"body":{"id":1,"status":"running"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 124 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ teardown() {
|
|||||||
{"code":500}
|
{"code":500}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 0 ]
|
||||||
path=$(mock_get_first_request_path)
|
path=$(mock_get_first_request_path)
|
||||||
[[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]]
|
[[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]]
|
||||||
@@ -126,7 +126,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"workflow_runs":[]}}
|
{"code":200,"body":{"workflow_runs":[]}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
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 ]
|
[ "$status" -eq 1 ]
|
||||||
[[ "$output" == *"ERROR"* ]]
|
[[ "$output" == *"ERROR"* ]]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
MOCK_PORT=18080
|
MOCK_PORT=""
|
||||||
MOCK_PID=""
|
MOCK_PID=""
|
||||||
MOCK_REQUEST_FILE=""
|
MOCK_REQUEST_FILE=""
|
||||||
MOCK_RESPONSE_CODE=201
|
MOCK_RESPONSE_CODE=201
|
||||||
@@ -9,11 +9,17 @@ MOCK_STATE_FILE="/tmp/mock_api_state"
|
|||||||
MOCK_SEQUENCE_FILE=""
|
MOCK_SEQUENCE_FILE=""
|
||||||
MOCK_CONFIG_FILE=""
|
MOCK_CONFIG_FILE=""
|
||||||
|
|
||||||
|
_free_port() {
|
||||||
|
python3 -c "import socket; s=socket.socket(); s.bind(('',0)); print(s.getsockname()[1]); s.close()"
|
||||||
|
}
|
||||||
|
|
||||||
_kill_port() {
|
_kill_port() {
|
||||||
local pids
|
local pids
|
||||||
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
|
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
|
||||||
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true
|
[ -n "$pids" ] && kill $pids 2>/dev/null || true
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
|
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
|
||||||
|
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
_wait_port_free() {
|
_wait_port_free() {
|
||||||
@@ -26,10 +32,14 @@ _wait_port_free() {
|
|||||||
|
|
||||||
_wait_port_ready() {
|
_wait_port_ready() {
|
||||||
local i=0
|
local i=0
|
||||||
while ! lsof -ti ":$MOCK_PORT" >/dev/null 2>&1 && [ $i -lt 5 ]; do
|
while [ $i -lt 50 ]; do
|
||||||
|
if nc -z localhost "$MOCK_PORT" 2>/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
mock_set_sequence() {
|
mock_set_sequence() {
|
||||||
@@ -43,6 +53,12 @@ mock_clear_sequence() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mock_start() {
|
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_RESPONSE_CODE="${MOCK_RESPONSE_CODE:-201}"
|
||||||
MOCK_REQUEST_FILE=$(mktemp)
|
MOCK_REQUEST_FILE=$(mktemp)
|
||||||
echo "$MOCK_REQUEST_FILE" > "$MOCK_STATE_FILE"
|
echo "$MOCK_REQUEST_FILE" > "$MOCK_STATE_FILE"
|
||||||
|
|||||||
@@ -63,9 +63,10 @@ teardown() {
|
|||||||
{"code":200,"body":"published"}
|
{"code":200,"body":"published"}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
|
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
|
||||||
run bash scripts/publish-git-pages.sh "unit-tests"
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
||||||
[ "$status" -eq 0 ]
|
[ "$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" {
|
@test "publish with suite subpath" {
|
||||||
@@ -75,9 +76,10 @@ teardown() {
|
|||||||
{"code":200,"body":"published"}
|
{"code":200,"body":"published"}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
|
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
|
||||||
run bash scripts/publish-git-pages.sh "sub/suite"
|
run bash scripts/publish-git-pages.sh "sub/suite"
|
||||||
[ "$status" -eq 0 ]
|
[ "$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" {
|
@test "git-pages returns HTTP 500 → exit 1" {
|
||||||
@@ -85,6 +87,7 @@ teardown() {
|
|||||||
{"code":500,"body":"internal error"}
|
{"code":500,"body":"internal error"}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
|
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
|
||||||
run bash scripts/publish-git-pages.sh "unit-tests"
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[[ "$output" == *"500"* ]]
|
[[ "$output" == *"500"* ]]
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ teardown() {
|
|||||||
body=$(mock_get_request_body)
|
body=$(mock_get_request_body)
|
||||||
[[ "$body" == *'"state":"pending"'* ]]
|
[[ "$body" == *'"state":"pending"'* ]]
|
||||||
[[ "$body" == *'"description":"Building project"'* ]]
|
[[ "$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=$(mock_get_request_method)
|
||||||
[[ "$method" == "POST" ]]
|
[[ "$method" == "POST" ]]
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,8 @@ teardown() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
body=$(mock_get_request_body)
|
body=$(mock_get_request_body)
|
||||||
[[ "$body" == *'"state":"failure"'* ]]
|
[[ "$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" {
|
@test "default key when not provided" {
|
||||||
|
|||||||
Reference in New Issue
Block a user