pipeline siivous ja testikattavuuden nosto (#9)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #9
This commit is contained in:
@@ -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