piilloparametrit eksplisiittisiksi
CI / load-config (push) Successful in 12s
ci-bats Bats tests
ci-cucumber Cucumber tests passed
ci-build Build complete
CI / feature (push) Successful in 1m24s
CI / main (push) Has been skipped

This commit is contained in:
moilanik
2026-06-13 16:21:47 +03:00
parent a80731a162
commit 0655372a86
7 changed files with 90 additions and 95 deletions
+8 -23
View File
@@ -52,22 +52,17 @@ jobs:
if: always() if: always()
shell: bash shell: bash
run: | run: |
bash .ci/scripts/publish-git-pages.sh "reports/${GITHUB_SHA:0:8}/bats" bash .ci/scripts/publish-git-pages.sh "bats/" "$PAGES_HOST" "$GIT_PAGES_PUBLISH_URL" "$GIT_PAGES_PUBLISH_TOKEN"
- name: Set bats commit status - name: Set bats commit status
if: always() if: always()
shell: bash shell: bash
run: | run: |
if [ "${BATS_EXIT}" = "0" ]; then if [ "${BATS_EXIT}" = "0" ]; then
STATUS="success" bash .ci/scripts/report-status.sh success "Bats tests" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-bats" "$PAGES_HOST" "bats/"
DESC="Bats tests"
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/bats/"
else else
STATUS="failure" bash .ci/scripts/report-status.sh failure "Bats tests FAILED" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-bats" "$PAGES_HOST" "bats/"
DESC="Bats tests FAILED"
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/bats/"
fi fi
bash .ci/scripts/report-status.sh "$STATUS" "$DESC" "$URL" ci-bats
cucumber: cucumber:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -115,7 +110,7 @@ jobs:
shell: bash shell: bash
run: | run: |
if [ "${TOOL_OK}" = "true" ]; then if [ "${TOOL_OK}" = "true" ]; then
bash .ci/scripts/publish-git-pages.sh "reports/${GITHUB_SHA:0:8}/cucumber" bash .ci/scripts/publish-git-pages.sh "cucumber/" "$PAGES_HOST" "$GIT_PAGES_PUBLISH_URL" "$GIT_PAGES_PUBLISH_TOKEN"
fi fi
- name: Set cucumber commit status - name: Set cucumber commit status
@@ -123,19 +118,12 @@ jobs:
shell: bash shell: bash
run: | run: |
if [ "${TOOL_OK}" != "true" ]; then if [ "${TOOL_OK}" != "true" ]; then
STATUS="failure" bash .ci/scripts/report-status.sh failure "Cucumber tool unavailable" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-cucumber" "$PAGES_HOST"
DESC="Cucumber tool unavailable"
URL="${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
elif [ "${CUCUMBER_EXIT}" = "0" ]; then elif [ "${CUCUMBER_EXIT}" = "0" ]; then
STATUS="success" bash .ci/scripts/report-status.sh success "Cucumber tests passed" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-cucumber" "$PAGES_HOST" "cucumber/"
DESC="Cucumber tests passed"
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/cucumber/"
else else
STATUS="failure" bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-cucumber" "$PAGES_HOST" "cucumber/"
DESC="Cucumber tests FAILED"
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/cucumber/"
fi fi
bash .ci/scripts/report-status.sh "$STATUS" "$DESC" "$URL" ci-cucumber
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -153,7 +141,4 @@ jobs:
- name: Set build commit status - name: Set build commit status
run: | run: |
bash .ci/scripts/report-status.sh success \ bash .ci/scripts/report-status.sh success "Build complete" "" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-build" "$PAGES_HOST"
"Build complete" \
"${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
ci-build
+7 -7
View File
@@ -14,14 +14,14 @@ on:
jobs: jobs:
publish: publish:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
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
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Publish reports - name: Publish reports
run: bash scripts/publish.sh reports run: |
bash scripts/publish.sh "reports" \
"https://gitea.app.keskikuja.site" \
"${{ secrets.GITEA_TOKEN }}" \
"ci-reports.helm-dev.keskikuja.site" \
"https://ci-reports.helm-dev.keskikuja.site" \
"${{ secrets.GIT_PAGES_PUBLISH_TOKEN }}"
+12 -11
View File
@@ -1,27 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Publish a report directory to git-pages apex index-site via Traefik (BasicAuth).
# Public URL: https://{PAGES_HOST}/{owner}/{repo}/reports/{sha8}/index.html
set -euo pipefail set -euo pipefail
REPORT_DIR="${1:-}" SUITE_PATH="${1:-}"
PAGES_HOST="${PAGES_HOST:-}" PAGES_HOST="${2:-}"
GIT_PAGES_PUBLISH_URL="${GIT_PAGES_PUBLISH_URL:-https://pages.helm-dev.keskikuja.site}" GIT_PAGES_PUBLISH_URL="${3:-}"
GIT_PAGES_PUBLISH_TOKEN="${GIT_PAGES_PUBLISH_TOKEN:-}" GIT_PAGES_PUBLISH_TOKEN="${4:-}"
GIT_PAGES_PUBLISH_USER="${GIT_PAGES_PUBLISH_USER:-publish}" GIT_PAGES_PUBLISH_USER="${5:-publish}"
REPO_SLUG="${GITHUB_REPOSITORY:-}" REPO_SLUG="${GITHUB_REPOSITORY:-}"
[ -n "$REPORT_DIR" ] || { echo "ERROR: report directory argument required" >&2; exit 1; } [ -n "$SUITE_PATH" ] || { echo "ERROR: suite_path argument required" >&2; exit 1; }
[ -d "$REPORT_DIR" ] || { echo "ERROR: not a directory: $REPORT_DIR" >&2; exit 1; } [ -n "$PAGES_HOST" ] || { echo "ERROR: pages_host argument is required" >&2; exit 1; }
[ -n "$PAGES_HOST" ] || { echo "ERROR: PAGES_HOST is not set" >&2; exit 1; } [ -n "$GIT_PAGES_PUBLISH_URL" ] || { echo "ERROR: publish_url argument is required" >&2; exit 1; }
[ -n "$GIT_PAGES_PUBLISH_TOKEN" ] || { echo "ERROR: GIT_PAGES_PUBLISH_TOKEN is not set" >&2; exit 1; } [ -n "$GIT_PAGES_PUBLISH_TOKEN" ] || { echo "ERROR: publish_token argument is required" >&2; exit 1; }
[ -n "$REPO_SLUG" ] || { echo "ERROR: GITHUB_REPOSITORY is not set" >&2; exit 1; } [ -n "$REPO_SLUG" ] || { echo "ERROR: GITHUB_REPOSITORY is not set" >&2; exit 1; }
[ -n "${GITHUB_SHA:-}" ] || { echo "ERROR: GITHUB_SHA is not set" >&2; exit 1; } [ -n "${GITHUB_SHA:-}" ] || { echo "ERROR: GITHUB_SHA is not set" >&2; exit 1; }
OWNER="${REPO_SLUG%%/*}" OWNER="${REPO_SLUG%%/*}"
REPO="${REPO_SLUG##*/}" REPO="${REPO_SLUG##*/}"
SHA8="${GITHUB_SHA:0:8}" SHA8="${GITHUB_SHA:0:8}"
REPORT_DIR="reports/${SHA8}/${SUITE_PATH}"
REPORT_BASE="https://${PAGES_HOST}/${OWNER}/${REPO}/reports/${SHA8}" REPORT_BASE="https://${PAGES_HOST}/${OWNER}/${REPO}/reports/${SHA8}"
[ -d "$REPORT_DIR" ] || { echo "ERROR: not a directory: $REPORT_DIR" >&2; exit 1; }
PUBLISH_BASE="${GIT_PAGES_PUBLISH_URL%/}" PUBLISH_BASE="${GIT_PAGES_PUBLISH_URL%/}"
PUBLISH_SITE_URL="${PUBLISH_BASE}/" PUBLISH_SITE_URL="${PUBLISH_BASE}/"
+18 -5
View File
@@ -1,10 +1,23 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Vie raportit git-pagesiin + commit-status linkillä
set -euo pipefail set -euo pipefail
REPORT_DIR="${1:-reports}" SUITE_PATH="${1:-}"
PAGES_HOST="${PAGES_HOST:-ci-reports.helm-dev.keskikuja.site}" GITEA_API_URL="${2:-}"
GITEA_TOKEN="${3:-}"
PAGES_HOST="${4:-}"
GIT_PAGES_PUBLISH_URL="${5:-}"
GIT_PAGES_PUBLISH_TOKEN="${6:-}"
GIT_PAGES_PUBLISH_USER="${7:-publish}"
REPORT_URL=$(bash "$(dirname $0)/publish-git-pages.sh" "$REPORT_DIR") [ -n "$SUITE_PATH" ] || { echo "ERROR: suite_path argument required" >&2; exit 1; }
[ -n "$GITEA_API_URL" ] || { echo "ERROR: gitea_api_url argument required" >&2; exit 1; }
[ -n "$GITEA_TOKEN" ] || { echo "ERROR: gitea_token argument required" >&2; exit 1; }
[ -n "$PAGES_HOST" ] || { echo "ERROR: pages_host argument required" >&2; exit 1; }
[ -n "$GIT_PAGES_PUBLISH_URL" ] || { echo "ERROR: publish_url argument required" >&2; exit 1; }
[ -n "$GIT_PAGES_PUBLISH_TOKEN" ] || { echo "ERROR: publish_token argument required" >&2; exit 1; }
SCRIPT_DIR="$(dirname "$0")"
REPORT_URL=$(bash "$SCRIPT_DIR/publish-git-pages.sh" "$SUITE_PATH" "$PAGES_HOST" "$GIT_PAGES_PUBLISH_URL" "$GIT_PAGES_PUBLISH_TOKEN" "$GIT_PAGES_PUBLISH_USER")
echo "Published: $REPORT_URL" echo "Published: $REPORT_URL"
bash "$(dirname $0)/report-status.sh" success "Reports published" "$REPORT_URL" ci-report bash "$SCRIPT_DIR/report-status.sh" success "Reports published" "$REPORT_URL" "$GITEA_API_URL" "$GITEA_TOKEN" "ci-report"
+15 -7
View File
@@ -1,19 +1,27 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
[ -z "${GITEA_API_URL:-}" ] && echo "ERROR: GITEA_API_URL is not set" >&2 && exit 1
[ -z "${GITEA_TOKEN:-}" ] && echo "ERROR: GITEA_TOKEN is not set" >&2 && exit 1
STATE="${1:-}" STATE="${1:-}"
DESCRIPTION="${2:-}" DESCRIPTION="${2:-}"
URL="${3:-}" URL="${3:-}"
KEY="${4:-commit-${GITHUB_SHA:0:8}}" GITEA_API_URL="${4:-}"
ROOT_COMMIT="${5:-}" GITEA_TOKEN="${5:-}"
ROOT_REPO="${6:-}" KEY="${6:-commit-${GITHUB_SHA:0:8}}"
PAGES_HOST="${7:-}"
REPORT_PATH="${8:-}"
ROOT_COMMIT="${9:-}"
ROOT_REPO="${10:-}"
[ -z "$STATE" ] && echo "ERROR: state argument is required" >&2 && exit 1 [ -z "$STATE" ] && echo "ERROR: state argument is required" >&2 && exit 1
[ -z "$DESCRIPTION" ] && echo "ERROR: description argument is required" >&2 && exit 1 [ -z "$DESCRIPTION" ] && echo "ERROR: description argument is required" >&2 && exit 1
[ -z "$URL" ] && echo "ERROR: url argument is required" >&2 && exit 1 [ -z "$GITEA_API_URL" ] && echo "ERROR: gitea_api_url argument is required" >&2 && exit 1
[ -z "$GITEA_TOKEN" ] && echo "ERROR: gitea_token argument is required" >&2 && exit 1
if [ -n "$REPORT_PATH" ]; then
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/${REPORT_PATH}"
elif [ -n "$PAGES_HOST" ]; then
URL="${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
fi
if [ -n "$ROOT_COMMIT" ] && [ -n "$ROOT_REPO" ]; then if [ -n "$ROOT_COMMIT" ] && [ -n "$ROOT_REPO" ]; then
REPO="$ROOT_REPO" REPO="$ROOT_REPO"
@@ -26,19 +26,8 @@ function bashQuiet(cmd) {
}); });
} }
function envBlock() {
return [
'export GITEA_API_URL="http://localhost:18080"',
'export GITEA_TOKEN="test-token-abc123"',
'export GITHUB_REPOSITORY="test-owner/test-repo"',
'export GITHUB_SHA="abc123def456789012345678901234567890abcd"',
'export GITHUB_SERVER_URL="https://gitea.example.com"',
'export GITHUB_RUN_ID="42"',
].join('; ');
}
function runReportStatus(args) { function runReportStatus(args) {
return bash(`${envBlock()}; bash "${REPORT_SCRIPT}" ${args}`); return bash(`export GITHUB_REPOSITORY="test-owner/test-repo" GITHUB_SHA="abc123def456789012345678901234567890abcd" GITHUB_RUN_ID="42"; bash "${REPORT_SCRIPT}" ${args}`);
} }
function getMockBody() { function getMockBody() {
@@ -50,7 +39,7 @@ function getMockPath() {
} }
When('a build step starts executing', function () { When('a build step starts executing', function () {
const r = runReportStatus('pending "Building project" "http://example.com/build/42"'); const r = runReportStatus('pending "Building project" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"');
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}: ${r.stderr}`); if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}: ${r.stderr}`);
}); });
@@ -61,7 +50,7 @@ Then('the commit shows a pending status with a description of the step', functio
}); });
When('a build step completes successfully and reports its results', function () { When('a build step completes successfully and reports its results', function () {
const r = runReportStatus('success "Unit tests OK" "http://example.com/reports/cucumber.html" "unit-test"'); const r = runReportStatus('success "Unit tests OK" "http://example.com/reports/cucumber.html" "http://localhost:18080" "test-token-abc123" "unit-test"');
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`); if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
}); });
@@ -72,7 +61,7 @@ Then('the commit shows a success status with a clickable link to the results', f
}); });
When('a build step fails', function () { When('a build step fails', function () {
const r = runReportStatus('failure "Tests failed: 3 of 10" "http://example.com/build/42"'); const r = runReportStatus('failure "Tests failed: 3 of 10" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"');
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`); if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
}); });
@@ -83,11 +72,11 @@ Then('the commit shows a failure status with a description of what went wrong',
}); });
When('several build steps each report their own status to the same commit', function () { When('several build steps each report their own status to the same commit', function () {
runReportStatus('pending "Build started" "http://example.com/build/42" "ci-build"'); runReportStatus('pending "Build started" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123" "ci-build"');
execSync('sleep 0.3', { stdio: 'ignore' }); execSync('sleep 0.3', { stdio: 'ignore' });
runReportStatus('success "Unit tests passed" "http://example.com/reports/unit.html" "unit-test"'); runReportStatus('success "Unit tests passed" "http://example.com/reports/unit.html" "http://localhost:18080" "test-token-abc123" "unit-test"');
execSync('sleep 0.3', { stdio: 'ignore' }); execSync('sleep 0.3', { stdio: 'ignore' });
runReportStatus('success "Integration tests passed" "http://example.com/reports/integration.html" "integration-test"'); runReportStatus('success "Integration tests passed" "http://example.com/reports/integration.html" "http://localhost:18080" "test-token-abc123" "integration-test"');
}); });
Then('each status appears under a unique label on the commit', function () { Then('each status appears under a unique label on the commit', function () {
@@ -104,7 +93,7 @@ Then('each status appears under a unique label on the commit', function () {
}); });
When('a deployment finishes for a commit that originated from another repository', function () { When('a deployment finishes for a commit that originated from another repository', function () {
const r = runReportStatus('success "Deployed to staging" "http://example.com/deploy/42" "deploy-staging" "rootabc123" "services/temperature-store"'); const r = runReportStatus('success "Deployed to staging" "http://example.com/deploy/42" "http://localhost:18080" "test-token-abc123" "deploy-staging" "" "" "rootabc123" "services/temperature-store"');
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`); if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
}); });
@@ -122,7 +111,7 @@ When('a build step tries to report status but the build system is unavailable',
bashQuiet(`source "${MOCK_SCRIPT}" && mock_stop`); bashQuiet(`source "${MOCK_SCRIPT}" && mock_stop`);
execSync('sleep 0.3', { stdio: 'ignore' }); execSync('sleep 0.3', { stdio: 'ignore' });
bashQuiet(`source "${MOCK_SCRIPT}" && mock_set_response 500 && mock_start`); bashQuiet(`source "${MOCK_SCRIPT}" && mock_set_response 500 && mock_start`);
const r = runReportStatus('success "Should fail" "http://example.com"'); const r = runReportStatus('success "Should fail" "http://example.com" "http://localhost:18080" "test-token-abc123"');
this.reportStatusFailed = (r.status !== 0); this.reportStatusFailed = (r.status !== 0);
}); });
+21 -22
View File
@@ -2,8 +2,6 @@
setup() { setup() {
source tests/helpers/mock-api.sh source tests/helpers/mock-api.sh
export GITEA_API_URL="http://localhost:18080"
export GITEA_TOKEN="test-token-abc123"
export GITHUB_REPOSITORY="test-owner/test-repo" export GITHUB_REPOSITORY="test-owner/test-repo"
export GITHUB_SHA="abc123def456789012345678901234567890abcd" export GITHUB_SHA="abc123def456789012345678901234567890abcd"
export GITHUB_SERVER_URL="https://gitea.example.com" export GITHUB_SERVER_URL="https://gitea.example.com"
@@ -16,7 +14,7 @@ teardown() {
@test "pending status is POSTed with correct payload" { @test "pending status is POSTed with correct payload" {
mock_start mock_start
run bash scripts/report-status.sh pending "Building project" "http://example.com/build/42" run bash scripts/report-status.sh pending "Building project" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
path=$(mock_get_request_path) path=$(mock_get_request_path)
[[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]] [[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]]
@@ -30,7 +28,7 @@ teardown() {
@test "success status with url and custom key" { @test "success status with url and custom key" {
mock_start mock_start
run bash scripts/report-status.sh success "Unit tests OK" "http://example.com/reports/cucumber.html" "unit-test" run bash scripts/report-status.sh success "Unit tests OK" "http://example.com/reports/cucumber.html" "http://localhost:18080" "test-token-abc123" "unit-test"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
body=$(mock_get_request_body) body=$(mock_get_request_body)
[[ "$body" == *'"state":"success"'* ]] [[ "$body" == *'"state":"success"'* ]]
@@ -41,7 +39,7 @@ teardown() {
@test "failure status is POSTed correctly" { @test "failure status is POSTed correctly" {
mock_start mock_start
run bash scripts/report-status.sh failure "Tests failed: 3 of 10" "http://example.com/build/42" run bash scripts/report-status.sh failure "Tests failed: 3 of 10" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
body=$(mock_get_request_body) body=$(mock_get_request_body)
[[ "$body" == *'"state":"failure"'* ]] [[ "$body" == *'"state":"failure"'* ]]
@@ -50,7 +48,7 @@ teardown() {
@test "error status is POSTed correctly" { @test "error status is POSTed correctly" {
mock_start mock_start
run bash scripts/report-status.sh error "Build timed out" "http://example.com/build/42" run bash scripts/report-status.sh error "Build timed out" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
body=$(mock_get_request_body) body=$(mock_get_request_body)
[[ "$body" == *'"state":"error"'* ]] [[ "$body" == *'"state":"error"'* ]]
@@ -58,7 +56,7 @@ teardown() {
@test "cross-repo: root_commit and root_repo override target" { @test "cross-repo: root_commit and root_repo override target" {
mock_start mock_start
run bash scripts/report-status.sh success "Deployed to staging" "http://example.com/deploy/42" "deploy-staging" "rootabc123" "services/temperature-store" run bash scripts/report-status.sh success "Deployed to staging" "http://example.com/deploy/42" "http://localhost:18080" "test-token-abc123" "deploy-staging" "" "" "rootabc123" "services/temperature-store"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
path=$(mock_get_request_path) path=$(mock_get_request_path)
[[ "$path" == "/api/v1/repos/services/temperature-store/statuses/rootabc123" ]] [[ "$path" == "/api/v1/repos/services/temperature-store/statuses/rootabc123" ]]
@@ -69,7 +67,7 @@ teardown() {
@test "cross-repo: only root_commit without root_repo is ignored" { @test "cross-repo: only root_commit without root_repo is ignored" {
mock_start mock_start
run bash scripts/report-status.sh success "Partial cross-repo" "http://example.com" "my-key" "abc" run bash scripts/report-status.sh success "Partial cross-repo" "http://example.com" "http://localhost:18080" "test-token-abc123" "my-key" "" "" "abc"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
path=$(mock_get_request_path) path=$(mock_get_request_path)
[[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]] [[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]]
@@ -77,7 +75,7 @@ teardown() {
@test "default key when not provided" { @test "default key when not provided" {
mock_start mock_start
run bash scripts/report-status.sh pending "Build started" "http://example.com/build/42" run bash scripts/report-status.sh pending "Build started" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
body=$(mock_get_request_body) body=$(mock_get_request_body)
[[ "$body" == *'"context":"commit-abc123de"'* ]] [[ "$body" == *'"context":"commit-abc123de"'* ]]
@@ -86,38 +84,39 @@ teardown() {
@test "API returns 500 causes exit 1" { @test "API returns 500 causes exit 1" {
mock_set_response 500 mock_set_response 500
mock_start mock_start
run bash scripts/report-status.sh success "Should fail" "http://example.com" run bash scripts/report-status.sh success "Should fail" "http://example.com" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "missing GITEA_API_URL causes exit 1 with error message" { @test "missing gitea_api_url argument causes exit 1 with error message" {
unset GITEA_API_URL mock_start
run bash scripts/report-status.sh pending "Test" "http://example.com" run bash scripts/report-status.sh pending "Test" "http://example.com" "" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ "$output" == *"ERROR"* ]] || [[ "$output" == *"GITEA_API_URL"* ]] [[ "$output" == *"ERROR"* || "$output" == *"gitea_api_url"* ]]
} }
@test "missing GITEA_TOKEN causes exit 1 with error message" { @test "missing gitea_token argument causes exit 1 with error message" {
unset GITEA_TOKEN mock_start
run bash scripts/report-status.sh pending "Test" "http://example.com" run bash scripts/report-status.sh pending "Test" "http://example.com" "http://localhost:18080" ""
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ "$output" == *"ERROR"* ]] || [[ "$output" == *"GITEA_TOKEN"* ]] [[ "$output" == *"ERROR"* || "$output" == *"gitea_token"* ]]
} }
@test "missing required state argument causes exit 1" { @test "missing required state argument causes exit 1" {
mock_start mock_start
run bash scripts/report-status.sh "" "desc" "http://example.com" run bash scripts/report-status.sh "" "desc" "http://example.com" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "missing required description argument causes exit 1" { @test "missing required description argument causes exit 1" {
mock_start mock_start
run bash scripts/report-status.sh pending "" "http://example.com" run bash scripts/report-status.sh pending "" "http://example.com" "http://localhost:18080" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@test "missing required url argument causes exit 1" { @test "missing required state argument is checked before gitea_api_url" {
mock_start mock_start
run bash scripts/report-status.sh pending "desc" "" run bash scripts/report-status.sh "" "desc" "http://example.com" "" ""
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ "$output" == *"state"* ]]
} }