pipeline siivous ja testikattavuuden nosto (#9)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #9
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
WORKSPACE_VOLUME="${1:-}"
|
||||
REPORT_DIR="${2:-}"
|
||||
|
||||
[ -n "$WORKSPACE_VOLUME" ] || { echo "ERROR: workspace volume name required" >&2; exit 1; }
|
||||
[ -n "$REPORT_DIR" ] || { echo "ERROR: report directory required" >&2; exit 1; }
|
||||
|
||||
HAS_COVERAGE=false
|
||||
COVERAGE_SRC=""
|
||||
if docker run --rm -v "$WORKSPACE_VOLUME":/data alpine sh -c '[ -d /data/coverage ] && ls -A /data/coverage | grep -q .' 2>/dev/null; then
|
||||
COVERAGE_SRC="/data/coverage"
|
||||
fi
|
||||
|
||||
if [ -n "$COVERAGE_SRC" ]; then
|
||||
mkdir -p "$REPORT_DIR/coverage"
|
||||
docker run --rm -v "$WORKSPACE_VOLUME":/data alpine tar c -C "$COVERAGE_SRC" . | tar x -C "$REPORT_DIR/coverage"
|
||||
HAS_COVERAGE=true
|
||||
fi
|
||||
|
||||
cat > "$REPORT_DIR/index.html" << EOF
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
|
||||
<title>Bats report ${GITHUB_SHA:0:8}</title>
|
||||
<style>body{font-family:sans-serif;margin:2em;max-width:960px}
|
||||
h1{color:#1e293b}a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}
|
||||
</style></head><body>
|
||||
<h1>Bats report <code>${GITHUB_SHA:0:8}</code></h1>
|
||||
<ul>
|
||||
<li><a href="test-report.html">Test results</a></li>
|
||||
EOF
|
||||
|
||||
if [ "$HAS_COVERAGE" = true ]; then
|
||||
echo '<li><a href="coverage/index.html">Coverage report</a></li>' >> "$REPORT_DIR/index.html"
|
||||
fi
|
||||
|
||||
echo '</ul></body></html>' >> "$REPORT_DIR/index.html"
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPORT_DIR="${1:-reports/bats}"
|
||||
INPUT="$REPORT_DIR/results.txt"
|
||||
OUTPUT="$REPORT_DIR/test-report.html"
|
||||
|
||||
[ -f "$INPUT" ] || { echo "ERROR: $INPUT not found" >&2; exit 1; }
|
||||
|
||||
TOTAL=$(grep -cE '^(ok|not ok) ' "$INPUT" 2>/dev/null) || TOTAL=0
|
||||
PASS=$(grep -c '^ok ' "$INPUT" 2>/dev/null) || PASS=0
|
||||
FAIL=$((TOTAL - PASS))
|
||||
|
||||
{
|
||||
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'
|
||||
echo "<title>Bats test report ${GITHUB_SHA:0:8}</title>"
|
||||
echo '<style>body{font-family:sans-serif;margin:2em;max-width:960px}'
|
||||
echo 'h1{color:#1e293b}.pass{color:#059669}.fail{color:#dc2626}'
|
||||
echo 'table{width:100%;border-collapse:collapse;margin-top:1em}'
|
||||
echo 'th,td{border:1px solid #e2e8f0;padding:8px;text-align:left}'
|
||||
echo 'th{background:#f8fafc}</style></head><body>'
|
||||
echo "<h1>Bats test report <code>${GITHUB_SHA:0:8}</code></h1>"
|
||||
echo "<p>Total: ${TOTAL} | Passed: <span class='pass'>${PASS}</span> | Failed: <span class='fail'>${FAIL}</span></p>"
|
||||
echo '<table><tr><th>#</th><th>Status</th><th>Test</th></tr>'
|
||||
|
||||
while IFS=' ' read -r status num rest; do
|
||||
case "$status" in
|
||||
ok) echo "<tr><td>${num}</td><td class='pass'>PASS</td><td>${rest}</td></tr>" ;;
|
||||
not) echo "<tr><td>${num}</td><td class='fail'>FAIL</td><td>${rest}</td></tr>" ;;
|
||||
esac
|
||||
done < <(grep -E '^(ok|not ok) ' "$INPUT")
|
||||
|
||||
echo '</table></body></html>'
|
||||
} > "$OUTPUT"
|
||||
|
||||
echo "$OUTPUT"
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SHA8="${GITHUB_SHA:0:8}"
|
||||
REPORTS_DIR="reports/${SHA8}"
|
||||
|
||||
mkdir -p "${REPORTS_DIR}"
|
||||
|
||||
BATS_PASS=$(grep -c 'ok' "${REPORTS_DIR}/bats/results.txt" 2>/dev/null || echo 0)
|
||||
BATS_FAIL=$(grep -c 'not ok' "${REPORTS_DIR}/bats/results.txt" 2>/dev/null || echo 0)
|
||||
CUCUMBER_PASS=$(jq '.summary.passed // 0' "${REPORTS_DIR}/cucumber/report.json" 2>/dev/null || echo 0)
|
||||
CUCUMBER_FAIL=$(jq '.summary.failed // 0' "${REPORTS_DIR}/cucumber/report.json" 2>/dev/null || echo 0)
|
||||
|
||||
{
|
||||
echo "<!DOCTYPE html><html><head><meta charset='utf-8'>"
|
||||
echo "<title>CI report ${SHA8}</title>"
|
||||
echo "<style>body{font-family:sans-serif;margin:2em}a{color:#2563eb}table{border-collapse:collapse}"
|
||||
echo "th,td{border:1px solid #ccc;padding:8px;text-align:left}"
|
||||
echo ".pass{color:#059669}.fail{color:#dc2626}</style></head><body>"
|
||||
echo "<h1>CI report <code>${SHA8}</code></h1>"
|
||||
echo "<p>Commit: ${GITHUB_SHA}<br>Branch: ${GITHUB_REF_NAME}<br>Run: ${GITHUB_RUN_ID}</p>"
|
||||
echo "<table><tr><th>Suite</th><th>Passed</th><th>Failed</th><th>Report</th></tr>"
|
||||
echo "<tr><td>Bats</td><td class='pass'>${BATS_PASS}</td><td class='fail'>${BATS_FAIL}</td>"
|
||||
echo "<td><a href='bats/results.txt'>results.txt</a>"
|
||||
echo " | <a href='bats/junit.xml'>junit.xml</a></td></tr>"
|
||||
echo "<tr><td>Cucumber</td><td class='pass'>${CUCUMBER_PASS}</td><td class='fail'>${CUCUMBER_FAIL}</td>"
|
||||
echo "<td><a href='cucumber/index.html'>report</a>"
|
||||
echo " | <a href='cucumber/report.json'>json</a></td></tr>"
|
||||
echo "</table></body></html>"
|
||||
} > "${REPORTS_DIR}/index.html"
|
||||
@@ -2,24 +2,42 @@ 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
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
GIT_PAGES_PUBLISH_TOKEN:
|
||||
required: true
|
||||
|
||||
env:
|
||||
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
||||
GIT_PAGES_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_URL }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }}
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: niko/gitea-ci-library
|
||||
path: .ci
|
||||
|
||||
- name: Validate CI config
|
||||
run: bash .ci/scripts/ci-validate.sh
|
||||
|
||||
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
|
||||
- uses: actions/checkout@v4
|
||||
@@ -35,56 +53,37 @@ jobs:
|
||||
tar c . | docker run --rm -i -v bats-workspace:/data alpine tar x -C /data
|
||||
mkdir -p "reports/${GITHUB_SHA:0:8}/bats"
|
||||
set +e
|
||||
docker run --rm -v bats-workspace:/data \
|
||||
docker run --rm \
|
||||
-v bats-workspace:/data \
|
||||
--entrypoint bash ${{ inputs.bats-image }} \
|
||||
-c 'apk add -q lsof python3 jq curl && \
|
||||
cd /data && bats tests/ ' \
|
||||
-c 'apk add -q lsof python3 jq curl ruby && cd /data && \
|
||||
gem install bashcov -v 3.3.0 2>&1 | tail -1 && \
|
||||
bashcov -- bats tests/' \
|
||||
> "reports/${GITHUB_SHA:0:8}/bats/results.txt" 2>&1
|
||||
BATS_EXIT=$?
|
||||
bash .ci/.gitea/scripts/bats-coverage.sh bats-workspace "reports/${GITHUB_SHA:0:8}/bats"
|
||||
docker volume rm bats-workspace > /dev/null 2>&1
|
||||
{
|
||||
echo "<html><body><h1>Bats tests</h1><ul>"
|
||||
for f in reports/${GITHUB_SHA:0:8}/bats/*; do
|
||||
b="$(basename $f)"
|
||||
[ "$b" = "index.html" ] && continue
|
||||
echo "<li><a href=\"$b\">$b</a></li>"
|
||||
done
|
||||
echo "</ul></body></html>"
|
||||
} > "reports/${GITHUB_SHA:0:8}/bats/index.html"
|
||||
bash .ci/.gitea/scripts/bats-report.sh "reports/${GITHUB_SHA:0:8}/bats"
|
||||
echo "BATS_EXIT=${BATS_EXIT}" >> "${GITHUB_ENV}"
|
||||
exit ${BATS_EXIT}
|
||||
|
||||
- name: Publish bats reports
|
||||
if: always()
|
||||
shell: bash
|
||||
run: |
|
||||
bash .ci/scripts/publish-git-pages.sh "reports/${GITHUB_SHA:0:8}/bats"
|
||||
run: bash .ci/scripts/publish-git-pages.sh bats
|
||||
|
||||
- name: Set bats commit status
|
||||
if: always()
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${BATS_EXIT}" = "0" ]; then
|
||||
STATUS="success"
|
||||
DESC="Bats tests"
|
||||
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/bats/"
|
||||
bash .ci/scripts/report-status.sh success "Bats tests" ci-bats bats
|
||||
else
|
||||
STATUS="failure"
|
||||
DESC="Bats tests FAILED"
|
||||
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/bats/"
|
||||
bash .ci/scripts/report-status.sh failure "Bats tests FAILED" ci-bats bats
|
||||
fi
|
||||
bash .ci/scripts/report-status.sh "$STATUS" "$DESC" "$URL" ci-bats
|
||||
|
||||
cucumber:
|
||||
runs-on: ubuntu-latest
|
||||
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
|
||||
- uses: actions/checkout@v4
|
||||
@@ -124,40 +123,25 @@ jobs:
|
||||
|
||||
- name: Publish cucumber reports
|
||||
if: always()
|
||||
shell: bash
|
||||
run: |
|
||||
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
|
||||
fi
|
||||
|
||||
- name: Set cucumber commit status
|
||||
if: always()
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${TOOL_OK}" != "true" ]; then
|
||||
STATUS="failure"
|
||||
DESC="Cucumber tool unavailable"
|
||||
URL="https://gitea.app.keskikuja.site/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|
||||
bash .ci/scripts/report-status.sh failure "Cucumber tool unavailable" ci-cucumber
|
||||
elif [ "${CUCUMBER_EXIT}" = "0" ]; then
|
||||
STATUS="success"
|
||||
DESC="Cucumber tests passed"
|
||||
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/cucumber/"
|
||||
bash .ci/scripts/report-status.sh success "Cucumber tests passed" ci-cucumber cucumber
|
||||
else
|
||||
STATUS="failure"
|
||||
DESC="Cucumber tests FAILED"
|
||||
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/cucumber/"
|
||||
bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" ci-cucumber cucumber
|
||||
fi
|
||||
bash .ci/scripts/report-status.sh "$STATUS" "$DESC" "$URL" ci-cucumber
|
||||
|
||||
build:
|
||||
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
|
||||
- uses: actions/checkout@v4
|
||||
@@ -166,35 +150,7 @@ jobs:
|
||||
path: .ci
|
||||
|
||||
- name: Generate report index
|
||||
shell: bash
|
||||
run: |
|
||||
SHA8="${GITHUB_SHA:0:8}"
|
||||
mkdir -p "reports/${SHA8}"
|
||||
BATS_PASS=$(grep -c 'ok' "reports/${SHA8}/bats/results.txt" 2>/dev/null || echo 0)
|
||||
BATS_FAIL=$(grep -c 'not ok' "reports/${SHA8}/bats/results.txt" 2>/dev/null || echo 0)
|
||||
CUCUMBER_PASS=$(jq '.summary.passed // 0' "reports/${SHA8}/cucumber/report.json" 2>/dev/null || echo 0)
|
||||
CUCUMBER_FAIL=$(jq '.summary.failed // 0' "reports/${SHA8}/cucumber/report.json" 2>/dev/null || echo 0)
|
||||
{
|
||||
echo "<!DOCTYPE html><html><head><meta charset='utf-8'>"
|
||||
echo "<title>CI report ${SHA8}</title>"
|
||||
echo "<style>body{font-family:sans-serif;margin:2em}a{color:#2563eb}table{border-collapse:collapse}"
|
||||
echo "th,td{border:1px solid #ccc;padding:8px;text-align:left}"
|
||||
echo ".pass{color:#059669}.fail{color:#dc2626}</style></head><body>"
|
||||
echo "<h1>CI report <code>${SHA8}</code></h1>"
|
||||
echo "<p>Commit: ${GITHUB_SHA}<br>Branch: ${GITHUB_REF_NAME}<br>Run: ${GITHUB_RUN_ID}</p>"
|
||||
echo "<table><tr><th>Suite</th><th>Passed</th><th>Failed</th><th>Report</th></tr>"
|
||||
echo "<tr><td>Bats</td><td class='pass'>${BATS_PASS}</td><td class='fail'>${BATS_FAIL}</td>"
|
||||
echo "<td><a href='bats/results.txt'>results.txt</a>"
|
||||
echo " | <a href='bats/junit.xml'>junit.xml</a></td></tr>"
|
||||
echo "<tr><td>Cucumber</td><td class='pass'>${CUCUMBER_PASS}</td><td class='fail'>${CUCUMBER_FAIL}</td>"
|
||||
echo "<td><a href='cucumber/index.html'>report</a>"
|
||||
echo " | <a href='cucumber/report.json'>json</a></td></tr>"
|
||||
echo "</table></body></html>"
|
||||
} > "reports/${SHA8}/index.html"
|
||||
run: bash .ci/.gitea/scripts/generate-report-index.sh
|
||||
|
||||
- name: Set build commit status
|
||||
run: |
|
||||
bash .ci/scripts/report-status.sh success \
|
||||
"Build complete" \
|
||||
"https://gitea.app.keskikuja.site/niko/gitea-ci-library/actions/runs/${GITHUB_RUN_ID}" \
|
||||
ci-build
|
||||
run: bash .ci/scripts/report-status.sh success "Build complete" ci-build
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
name: CI Engine
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
config-file:
|
||||
required: true
|
||||
type: string
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
GIT_PAGES_PUBLISH_TOKEN:
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
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:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Publish reports
|
||||
run: bash scripts/publish.sh reports
|
||||
@@ -5,16 +5,27 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
|
||||
with:
|
||||
config_path: .gitea/workflows/gitea-env.conf
|
||||
|
||||
feature:
|
||||
if: github.ref != 'refs/heads/main'
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@main
|
||||
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'
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
bats-image: bats/bats:latest
|
||||
cucumber-node-image: node:22
|
||||
|
||||
@@ -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"
|
||||
@@ -0,0 +1,2 @@
|
||||
GITEA_API_URL=https://gitea.app.keskikuja.site
|
||||
GIT_PAGES_URL=https://ci-reports.helm-dev.keskikuja.site
|
||||
Reference in New Issue
Block a user