204 lines
7.8 KiB
YAML
204 lines
7.8 KiB
YAML
name: Build Feature
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
bats-image:
|
|
required: false
|
|
type: string
|
|
default: bats/bats:latest
|
|
cucumber-node-image:
|
|
required: false
|
|
type: string
|
|
default: node:22
|
|
|
|
jobs:
|
|
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
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
path: .ci
|
|
|
|
- name: Run bats tests
|
|
id: bats-tests
|
|
shell: bash
|
|
run: |
|
|
docker volume create bats-workspace
|
|
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 \
|
|
--entrypoint sh ${{ inputs.bats-image }} \
|
|
-c 'apk add -q lsof python3 jq && \
|
|
echo "=== Volume contents ===" && \
|
|
ls -la /data/scripts/ && \
|
|
echo "=== Run bats ===" && \
|
|
cd /data && bats tests/ ' \
|
|
> "reports/${GITHUB_SHA:0:8}/bats/results.txt" 2>&1
|
|
BATS_EXIT=$?
|
|
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"
|
|
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"
|
|
|
|
- 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/"
|
|
else
|
|
STATUS="failure"
|
|
DESC="Bats tests FAILED"
|
|
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/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
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
path: .ci
|
|
|
|
- name: Prepare cucumber
|
|
id: prepare-cucumber
|
|
shell: bash
|
|
run: |
|
|
apt-get update -qq && apt-get install -y -qq --no-install-recommends lsof jq
|
|
if npm install @cucumber/cucumber > /dev/null 2>&1 && \
|
|
npx --package @cucumber/cucumber cucumber-js --dry-run tests/features/ > /dev/null 2>&1; then
|
|
echo "TOOL_OK=true" >> "${GITHUB_ENV}"
|
|
else
|
|
echo "TOOL_OK=false" >> "${GITHUB_ENV}"
|
|
fi
|
|
|
|
- name: Run cucumber tests
|
|
if: always()
|
|
id: cucumber-tests
|
|
shell: bash
|
|
run: |
|
|
if [ "${TOOL_OK}" != "true" ]; then
|
|
echo "CUCUMBER_EXIT=1" >> "${GITHUB_ENV}"
|
|
exit 0
|
|
fi
|
|
mkdir -p "reports/${GITHUB_SHA:0:8}/cucumber"
|
|
set +e
|
|
npx cucumber-js \
|
|
--format json:"reports/${GITHUB_SHA:0:8}/cucumber/report.json" \
|
|
--format html:"reports/${GITHUB_SHA:0:8}/cucumber/index.html" 2>&1
|
|
CUCUMBER_EXIT=$?
|
|
echo "CUCUMBER_EXIT=${CUCUMBER_EXIT}" >> "${GITHUB_ENV}"
|
|
exit ${CUCUMBER_EXIT}
|
|
|
|
- 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"
|
|
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}"
|
|
elif [ "${CUCUMBER_EXIT}" = "0" ]; then
|
|
STATUS="success"
|
|
DESC="Cucumber tests passed"
|
|
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/cucumber/"
|
|
else
|
|
STATUS="failure"
|
|
DESC="Cucumber tests FAILED"
|
|
URL="https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/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
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
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"
|
|
|
|
- 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
|