Implement automatic versioning and display in the application
- Added a step in the CI/CD pipeline to generate a version based on the branch and commit history. - Updated Dockerfile to accept the application version as an argument. - Modified the configuration to retrieve the application version from the environment variable. - Created a new API endpoint to expose the application version. - Added a new Svelte component to display the application version in the UI.
This commit is contained in:
@@ -13,6 +13,60 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout código
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Necesario para obtener el historial completo de git
|
||||
|
||||
# ------------------------
|
||||
# Generar versión automática
|
||||
# ------------------------
|
||||
- name: Generar versión automática
|
||||
id: version
|
||||
run: |
|
||||
# Obtener año y mes actual
|
||||
YEAR=$(date +%y)
|
||||
MONTH=$(date +%m)
|
||||
|
||||
# Detectar rama actual usando variables de Gitea
|
||||
BRANCH="${GITHUB_REF##*/}"
|
||||
|
||||
if [ "$BRANCH" = "development" ]; then
|
||||
# Para development: YY.MM.1.<short-git-hash>
|
||||
SHORT_HASH=$(git rev-parse --short=8 HEAD)
|
||||
VERSION="${YEAR}.${MONTH}.${{ secrets.VERSION_MAYOR }}.${SHORT_HASH}"
|
||||
elif [ "$BRANCH" = "main" ]; then
|
||||
# Para main: YY.MM.0.<commit-count>
|
||||
# Intentar obtener el último tag
|
||||
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
||||
|
||||
if [ -z "$LAST_TAG" ]; then
|
||||
# No hay tags, usar commit count total (primera ejecución)
|
||||
COMMIT_COUNT=$(git rev-list --count HEAD)
|
||||
echo "⚠️ No se encontraron tags. Usando commit count total: ${COMMIT_COUNT}"
|
||||
else
|
||||
# Hay tags, contar commits desde el último tag
|
||||
COMMIT_COUNT=$(git rev-list ${LAST_TAG}..HEAD --count)
|
||||
# Si es 0, significa que estamos en el mismo commit del tag, incrementar
|
||||
if [ "$COMMIT_COUNT" -eq 0 ]; then
|
||||
COMMIT_COUNT=1
|
||||
fi
|
||||
echo "📌 Último tag: ${LAST_TAG}"
|
||||
echo "🔢 Commits desde el último tag: ${COMMIT_COUNT}"
|
||||
fi
|
||||
|
||||
VERSION="${YEAR}.${MONTH}.${{ secrets.VERSION_MAYOR }}.${COMMIT_COUNT}"
|
||||
else
|
||||
# Fallback para otras ramas
|
||||
SHORT_HASH=$(git rev-parse --short=8 HEAD)
|
||||
VERSION="${YEAR}.${MONTH}.99.${SHORT_HASH}"
|
||||
fi
|
||||
|
||||
# Guardar versión en output para usarla en steps posteriores
|
||||
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
|
||||
echo "BRANCH=${BRANCH}" >> $GITHUB_OUTPUT
|
||||
|
||||
# Mostrar en logs
|
||||
echo "📦 Versión generada: ${VERSION}"
|
||||
echo "🌿 Rama: ${BRANCH}"
|
||||
|
||||
- name: Login a Harbor
|
||||
run: |
|
||||
@@ -27,6 +81,7 @@ jobs:
|
||||
- name: Build backend
|
||||
run: |
|
||||
docker build \
|
||||
--build-arg APP_VERSION=${{ steps.version.outputs.VERSION }} \
|
||||
-t dev.aduanasoft.com/anexo76/backend:latest \
|
||||
-f ./backend/Dockerfile \
|
||||
./backend
|
||||
@@ -55,6 +110,19 @@ jobs:
|
||||
run: |
|
||||
docker push dev.aduanasoft.com/anexo76/frontend:latest
|
||||
|
||||
# ------------------------
|
||||
# Crear tag de versión (solo para main)
|
||||
# ------------------------
|
||||
- name: Crear tag de versión
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
VERSION=${{ steps.version.outputs.VERSION }}
|
||||
git config user.name "Gitea Actions"
|
||||
git config user.email "actions@gitea.local"
|
||||
git tag -a "v${VERSION}" -m "Release version ${VERSION}"
|
||||
git push origin "v${VERSION}"
|
||||
echo "✅ Tag v${VERSION} creado y pusheado"
|
||||
|
||||
# ------------------------
|
||||
# Deploy a Development
|
||||
# ------------------------
|
||||
|
||||
Reference in New Issue
Block a user