default pipeline on quality-gate (#10)
CI / Load gitea-env.conf to pipeline env (push) Successful in 12s
CI / Build & Push Artifact (push) Has been skipped
ci-build Build complete
ci-cucumber Cucumber tests
ci-bats Bats tests
CI / Quality Gate (push) Failing after 1m59s

Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #10
This commit is contained in:
2026-06-14 08:43:19 +03:00
parent c422825bf0
commit 3d45b08f70
9 changed files with 506 additions and 151 deletions
+124
View File
@@ -0,0 +1,124 @@
name: Build & Publish Artifact
on:
workflow_call:
inputs:
env_json:
required: true
type: string
bats-image:
required: true
type: string
cucumber-node-image:
required: true
type: string
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:
check:
runs-on: ubuntu-latest
outputs:
artifact_exists: ${{ steps.check.outputs.artifact_exists }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Check existing artifact
id: check
run: |
VERSION=$(jq -r '.version' package.json)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
TAG=$(curl -s "$GITEA_API_URL/api/v1/repos/$GITHUB_REPOSITORY/tags" | \
jq -r '.[] | select(.commit.sha == "'"$GITHUB_SHA"'") | .name' | head -1)
if [ -n "$TAG" ]; then
echo "artifact_exists=true" >> "$GITHUB_OUTPUT"
echo "Commit already tagged as $TAG, skipping build"
else
echo "artifact_exists=false" >> "$GITHUB_OUTPUT"
fi
quality-gate:
needs: [check]
if: needs.check.outputs.artifact_exists == 'false'
uses: niko/gitea-ci-library/.gitea/workflows/quality-gate.yml@main
secrets: inherit
with:
env_json: ${{ inputs.env_json }}
bats-image: ${{ inputs.bats-image }}
cucumber-node-image: ${{ inputs.cucumber-node-image }}
build:
needs: [check, quality-gate]
if: needs.check.outputs.artifact_exists == 'false'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build container
run: |
docker build -t "minimal:${{ needs.check.outputs.version }}" .
mkdir -p /tmp/image
docker save "minimal:${{ needs.check.outputs.version }}" -o /tmp/image/artifact.tar
- name: Save Docker image for next job
uses: actions/upload-artifact@v4
with:
name: docker-image
path: /tmp/image/artifact.tar
push:
needs: [check, build]
runs-on: ubuntu-latest
steps:
- name: Load saved Docker image
uses: actions/download-artifact@v4
with:
name: docker-image
path: /tmp/image
- name: Push to Gitea Packages
run: |
VERSION="${{ needs.check.outputs.version }}"
docker load -i /tmp/image/artifact.tar
REGISTRY=$(echo "$GITEA_API_URL" | sed 's|https://||')
IMAGE="$REGISTRY/niko/gitea-ci-library/minimal:$VERSION"
docker tag "minimal:$VERSION" "$IMAGE"
docker login "$REGISTRY" -u niko -p "$GITEA_TOKEN"
docker push "$IMAGE"
docker logout "$REGISTRY"
tag-commit:
needs: [check, push]
runs-on: ubuntu-latest
steps:
- name: Create git tag
run: |
VERSION="${{ needs.check.outputs.version }}"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
"$GITEA_API_URL/api/v1/repos/$GITHUB_REPOSITORY/tags" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"$VERSION\",
\"message\": \"Build #$GITHUB_RUN_NUMBER\",
\"target\": \"$GITHUB_SHA\"
}")
if [ "$HTTP_CODE" = "201" ]; then
echo "Tag $VERSION created"
elif [ "$HTTP_CODE" = "409" ]; then
echo "Tag $VERSION already exists (parallel build won), skipping"
else
echo "Failed to create tag: HTTP $HTTP_CODE"
exit 1
fi
+5 -2
View File
@@ -6,14 +6,16 @@ on:
jobs:
load-config:
name: Load gitea-env.conf to pipeline env
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
with:
config_path: .gitea/workflows/gitea-env.conf
feature:
name: Quality Gate
if: github.ref != 'refs/heads/main'
needs: [load-config]
uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@main
uses: niko/gitea-ci-library/.gitea/workflows/quality-gate.yml@main
secrets: inherit
with:
env_json: ${{ needs.load-config.outputs.env_json }}
@@ -21,9 +23,10 @@ jobs:
cucumber-node-image: node:22
main:
name: Build & Push Artifact
if: github.ref == 'refs/heads/main'
needs: [load-config]
uses: niko/gitea-ci-library/.gitea/workflows/build-feature.yml@main
uses: niko/gitea-ci-library/.gitea/workflows/build_publish-artifact.yml@main
secrets: inherit
with:
env_json: ${{ needs.load-config.outputs.env_json }}
@@ -1,4 +1,4 @@
name: Build Feature
name: Quality Gate
on:
workflow_call:
inputs:
@@ -56,9 +56,7 @@ jobs:
docker run --rm \
-v bats-workspace:/data \
--entrypoint bash ${{ inputs.bats-image }} \
-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/' \
-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"
@@ -91,53 +89,32 @@ jobs:
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
apt-get update -qq && apt-get install -y -qq --no-install-recommends lsof jq
npm install @cucumber/cucumber > /dev/null 2>&1
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}"
STATE="success"
[ "${CUCUMBER_EXIT}" != "0" ] && STATE="failure"
if [ -f "reports/${GITHUB_SHA:0:8}/cucumber/index.html" ]; then
bash .ci/scripts/report-status.sh "${STATE}" "Cucumber tests" ci-cucumber cucumber
else
bash .ci/scripts/report-status.sh "${STATE}" "Cucumber tests" ci-cucumber
fi
exit ${CUCUMBER_EXIT}
- name: Publish cucumber reports
if: always()
run: |
if [ "${TOOL_OK}" = "true" ]; then
bash .ci/scripts/publish-git-pages.sh cucumber
fi
- name: Set cucumber commit status
if: always()
run: |
if [ "${TOOL_OK}" != "true" ]; then
bash .ci/scripts/report-status.sh failure "Cucumber tool unavailable" ci-cucumber
elif [ "${CUCUMBER_EXIT}" = "0" ]; then
bash .ci/scripts/report-status.sh success "Cucumber tests passed" ci-cucumber cucumber
else
bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" ci-cucumber cucumber
fi
run: bash .ci/scripts/publish-git-pages.sh cucumber
build:
runs-on: ubuntu-latest