argha
CI / Load gitea-env.conf to pipeline env (push) Successful in 12s
ci-check Build version 0.1.0 required
ci-cucumber Cucumber tests
ci-bats Bats tests
ci-build Build complete
CI / Build & Push Artifact (push) Successful in 2m29s

This commit is contained in:
moilanik
2026-06-14 14:07:13 +03:00
parent 95f0aca47e
commit 2d3fd96768
2 changed files with 41 additions and 39 deletions
+23 -24
View File
@@ -22,6 +22,7 @@ env:
GIT_PAGES_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_URL }} GIT_PAGES_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_URL }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }} GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }}
REPO: ${{ github.repository }}
jobs: jobs:
check: check:
@@ -32,23 +33,25 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Pending
run: bash scripts/report-status.sh pending "Checking version..." ci-check
- name: Check existing artifact - name: Check existing artifact
id: check id: check
run: | run: |
bash scripts/report-status.sh pending "Checking version..." ci-check-running
VERSION=$(jq -r '.version' package.json) VERSION=$(jq -r '.version' package.json)
echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "version=$VERSION" >> "$GITHUB_OUTPUT"
TAGS_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" \ TAGS_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_API_URL/api/v1/repos/${{ github.repository }}/tags" 2>&1) "$GITEA_API_URL/api/v1/repos/$REPO/tags" 2>&1)
CURL_EXIT=$? CURL_EXIT=$?
if [ "${CURL_EXIT}" != "0" ]; then if [ "${CURL_EXIT}" != "0" ]; then
echo "ERROR: curl failed with exit code ${CURL_EXIT}" >&2 echo "ERROR: curl failed with exit code ${CURL_EXIT}" >&2
echo "artifact_exists=false" >> "$GITHUB_OUTPUT" echo "artifact_exists=false" >> "$GITHUB_OUTPUT"
exit ${CURL_EXIT} exit ${CURL_EXIT}
fi fi
TAG=$(echo "$TAGS_JSON" | jq -r 'if type == "array" then .[] | select(.commit.sha == "'"$GITHUB_SHA"'") | .name else empty end' | head -1) TAG=$(echo "$TAGS_JSON" | jq -r 'if type == "array" then .[] | select(.commit.sha == "'"$GITHUB_SHA"'") | .name else empty end' | head -1)
if [ -n "$TAG" ]; then if [ -n "$TAG" ]; then
echo "artifact_exists=true" >> "$GITHUB_OUTPUT" echo "artifact_exists=true" >> "$GITHUB_OUTPUT"
@@ -59,21 +62,19 @@ jobs:
echo "Build required: no tag for this commit" echo "Build required: no tag for this commit"
fi fi
- name: Report check status - name: Report status
if: always() if: always()
run: | run: |
VERSION="${{ steps.check.outputs.version }}" VERSION="${{ steps.check.outputs.version }}"
ARTIFACT_EXISTS="${{ steps.check.outputs.artifact_exists }}" ARTIFACT_EXISTS="${{ steps.check.outputs.artifact_exists }}"
ARTIFACT_TAG="${{ steps.check.outputs.artifact_tag }}" ARTIFACT_TAG="${{ steps.check.outputs.artifact_tag }}"
if [ "${{ steps.check.outcome }}" = "success" ]; then if [ "${{ steps.check.outcome }}" = "success" ]; then
bash scripts/report-status.sh success "Checking version..." ci-check-running
if [ "${ARTIFACT_EXISTS}" = "true" ]; then if [ "${ARTIFACT_EXISTS}" = "true" ]; then
bash scripts/report-status.sh success "Skip build: version $VERSION exists as $ARTIFACT_TAG" ci-check bash scripts/report-status.sh success "Skip build: version $VERSION exists as $ARTIFACT_TAG" ci-check
else else
bash scripts/report-status.sh success "Build version $VERSION required" ci-check bash scripts/report-status.sh success "Build version $VERSION required" ci-check
fi fi
else else
bash scripts/report-status.sh failure "Checking version..." ci-check-running
bash scripts/report-status.sh failure "Check version $VERSION FAILED" ci-check bash scripts/report-status.sh failure "Check version $VERSION FAILED" ci-check
exit 1 exit 1
fi fi
@@ -104,11 +105,13 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Pending
run: bash scripts/report-status.sh pending "Building Docker image..." ci-docker-build
- name: Build container - name: Build container
shell: bash shell: bash
id: build id: build
run: | run: |
bash scripts/report-status.sh pending "Building Docker image..." ci-docker-build-running
VERSION="${{ needs.check.outputs.version }}" VERSION="${{ needs.check.outputs.version }}"
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ) NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
docker build \ docker build \
@@ -118,16 +121,14 @@ jobs:
-t "minimal:${VERSION}" . -t "minimal:${VERSION}" .
echo "exit-code=$?" >> "$GITHUB_OUTPUT" echo "exit-code=$?" >> "$GITHUB_OUTPUT"
- name: Report docker build status - name: Report status
if: always() if: always()
run: | run: |
VERSION="${{ needs.check.outputs.version }}" VERSION="${{ needs.check.outputs.version }}"
BUILD_EXIT="${{ steps.build.outputs.exit-code }}" BUILD_EXIT="${{ steps.build.outputs.exit-code }}"
if [ "${BUILD_EXIT}" = "0" ]; then if [ "${BUILD_EXIT}" = "0" ]; then
bash scripts/report-status.sh success "Building Docker image..." ci-docker-build-running
bash scripts/report-status.sh success "Docker build $VERSION OK" ci-docker-build bash scripts/report-status.sh success "Docker build $VERSION OK" ci-docker-build
else else
bash scripts/report-status.sh failure "Building Docker image..." ci-docker-build-running
bash scripts/report-status.sh failure "Docker build $VERSION FAILED" ci-docker-build bash scripts/report-status.sh failure "Docker build $VERSION FAILED" ci-docker-build
fi fi
exit ${BUILD_EXIT} exit ${BUILD_EXIT}
@@ -165,11 +166,13 @@ jobs:
name: docker-image name: docker-image
path: /tmp/image path: /tmp/image
- name: Pending
run: bash scripts/report-status.sh pending "Pushing to registry..." ci-docker-push
- name: Push to Gitea Packages - name: Push to Gitea Packages
shell: bash shell: bash
id: push id: push
run: | run: |
bash scripts/report-status.sh pending "Pushing to registry..." ci-docker-push-running
VERSION="${{ needs.check.outputs.version }}" VERSION="${{ needs.check.outputs.version }}"
docker load -i /tmp/image/artifact.tar docker load -i /tmp/image/artifact.tar
REGISTRY=$(echo "$GITEA_API_URL" | sed 's|https://||') REGISTRY=$(echo "$GITEA_API_URL" | sed 's|https://||')
@@ -180,16 +183,14 @@ jobs:
docker logout "$REGISTRY" > /dev/null 2>&1 docker logout "$REGISTRY" > /dev/null 2>&1
echo "exit-code=$?" >> "$GITHUB_OUTPUT" echo "exit-code=$?" >> "$GITHUB_OUTPUT"
- name: Report docker push status - name: Report status
if: always() if: always()
run: | run: |
VERSION="${{ needs.check.outputs.version }}" VERSION="${{ needs.check.outputs.version }}"
PUSH_EXIT="${{ steps.push.outputs.exit-code }}" PUSH_EXIT="${{ steps.push.outputs.exit-code }}"
if [ "${PUSH_EXIT}" = "0" ]; then if [ "${PUSH_EXIT}" = "0" ]; then
bash scripts/report-status.sh success "Pushing to registry..." ci-docker-push-running
bash scripts/report-status.sh success "Docker push $VERSION OK" ci-docker-push bash scripts/report-status.sh success "Docker push $VERSION OK" ci-docker-push
else else
bash scripts/report-status.sh failure "Pushing to registry..." ci-docker-push-running
bash scripts/report-status.sh failure "Docker push $VERSION FAILED" ci-docker-push bash scripts/report-status.sh failure "Docker push $VERSION FAILED" ci-docker-push
fi fi
exit ${PUSH_EXIT} exit ${PUSH_EXIT}
@@ -200,14 +201,18 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Pending
run: bash scripts/report-status.sh pending "Creating tag..." ci-docker-tag
- name: Create git tag - name: Create git tag
shell: bash shell: bash
id: tag id: tag
env:
REPO: ${{ github.repository }}
run: | run: |
bash scripts/report-status.sh pending "Creating tag..." ci-docker-tag-running
VERSION="${{ needs.check.outputs.version }}" VERSION="${{ needs.check.outputs.version }}"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
"$GITEA_API_URL/api/v1/repos/${{ github.repository }}/tags" \ "$GITEA_API_URL/api/v1/repos/$REPO/tags" \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{ -d "{
@@ -219,29 +224,23 @@ jobs:
if [ "$HTTP_CODE" = "201" ]; then if [ "$HTTP_CODE" = "201" ]; then
echo "Tag $VERSION created" echo "Tag $VERSION created"
echo "status=success" >> "$GITHUB_OUTPUT" echo "status=success" >> "$GITHUB_OUTPUT"
echo "message=Tag $VERSION created" >> "$GITHUB_OUTPUT"
elif [ "$HTTP_CODE" = "409" ]; then elif [ "$HTTP_CODE" = "409" ]; then
echo "Tag $VERSION already exists (parallel build won), skipping" echo "Tag $VERSION already exists (parallel build won), skipping"
echo "status=success" >> "$GITHUB_OUTPUT" echo "status=success" >> "$GITHUB_OUTPUT"
echo "message=Tag exists" >> "$GITHUB_OUTPUT"
else else
echo "status=failure" >> "$GITHUB_OUTPUT" echo "status=failure" >> "$GITHUB_OUTPUT"
echo "message=Tag FAILED HTTP $HTTP_CODE" >> "$GITHUB_OUTPUT"
echo "exit-code=$HTTP_CODE" >> "$GITHUB_OUTPUT" echo "exit-code=$HTTP_CODE" >> "$GITHUB_OUTPUT"
fi fi
- name: Report docker tag status - name: Report status
if: always() if: always()
run: | run: |
VERSION="${{ needs.check.outputs.version }}" VERSION="${{ needs.check.outputs.version }}"
TAG_STATUS="${{ steps.tag.outputs.status }}" TAG_STATUS="${{ steps.tag.outputs.status }}"
TAG_MESSAGE="${{ steps.tag.outputs.message }}"
if [ "${TAG_STATUS}" = "success" ]; then if [ "${TAG_STATUS}" = "success" ]; then
bash scripts/report-status.sh success "Creating tag..." ci-docker-tag-running
bash scripts/report-status.sh success "Tag $VERSION OK" ci-docker-tag bash scripts/report-status.sh success "Tag $VERSION OK" ci-docker-tag
else else
TAG_EXIT="${{ steps.tag.outputs.exit-code }}" TAG_EXIT="${{ steps.tag.outputs.exit-code }}"
bash scripts/report-status.sh failure "Creating tag..." ci-docker-tag-running
bash scripts/report-status.sh failure "Tag $VERSION FAILED" ci-docker-tag bash scripts/report-status.sh failure "Tag $VERSION FAILED" ci-docker-tag
exit ${TAG_EXIT} exit ${TAG_EXIT}
fi fi
+18 -15
View File
@@ -33,13 +33,14 @@ jobs:
repository: niko/gitea-ci-library repository: niko/gitea-ci-library
path: .ci path: .ci
- name: Pending
run: bash .ci/scripts/report-status.sh pending "Validating CI config..." ci-validate
- name: Validate CI config - name: Validate CI config
id: validate id: validate
run: | run: bash .ci/scripts/ci-validate.sh
bash .ci/scripts/report-status.sh pending "Validating CI config..." ci-validate-running
bash .ci/scripts/ci-validate.sh
- name: Report validate status - name: Report status
if: always() if: always()
run: | run: |
if [ "${{ steps.validate.outcome }}" = "success" ]; then if [ "${{ steps.validate.outcome }}" = "success" ]; then
@@ -58,11 +59,13 @@ jobs:
repository: niko/gitea-ci-library repository: niko/gitea-ci-library
path: .ci path: .ci
- name: Pending
run: bash .ci/scripts/report-status.sh pending "Running Bats tests..." ci-bats
- name: Run bats tests - name: Run bats tests
id: bats-tests id: bats-tests
shell: bash shell: bash
run: | run: |
bash .ci/scripts/report-status.sh pending "Running Bats tests..." ci-bats-running
docker volume create bats-workspace docker volume create bats-workspace
tar c . | docker run --rm -i -v bats-workspace:/data alpine tar x -C /data tar c . | docker run --rm -i -v bats-workspace:/data alpine tar x -C /data
mkdir -p "reports/${GITHUB_SHA:0:8}/bats" mkdir -p "reports/${GITHUB_SHA:0:8}/bats"
@@ -83,7 +86,7 @@ jobs:
if: always() if: always()
run: bash .ci/scripts/publish-git-pages.sh bats run: bash .ci/scripts/publish-git-pages.sh bats
- name: Set bats commit status - name: Report status
if: always() if: always()
run: | run: |
if [ "${BATS_EXIT}" = "0" ]; then if [ "${BATS_EXIT}" = "0" ]; then
@@ -103,11 +106,13 @@ jobs:
repository: niko/gitea-ci-library repository: niko/gitea-ci-library
path: .ci path: .ci
- name: Pending
run: bash .ci/scripts/report-status.sh pending "Running Cucumber tests..." ci-cucumber
- name: Run cucumber tests - name: Run cucumber tests
id: cucumber-tests id: cucumber-tests
shell: bash shell: bash
run: | run: |
bash .ci/scripts/report-status.sh pending "Running Cucumber tests..." ci-cucumber-running
apt-get update -qq && apt-get install -y -qq --no-install-recommends lsof jq apt-get update -qq && apt-get install -y -qq --no-install-recommends lsof jq
npm install @cucumber/cucumber > /dev/null 2>&1 npm install @cucumber/cucumber > /dev/null 2>&1
mkdir -p "reports/${GITHUB_SHA:0:8}/cucumber" mkdir -p "reports/${GITHUB_SHA:0:8}/cucumber"
@@ -123,7 +128,7 @@ jobs:
if: always() if: always()
run: bash .ci/scripts/publish-git-pages.sh cucumber run: bash .ci/scripts/publish-git-pages.sh cucumber
- name: Set cucumber commit status - name: Report status
if: always() if: always()
run: | run: |
if [ "${CUCUMBER_EXIT}" = "0" ]; then if [ "${CUCUMBER_EXIT}" = "0" ]; then
@@ -133,7 +138,6 @@ jobs:
bash .ci/scripts/report-status.sh success "Cucumber tests OK" ci-cucumber bash .ci/scripts/report-status.sh success "Cucumber tests OK" ci-cucumber
fi fi
else else
bash .ci/scripts/report-status.sh failure "Running Cucumber tests..." ci-cucumber-running
if [ -f "reports/${GITHUB_SHA:0:8}/cucumber/index.html" ]; then if [ -f "reports/${GITHUB_SHA:0:8}/cucumber/index.html" ]; then
bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" ci-cucumber cucumber bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" ci-cucumber cucumber
else else
@@ -151,20 +155,19 @@ jobs:
repository: niko/gitea-ci-library repository: niko/gitea-ci-library
path: .ci path: .ci
- name: Pending
run: bash .ci/scripts/report-status.sh pending "Generating report index..." ci-build
- name: Generate report index - name: Generate report index
id: report-index id: report-index
run: | run: bash .ci/.gitea/scripts/generate-report-index.sh
bash .ci/scripts/report-status.sh pending "Generating report index..." ci-build-running
bash .ci/.gitea/scripts/generate-report-index.sh
- name: Set build commit status - name: Report status
if: always() if: always()
run: | run: |
if [ "${{ steps.report-index.outcome }}" = "success" ]; then if [ "${{ steps.report-index.outcome }}" = "success" ]; then
bash .ci/scripts/report-status.sh success "Generating report index..." ci-build-running
bash .ci/scripts/report-status.sh success "Build complete" ci-build bash .ci/scripts/report-status.sh success "Build complete" ci-build
else else
bash .ci/scripts/report-status.sh failure "Generating report index..." ci-build-running
bash .ci/scripts/report-status.sh failure "Build FAILED" ci-build bash .ci/scripts/report-status.sh failure "Build FAILED" ci-build
exit 1 exit 1
fi fi