Compare commits

..

1 Commits

Author SHA1 Message Date
niko 2bef079d03 Fix/ci kontin no internet vaatimus (#34)
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 22s
CI Main / Check existing artifact (push) Successful in 18s
acc-tests Cucumber test report
unit-tests Bats test report
CI Main / Cucumber tests (push) Successful in 1m25s
CI Main / Bats tests (push) Successful in 1m26s
ci-docker-build-push Docker build & push 0.2.19 OK
CI Main / Build & Push Docker (push) Successful in 47s
CI Main / Report Summary (push) Successful in 6s
CI Main / Move provider version tag (push) Successful in 16s
Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #34
2026-06-20 14:36:42 +03:00
9 changed files with 56 additions and 38 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ on:
cucumber-node-image:
required: false
type: string
default: gitea.app.keskikuja.site/niko/ci-cucumber:latest
default: gitea.app.keskikuja.site/niko/ci-cucumber:with-python
secrets:
GITEA_TOKEN:
required: true
+1 -1
View File
@@ -1,6 +1,6 @@
FROM node:22
RUN apt-get update -qq && \
apt-get install -y -qq --no-install-recommends lsof jq && \
apt-get install -y -qq --no-install-recommends lsof jq python3 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
npm install -g @cucumber/cucumber
+36
View File
@@ -182,6 +182,42 @@ 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
+1
View File
@@ -5,6 +5,7 @@ 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
+7 -7
View File
@@ -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"}' "$GITEA_API_URL" "test-token-abc123"
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "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"}' "$GITEA_API_URL" "test-token-abc123"
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "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"}' "$GITEA_API_URL" "test-token-abc123"
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "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"}' "$GITEA_API_URL" "test-token-abc123" "0.001"
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"
[ "$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"}' "$GITEA_API_URL" "test-token-abc123"
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "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"}' "$GITEA_API_URL" "test-token-abc123"
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "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" '{}' "$GITEA_API_URL" "test-token-abc123"
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{}' "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 1 ]
[[ "$output" == *"ERROR"* ]]
}
+6 -20
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
MOCK_PORT=""
MOCK_PORT=18080
MOCK_PID=""
MOCK_REQUEST_FILE=""
MOCK_RESPONSE_CODE=201
@@ -9,17 +9,13 @@ 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
[ -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
if [ -n "$pids" ]; then
kill -9 $pids 2>/dev/null || true
sleep 0.5
fi
}
_wait_port_free() {
@@ -32,14 +28,10 @@ _wait_port_free() {
_wait_port_ready() {
local i=0
while [ $i -lt 50 ]; do
if nc -z localhost "$MOCK_PORT" 2>/dev/null; then
return 0
fi
while ! lsof -ti ":$MOCK_PORT" >/dev/null 2>&1 && [ $i -lt 30 ]; do
sleep 0.2
i=$((i + 1))
done
return 1
}
mock_set_sequence() {
@@ -53,12 +45,6 @@ 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"
+2 -5
View File
@@ -63,10 +63,9 @@ 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" == "${GIT_PAGES_URL}/test-owner/test-repo/reports/abc123de" ]]
[[ "$output" == "http://localhost:18080/test-owner/test-repo/reports/abc123de" ]]
}
@test "publish with suite subpath" {
@@ -76,10 +75,9 @@ 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" == "${GIT_PAGES_URL}/test-owner/test-repo/reports/abc123de" ]]
[[ "$output" == "http://localhost:18080/test-owner/test-repo/reports/abc123de" ]]
}
@test "git-pages returns HTTP 500 → exit 1" {
@@ -87,7 +85,6 @@ 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"* ]]
+2 -4
View File
@@ -23,8 +23,7 @@ teardown() {
body=$(mock_get_request_body)
[[ "$body" == *'"state":"pending"'* ]]
[[ "$body" == *'"description":"Building project"'* ]]
expected_url="${GITEA_API_URL}/test-owner/test-repo/actions/runs/42"
[[ "$body" == *"\"target_url\":\"${expected_url}\""* ]]
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]]
method=$(mock_get_request_method)
[[ "$method" == "POST" ]]
}
@@ -45,8 +44,7 @@ teardown() {
[ "$status" -eq 0 ]
body=$(mock_get_request_body)
[[ "$body" == *'"state":"failure"'* ]]
expected_url="${GITEA_API_URL}/test-owner/test-repo/actions/runs/42"
[[ "$body" == *"\"target_url\":\"${expected_url}\""* ]]
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]]
}
@test "default key when not provided" {