diff --git a/.gitea/workflows/build_publish-artifact.yml b/.gitea/workflows/build_publish-artifact.yml index 464311b..e59843c 100644 --- a/.gitea/workflows/build_publish-artifact.yml +++ b/.gitea/workflows/build_publish-artifact.yml @@ -22,6 +22,7 @@ env: GIT_PAGES_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_URL }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }} + REPO: ${{ github.repository }} jobs: check: @@ -32,23 +33,25 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Pending + run: bash scripts/report-status.sh pending "Checking version..." ci-check + - name: Check existing artifact id: check run: | - bash scripts/report-status.sh pending "Checking version..." ci-check-running VERSION=$(jq -r '.version' package.json) echo "version=$VERSION" >> "$GITHUB_OUTPUT" 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=$? - + if [ "${CURL_EXIT}" != "0" ]; then echo "ERROR: curl failed with exit code ${CURL_EXIT}" >&2 echo "artifact_exists=false" >> "$GITHUB_OUTPUT" exit ${CURL_EXIT} fi - + 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 echo "artifact_exists=true" >> "$GITHUB_OUTPUT" @@ -59,21 +62,19 @@ jobs: echo "Build required: no tag for this commit" fi - - name: Report check status + - name: Report status if: always() run: | VERSION="${{ steps.check.outputs.version }}" ARTIFACT_EXISTS="${{ steps.check.outputs.artifact_exists }}" ARTIFACT_TAG="${{ steps.check.outputs.artifact_tag }}" if [ "${{ steps.check.outcome }}" = "success" ]; then - bash scripts/report-status.sh success "Checking version..." ci-check-running if [ "${ARTIFACT_EXISTS}" = "true" ]; then bash scripts/report-status.sh success "Skip build: version $VERSION exists as $ARTIFACT_TAG" ci-check else bash scripts/report-status.sh success "Build version $VERSION required" ci-check fi else - bash scripts/report-status.sh failure "Checking version..." ci-check-running bash scripts/report-status.sh failure "Check version $VERSION FAILED" ci-check exit 1 fi @@ -104,11 +105,13 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Pending + run: bash scripts/report-status.sh pending "Building Docker image..." ci-docker-build + - name: Build container shell: bash id: build run: | - bash scripts/report-status.sh pending "Building Docker image..." ci-docker-build-running VERSION="${{ needs.check.outputs.version }}" NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ) docker build \ @@ -118,16 +121,14 @@ jobs: -t "minimal:${VERSION}" . echo "exit-code=$?" >> "$GITHUB_OUTPUT" - - name: Report docker build status + - name: Report status if: always() run: | VERSION="${{ needs.check.outputs.version }}" BUILD_EXIT="${{ steps.build.outputs.exit-code }}" 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 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 fi exit ${BUILD_EXIT} @@ -165,11 +166,13 @@ jobs: name: docker-image path: /tmp/image + - name: Pending + run: bash scripts/report-status.sh pending "Pushing to registry..." ci-docker-push + - name: Push to Gitea Packages shell: bash id: push run: | - bash scripts/report-status.sh pending "Pushing to registry..." ci-docker-push-running VERSION="${{ needs.check.outputs.version }}" docker load -i /tmp/image/artifact.tar REGISTRY=$(echo "$GITEA_API_URL" | sed 's|https://||') @@ -180,16 +183,14 @@ jobs: docker logout "$REGISTRY" > /dev/null 2>&1 echo "exit-code=$?" >> "$GITHUB_OUTPUT" - - name: Report docker push status + - name: Report status if: always() run: | VERSION="${{ needs.check.outputs.version }}" PUSH_EXIT="${{ steps.push.outputs.exit-code }}" 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 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 fi exit ${PUSH_EXIT} @@ -200,14 +201,18 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Pending + run: bash scripts/report-status.sh pending "Creating tag..." ci-docker-tag + - name: Create git tag shell: bash id: tag + env: + REPO: ${{ github.repository }} run: | - bash scripts/report-status.sh pending "Creating tag..." ci-docker-tag-running 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" \ + "$GITEA_API_URL/api/v1/repos/$REPO/tags" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{ @@ -219,29 +224,23 @@ jobs: if [ "$HTTP_CODE" = "201" ]; then echo "Tag $VERSION created" echo "status=success" >> "$GITHUB_OUTPUT" - echo "message=Tag $VERSION created" >> "$GITHUB_OUTPUT" elif [ "$HTTP_CODE" = "409" ]; then echo "Tag $VERSION already exists (parallel build won), skipping" echo "status=success" >> "$GITHUB_OUTPUT" - echo "message=Tag exists" >> "$GITHUB_OUTPUT" else echo "status=failure" >> "$GITHUB_OUTPUT" - echo "message=Tag FAILED HTTP $HTTP_CODE" >> "$GITHUB_OUTPUT" echo "exit-code=$HTTP_CODE" >> "$GITHUB_OUTPUT" fi - - name: Report docker tag status + - name: Report status if: always() run: | VERSION="${{ needs.check.outputs.version }}" TAG_STATUS="${{ steps.tag.outputs.status }}" - TAG_MESSAGE="${{ steps.tag.outputs.message }}" 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 else 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 exit ${TAG_EXIT} fi diff --git a/.gitea/workflows/quality-gate.yml b/.gitea/workflows/quality-gate.yml index 7526f62..2176364 100644 --- a/.gitea/workflows/quality-gate.yml +++ b/.gitea/workflows/quality-gate.yml @@ -33,13 +33,14 @@ jobs: repository: niko/gitea-ci-library path: .ci + - name: Pending + run: bash .ci/scripts/report-status.sh pending "Validating CI config..." ci-validate + - name: Validate CI config id: validate - run: | - bash .ci/scripts/report-status.sh pending "Validating CI config..." ci-validate-running - bash .ci/scripts/ci-validate.sh + run: bash .ci/scripts/ci-validate.sh - - name: Report validate status + - name: Report status if: always() run: | if [ "${{ steps.validate.outcome }}" = "success" ]; then @@ -58,11 +59,13 @@ jobs: repository: niko/gitea-ci-library path: .ci + - name: Pending + run: bash .ci/scripts/report-status.sh pending "Running Bats tests..." ci-bats + - name: Run bats tests id: bats-tests shell: bash run: | - bash .ci/scripts/report-status.sh pending "Running Bats tests..." ci-bats-running 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" @@ -83,7 +86,7 @@ jobs: if: always() run: bash .ci/scripts/publish-git-pages.sh bats - - name: Set bats commit status + - name: Report status if: always() run: | if [ "${BATS_EXIT}" = "0" ]; then @@ -103,11 +106,13 @@ jobs: repository: niko/gitea-ci-library path: .ci + - name: Pending + run: bash .ci/scripts/report-status.sh pending "Running Cucumber tests..." ci-cucumber + - name: Run cucumber tests id: cucumber-tests shell: bash 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 npm install @cucumber/cucumber > /dev/null 2>&1 mkdir -p "reports/${GITHUB_SHA:0:8}/cucumber" @@ -123,7 +128,7 @@ jobs: if: always() run: bash .ci/scripts/publish-git-pages.sh cucumber - - name: Set cucumber commit status + - name: Report status if: always() run: | if [ "${CUCUMBER_EXIT}" = "0" ]; then @@ -133,7 +138,6 @@ jobs: bash .ci/scripts/report-status.sh success "Cucumber tests OK" ci-cucumber fi 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 bash .ci/scripts/report-status.sh failure "Cucumber tests FAILED" ci-cucumber cucumber else @@ -151,20 +155,19 @@ jobs: repository: niko/gitea-ci-library path: .ci + - name: Pending + run: bash .ci/scripts/report-status.sh pending "Generating report index..." ci-build + - name: Generate report index id: report-index - run: | - bash .ci/scripts/report-status.sh pending "Generating report index..." ci-build-running - bash .ci/.gitea/scripts/generate-report-index.sh + run: bash .ci/.gitea/scripts/generate-report-index.sh - - name: Set build commit status + - name: Report status if: always() run: | 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 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 exit 1 fi