70 lines
2.6 KiB
YAML
70 lines
2.6 KiB
YAML
name: MindSift CI & Docker Release
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- dev
|
||
- main
|
||
tags:
|
||
- 'v*'
|
||
|
||
jobs:
|
||
build-test-push:
|
||
name: Build, Test in Container & Push
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Login to Gitea Container Registry
|
||
uses: docker/login-action@v3
|
||
with:
|
||
registry: ${{ vars.REGISTRY_HOST || 'git.dsit.me' }}
|
||
username: ${{ github.actor }}
|
||
password: ${{ secrets.PUSH_TOKEN || secrets.GITEA_TOKEN || github.token }}
|
||
|
||
- name: Calculate Build Plan
|
||
id: plan
|
||
run: |
|
||
SERVER_URL="${GITHUB_SERVER_URL:-https://git.dsit.me}"
|
||
REGISTRY_HOST=$(echo "${SERVER_URL}" | sed -E 's#^https?://##' | sed 's#/$##')
|
||
[ -z "${REGISTRY_HOST}" ] && REGISTRY_HOST="git.dsit.me"
|
||
REPO_PATH="${GITHUB_REPOSITORY:-sandrodach/mindsift}"
|
||
IMAGE_NAME=$(echo "${REGISTRY_HOST}/${REPO_PATH}" | tr '[:upper:]' '[:lower:]')
|
||
|
||
echo "registry=${REGISTRY_HOST}" >> "$GITHUB_OUTPUT"
|
||
echo "image=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
|
||
|
||
REF="${GITHUB_REF:-}" COMMIT="${GITHUB_SHA:-HEAD}" IMAGE="${IMAGE_NAME}" .gitea/scripts/build-plan.sh
|
||
|
||
- name: Execute Build or Retag & Push
|
||
run: |
|
||
IMAGE="${{ steps.plan.outputs.image }}"
|
||
ACTION="${{ steps.plan.outputs.action }}"
|
||
TAGS="${{ steps.plan.outputs.tags }}"
|
||
|
||
if [ "${ACTION}" = "retag" ]; then
|
||
SOURCE="${{ steps.plan.outputs.source_image }}"
|
||
echo "🏷️ Re-tagging existing image ${SOURCE} without rebuilding (Reason: ${{ steps.plan.outputs.reason }})"
|
||
docker pull "${SOURCE}"
|
||
for t in ${TAGS}; do
|
||
docker tag "${SOURCE}" "${IMAGE}:${t}"
|
||
docker push "${IMAGE}:${t}"
|
||
done
|
||
else
|
||
SKIP_TESTS="${{ steps.plan.outputs.skip_tests }}"
|
||
APP_VERSION="${{ steps.plan.outputs.app_version }}"
|
||
TAG_ARGS=""
|
||
for t in ${TAGS}; do TAG_ARGS="${TAG_ARGS} -t ${IMAGE}:${t}"; done
|
||
|
||
echo "🚀 Building container (SKIP_TESTS=${SKIP_TESTS}, APP_VERSION=${APP_VERSION}) for tags: ${TAGS}"
|
||
echo "ℹ️ Reason: ${{ steps.plan.outputs.reason }}"
|
||
DOCKER_BUILDKIT=1 docker build --progress=plain \
|
||
--build-arg APP_VERSION="${APP_VERSION}" \
|
||
--build-arg SKIP_TESTS="${SKIP_TESTS}" \
|
||
${TAG_ARGS} .
|
||
|
||
echo "✅ Build complete! Pushing..."
|
||
for t in ${TAGS}; do docker push "${IMAGE}:${t}"; done
|
||
fi
|