30cd407018
- ci.yml: pure dispatch (Feature → ci-feature, Main → ci-main), 18 lines - ci-feature.yml (new): load-config → quality-gate - ci-main.yml (new): load-config → check-version → quality-gate → docker-build-push - check-version.yml (new): provider workflow for artifact existence check and version calculation - docker-build-push.yml (renamed from build_publish-artifact.yml): - removed check job, quality-gate block, gatekeeper logic, build-context artifact - version passed as input, simplified needs chain (build → push → tag-commit) - fixed consumer→provider checkout pattern (.ci/scripts/)
89 lines
3.2 KiB
YAML
89 lines
3.2 KiB
YAML
name: Check Existing Artifact
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
env_json:
|
|
required: true
|
|
type: string
|
|
secrets:
|
|
GITEA_TOKEN:
|
|
required: true
|
|
outputs:
|
|
artifact_exists:
|
|
value: ${{ jobs.check.outputs.artifact_exists }}
|
|
version:
|
|
value: ${{ jobs.check.outputs.version }}
|
|
|
|
env:
|
|
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
jobs:
|
|
check:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
artifact_exists: ${{ steps.set-outputs.outputs.artifact_exists }}
|
|
version: ${{ steps.set-outputs.outputs.version }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
repository: niko/gitea-ci-library
|
|
path: .ci
|
|
|
|
- name: Set Gitea status to PENDING
|
|
run: |
|
|
echo "===== gitea-ci-library - Check existing artifact | begin ====="
|
|
bash .ci/scripts/report-status.sh pending "Checking version..." ci-check
|
|
|
|
- name: Check existing artifact and calculate version
|
|
run: |
|
|
RAW_VERSION=$(jq -r '.version' package.json)
|
|
BASE_VERSION=$(echo "$RAW_VERSION" | cut -d'.' -f1-2)
|
|
echo "gitea-ci-library - Tunnistettu Major.Minor versio: $BASE_VERSION"
|
|
|
|
TAGS_JSON=$(curl -s -f -H "Authorization: token $GITEA_TOKEN" \
|
|
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/tags")
|
|
|
|
TAG=$(echo "$TAGS_JSON" | jq -r 'if type == "array" then .[] | select(.commit.sha == "${{ github.sha }}") | .name else empty end' | head -1)
|
|
|
|
mkdir -p /tmp/build-ctx
|
|
|
|
if [ -n "$TAG" ]; then
|
|
echo "ARTIFACT_EXISTS=true" > /tmp/build-ctx/build.env
|
|
echo "NEXT_VERSION=$TAG" >> /tmp/build-ctx/build.env
|
|
echo "gitea-ci-library - Artefakti löytyi jo tagilla: $TAG."
|
|
else
|
|
echo "ARTIFACT_EXISTS=false" > /tmp/build-ctx/build.env
|
|
|
|
HIGHEST_PATCH=$(echo "$TAGS_JSON" | jq -r --arg bv "$BASE_VERSION." '
|
|
if type == "array" then .[] | .name | select(startswith($bv)) | sub($bv; "") | tonumber else empty end' | sort -rn | head -1)
|
|
|
|
if [ -z "$HIGHEST_PATCH" ]; then NEXT_PATCH=0; else NEXT_PATCH=$((HIGHEST_PATCH + 1)); fi
|
|
FULL_VERSION="${BASE_VERSION}.${NEXT_PATCH}"
|
|
|
|
echo "NEXT_VERSION=$FULL_VERSION" >> /tmp/build-ctx/build.env
|
|
echo "gitea-ci-library - Uusi vapaa versio: $FULL_VERSION"
|
|
fi
|
|
|
|
- name: Set job outputs
|
|
id: set-outputs
|
|
run: |
|
|
source /tmp/build-ctx/build.env
|
|
echo "artifact_exists=$ARTIFACT_EXISTS" >> "$GITHUB_OUTPUT"
|
|
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Set Gitea status to SUCCESS
|
|
if: success()
|
|
run: |
|
|
source /tmp/build-ctx/build.env
|
|
if [ "${ARTIFACT_EXISTS}" = "true" ]; then
|
|
bash .ci/scripts/report-status.sh success "Skip build: version $NEXT_VERSION exists" ci-check
|
|
else
|
|
bash .ci/scripts/report-status.sh success "Build version $NEXT_VERSION required" ci-check
|
|
fi
|
|
|
|
- name: Set Gitea status to FAILURE
|
|
if: failure()
|
|
run: bash .ci/scripts/report-status.sh failure "Check version FAILED" ci-check
|