init
lint / lint (push) Failing after 10s
lint / smoke (push) Skipped

This commit is contained in:
Sherif Emad
2026-11-08 15:39:22 +02:00
commit d67d814144
12 changed files with 972 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# Calculates the next git tag for the current repo and optionally pushes it.
# Usage: auto-tag.sh
# Inputs (env vars):
# TAG_TYPE required tag prefix: dev, beta, prod, ...
# TAG_ENV optional "production" switches to <type>-<max>.<major>.<minor>
# PUSH_TAG optional "true" creates and pushes the tag (default false)
# GIT_PUSH_TOKEN optional token with write access; required when PUSH_TAG=true
# Outputs:
# stdout log, tag.env (TAG, STREAM, PREVIOUS_TAG) in the current directory,
# and TAG / STREAM / PREVIOUS_TAG written to $GITHUB_OUTPUT when it is set.
# Requires: full tag history (checkout with fetch-depth: 0).
set -euo pipefail
TAG_TYPE="${TAG_TYPE:?TAG_TYPE is required}"
TAG_ENV="${TAG_ENV:-}"
PUSH_TAG="${PUSH_TAG:-false}"
if [[ "${PUSH_TAG}" == "true" ]]; then
: "${GIT_PUSH_TOKEN:?GIT_PUSH_TOKEN is required when PUSH_TAG=true}"
fi
if [[ "${TAG_ENV}" == "production" ]]; then
PATTERN='^'"${TAG_TYPE}"'-[0-9]+\.[0-9]+\.[0-9]+$'
else
PATTERN='^'"${TAG_TYPE}"'-[0-9]+$'
fi
echo "auto-tag: type=${TAG_TYPE} env=${TAG_ENV:-<none>} push=${PUSH_TAG}"
# Latest tag with this prefix (version sort, newest first).
PREVIOUS_TAG="$(git tag --list "${TAG_TYPE}-*" | sort -V -r | sed -n 1p)"
if [[ -z "${PREVIOUS_TAG}" ]]; then
if [[ "${TAG_ENV}" == "production" ]]; then
TAG="${TAG_TYPE}-2.0.0"
else
TAG="${TAG_TYPE}-1"
fi
else
if ! [[ "${PREVIOUS_TAG}" =~ ${PATTERN} ]]; then
echo "ERROR: latest tag '${PREVIOUS_TAG}' is not in the expected format for TAG_TYPE=${TAG_TYPE} (pattern ${PATTERN})" >&2
exit 1
fi
VERSION="${PREVIOUS_TAG#"${TAG_TYPE}"-}"
if [[ "${TAG_ENV}" == "production" ]]; then
MAX="${VERSION%%.*}"
REST="${VERSION#*.}"
TAG="${TAG_TYPE}-$((MAX + 1)).${REST}"
else
TAG="${TAG_TYPE}-$((VERSION + 1))"
fi
fi
echo "previous tag: ${PREVIOUS_TAG:-<none>}"
echo "next tag: ${TAG}"
{
echo "TAG=${TAG}"
echo "STREAM=${TAG_TYPE}"
echo "PREVIOUS_TAG=${PREVIOUS_TAG}"
} > tag.env
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
cat tag.env >> "${GITHUB_OUTPUT}"
fi
if [[ "${PUSH_TAG}" == "true" ]]; then
SERVER_URL="${GITHUB_SERVER_URL:?GITHUB_SERVER_URL is required when PUSH_TAG=true}"
REPO="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required when PUSH_TAG=true}"
PROTO="${SERVER_URL%%://*}"
HOST="${SERVER_URL#*://}"
git tag "${TAG}"
git push "${PROTO}://oauth2:${GIT_PUSH_TOKEN}@${HOST}/${REPO}.git" "refs/tags/${TAG}" >/dev/null 2>&1 \
|| { echo "ERROR: failed to push tag ${TAG} (check token scope and tag protection)" >&2; exit 1; }
echo "pushed tag ${TAG}"
fi
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# Decides the next semantic-version tag for the current repo, or skips when the
# branch head is already tagged. Ports the Jenkins "Check Tags" stage.
# Usage: check-tags.sh
# Inputs (env vars):
# TAGS_VERSION required major | minor | test | cib
# major -> prefix main-v, bumps MAJOR (minor/patch reset)
# minor -> prefix dev-v, bumps MINOR (patch reset)
# test -> prefix test-v, bumps PATCH
# cib -> prefix cib-v, bumps PATCH
# BRANCH_NAME optional branch to compare against (default: $GITHUB_REF_NAME)
# Outputs:
# stdout log, tag.env (TAG, PREVIOUS_TAG, SKIP) in the current directory,
# and the same three written to $GITHUB_OUTPUT when it is set.
# TAG = the new tag, or the existing latest tag when SKIP=true
# SKIP = true when the branch head already carries the latest tag
# Requires: full history and tags (checkout with fetch-depth: 0).
# Does not create or push a tag; it only calculates it.
set -euo pipefail
TAGS_VERSION="${TAGS_VERSION:?TAGS_VERSION is required (major|minor|test|cib)}"
BRANCH_NAME="${BRANCH_NAME:-${GITHUB_REF_NAME:-}}"
BRANCH_NAME="${BRANCH_NAME:?BRANCH_NAME is required (or run inside Gitea Actions)}"
case "${TAGS_VERSION}" in
major) PREFIX="main-v" ;;
minor) PREFIX="dev-v" ;;
test) PREFIX="test-v" ;;
cib) PREFIX="cib-v" ;;
*)
echo "ERROR: TAGS_VERSION must be one of major|minor|test|cib, got '${TAGS_VERSION}'" >&2
exit 1
;;
esac
echo "check-tags: version=${TAGS_VERSION} prefix=${PREFIX} branch=${BRANCH_NAME}"
git fetch origin "${BRANCH_NAME}"
git fetch --tags --force --prune origin
PREVIOUS_TAG="$(git tag --list "${PREFIX}*" | sort -V -r | sed -n 1p)"
echo "latest tag for prefix ${PREFIX}: ${PREVIOUS_TAG:-<none>}"
LATEST_COMMIT="$(git rev-parse "origin/${BRANCH_NAME}")"
LATEST_TAG_COMMIT=""
if [[ -n "${PREVIOUS_TAG}" ]]; then
LATEST_TAG_COMMIT="$(git rev-list -n 1 "${PREVIOUS_TAG}")"
fi
if [[ "${LATEST_COMMIT}" == "${LATEST_TAG_COMMIT}" ]]; then
echo "No new commits since latest tag ${PREVIOUS_TAG}. Skipping tagging."
TAG="${PREVIOUS_TAG}"
SKIP="true"
else
echo "New commit detected. Incrementing tag..."
MAJOR=1
MINOR=0
PATCH=0
if [[ -n "${PREVIOUS_TAG}" ]]; then
if [[ "${PREVIOUS_TAG}" =~ ^${PREFIX}([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
MAJOR=$((10#${BASH_REMATCH[1]}))
MINOR=$((10#${BASH_REMATCH[2]}))
PATCH=$((10#${BASH_REMATCH[3]}))
else
echo "WARNING: latest tag '${PREVIOUS_TAG}' does not follow semantic versioning. Using defaults." >&2
fi
fi
case "${TAGS_VERSION}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
*)
PATCH=$((PATCH + 1))
;;
esac
TAG="${PREFIX}${MAJOR}.${MINOR}.${PATCH}"
SKIP="false"
echo "New tag will be: ${TAG}"
fi
{
echo "TAG=${TAG}"
echo "PREVIOUS_TAG=${PREVIOUS_TAG}"
echo "SKIP=${SKIP}"
} > tag.env
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
cat tag.env >> "${GITHUB_OUTPUT}"
fi
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Prints a greeting and basic CI info.
# Usage: hello.sh [name]
# Inputs (args): name (optional, default "world")
# Outputs: greeting on stdout
set -euo pipefail
NAME="${1:-world}"
echo "Hello, ${NAME}!"
echo "repository: ${GITHUB_REPOSITORY:-unknown}"
echo "ref: ${GITHUB_REF:-unknown}"
echo "sha: ${GITHUB_SHA:-unknown}"
echo "run id: ${GITHUB_RUN_ID:-unknown}"
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Prints a notification line (stub: replace with a webhook call later).
# Usage: notify.sh <status> <message>
# Inputs (args): status (required), message (required)
# Outputs: one line on stdout
set -euo pipefail
STATUS="${1:?usage: notify.sh <status> <message>}"
MESSAGE="${2:?usage: notify.sh <status> <message>}"
echo "[notify] ${STATUS}: ${MESSAGE} (${GITHUB_REPOSITORY:-unknown} @ ${GITHUB_SHA:-unknown})"