Files
gitea-ci-library/.gitea/workflows/build-feature.yml
T
moilanik 07e2b16cca
ci-cucumber Cucumber tests passed
ci-bats Bats tests
ci-build Build complete
CI / feature (push) Successful in 51s
CI / main (push) Has been skipped
kokeilu
2026-06-13 04:27:51 +03:00

157 lines
6.0 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:20
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
continue-on-error: true
shell: bash
run: |
mkdir -p "reports/${GITHUB_SHA:0:8}/bats"
docker run --rm -v "$PWD:/code" ${{ inputs.bats-image }} /code/tests/*.bats > "reports/${GITHUB_SHA:0:8}/bats/results.txt" 2>&1 || true
if ls tests/*.bats 1> /dev/null 2>&1; then
docker run --rm -v "$PWD:/code" ${{ inputs.bats-image }} --formatter junit /code/tests/*.bats > "reports/${GITHUB_SHA:0:8}/bats/junit.xml" 2>&1 || true
fi
- name: Publish bats reports
shell: bash
run: |
bash .ci/scripts/publish-git-pages.sh "reports/${GITHUB_SHA:0:8}/bats"
- name: Set bats commit status
shell: bash
run: |
bash .ci/scripts/report-status.sh success \
"Bats tests" \
"https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/bats/" \
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: Run cucumber tests
id: cucumber-tests
shell: bash
run: |
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
echo "exit_code=$?" >> "${GITHUB_OUTPUT}"
- name: Publish cucumber reports
if: always()
shell: bash
run: |
bash .ci/scripts/publish-git-pages.sh "reports/${GITHUB_SHA:0:8}/cucumber"
- name: Set cucumber commit status
if: always()
shell: bash
run: |
if [ "${{ steps.cucumber-tests.outputs.exit_code }}" = "0" ]; then
STATUS="success"
DESC="Cucumber tests passed"
else
STATUS="failure"
DESC="Cucumber tests FAILED"
fi
bash .ci/scripts/report-status.sh "$STATUS" \
"$DESC" \
"https://${PAGES_HOST}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/cucumber/" \
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: Publish report index
shell: bash
run: |
bash .ci/scripts/publish-git-pages.sh "reports/${GITHUB_SHA:0:8}"
- 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