test #152

Merged
hitanshu merged 7 commits from test into main 2026-07-09 06:57:21 +00:00
Showing only changes of commit 03c509c597 - Show all commits

View File

@ -7,15 +7,6 @@ on:
- test # → PATCH bump, build & tag as test - test # → PATCH bump, build & tag as test
- main # → MINOR bump, promote test→prod - main # → MINOR bump, promote test→prod
workflow_dispatch: workflow_dispatch:
inputs:
environment:
description: 'Target environment (test → PATCH bump, prod → MINOR bump)'
required: true
default: 'test'
type: choice
options:
- test
- prod
jobs: jobs:
version: version:
@ -31,15 +22,9 @@ jobs:
- name: Determine environment - name: Determine environment
id: env id: env
run: | run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
ENV="${{ inputs.environment }}"
else
# Push events: test branch → test env, main branch → prod env
[[ "${{ github.ref_name }}" == "main" ]] && ENV="prod" || ENV="${{ github.ref_name }}" [[ "${{ github.ref_name }}" == "main" ]] && ENV="prod" || ENV="${{ github.ref_name }}"
fi
# Validate
if [[ "$ENV" != "test" && "$ENV" != "prod" ]]; then if [[ "$ENV" != "test" && "$ENV" != "prod" ]]; then
echo " Invalid environment: $ENV. Must be 'test' or 'prod'." echo "→ Invalid environment: $ENV. Must be 'test' or 'prod'."
exit 1 exit 1
fi fi
echo "target_env=$ENV" >> $GITHUB_OUTPUT echo "target_env=$ENV" >> $GITHUB_OUTPUT
@ -47,8 +32,10 @@ jobs:
- name: Calculate semver bump - name: Calculate semver bump
id: semver id: semver
run: | run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") VERSION=$(git describe --tags --match "pa-*" --abbrev=0 2>/dev/null || echo "pa-0.0.0")
echo "Latest tag: ${VERSION}" echo "Latest tag: ${VERSION}"
# Strip pa- prefix
VERSION=${VERSION#pa-}
MAJOR=$(echo ${VERSION} | cut -d "." -f 1) MAJOR=$(echo ${VERSION} | cut -d "." -f 1)
MINOR=$(echo ${VERSION} | cut -d "." -f 2) MINOR=$(echo ${VERSION} | cut -d "." -f 2)
PATCH=$(echo ${VERSION} | cut -d "." -f 3) PATCH=$(echo ${VERSION} | cut -d "." -f 3)
@ -64,7 +51,7 @@ jobs:
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
echo "Test → patch bump: ${NEW_VERSION}" echo "Test → patch bump: ${NEW_VERSION}"
fi fi
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT echo "new_version=pa-${NEW_VERSION}" >> $GITHUB_OUTPUT
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -108,13 +95,13 @@ jobs:
REG="192.168.0.100:8928/hithomelabs/portainer-automation" REG="192.168.0.100:8928/hithomelabs/portainer-automation"
if [[ "$ENV" == "test" ]]; then if [[ "$ENV" == "test" ]]; then
echo "🔨 Building fresh image for test" echo " Building fresh image for test"
./gradlew :portainer-automation:bootBuildImage --imageName="${REG}:${VER}" ./gradlew :portainer-automation:bootBuildImage --imageName="${REG}:${VER}"
docker tag "${REG}:${VER}" "${REG}:test" docker tag "${REG}:${VER}" "${REG}:test"
docker push "${REG}:test" docker push "${REG}:test"
docker push "${REG}:${VER}" docker push "${REG}:${VER}"
else else
echo "♻️ Promoting test image to prod" echo " Promoting test image to prod"
docker pull "${REG}:test" docker pull "${REG}:test"
docker tag "${REG}:test" "${REG}:${VER}" docker tag "${REG}:test" "${REG}:${VER}"
docker tag "${REG}:${VER}" "${REG}:prod" docker tag "${REG}:${VER}" "${REG}:prod"