Files
gitea-ci-library/.gitea/workflows/check-version.yml
T
moilanik 504462b21e
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 27s
unit-tests Link to Bats reports
CI Feature / Bats tests (push) Successful in 1m40s
acc-tests Link to Cucumber reports
CI Feature / Cucumber tests (push) Successful in 1m7s
CI Feature / Report Summary (push) Successful in 5s
consumer project käyttöönotossa tulleitea muutoksia
2026-06-16 04:31:05 +03:00

74 lines
2.6 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_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
- name: Check existing artifact and calculate version
run: |
if [ -f VERSION ]; then
RAW_VERSION=$(cat VERSION | tr -d '[:space:]')
elif [ -f package.json ]; then
RAW_VERSION=$(jq -r '.version' package.json)
elif [ -f pom.xml ]; then
RAW_VERSION=$(grep -oP '<version>\K[^<]+' pom.xml | head -1)
else
echo "ERROR: No VERSION file, package.json, or pom.xml found" >&2
exit 1
fi
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"