Update .gitea/workflows/build.yaml
This commit is contained in:
+76
-13
@@ -11,15 +11,24 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
steps:
|
||||
- name: Checkout del código
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # Clonar todo para evitar errores de historial
|
||||
# Descarga el historial necesario para sincronizar origin/main.
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Definir Versión Semántica
|
||||
id: vars
|
||||
run: echo "VERSION=v1.0.${{ github.run_number }}" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
VERSION="v1.0.${{ github.run_number }}"
|
||||
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
echo "Versión generada: ${VERSION}"
|
||||
|
||||
- name: Login en Gitea Registry
|
||||
uses: docker/login-action@v2
|
||||
@@ -38,18 +47,72 @@ jobs:
|
||||
gitea.cruzcloud.net/devops/ecommerce-frontend:latest
|
||||
|
||||
- name: Actualizar Manifiesto GitOps (CD)
|
||||
shell: bash
|
||||
env:
|
||||
VERSION: ${{ steps.vars.outputs.VERSION }}
|
||||
MANIFEST: workloads/ecommerce/frontend.yaml
|
||||
IMAGE_REPOSITORY: gitea.cruzcloud.net/devops/ecommerce-frontend
|
||||
run: |
|
||||
# 1. Configuración de identidad
|
||||
git config --global user.name "Gitea Actions"
|
||||
git config --global user.email "[email protected]"
|
||||
set -euo pipefail
|
||||
|
||||
# 2. Sincronización agresiva: asegurar que estamos en la rama correcta
|
||||
git checkout main
|
||||
git config user.name "Cristian Felipe"
|
||||
git config user.email "[email protected]"
|
||||
|
||||
# 3. Aplicar el cambio
|
||||
sed -i -E "s|(image: gitea.cruzcloud.net/devops/ecommerce-frontend:).*|\1${{ steps.vars.outputs.VERSION }}|g" workloads/ecommerce/frontend.yaml
|
||||
# El repositorio remoto puede cambiar mientras se construye la imagen.
|
||||
# Se reintenta desde el último origin/main sin usar push --force.
|
||||
for intento in 1 2 3; do
|
||||
echo "--------------------------------------------------"
|
||||
echo "Intento ${intento}/3"
|
||||
echo "Versión: ${VERSION}"
|
||||
echo "Manifiesto: ${MANIFEST}"
|
||||
echo "--------------------------------------------------"
|
||||
|
||||
# 4. Commit y Push forzado
|
||||
git add workloads/ecommerce/frontend.yaml
|
||||
git commit -m "chore: release ${{ steps.vars.outputs.VERSION }} [skip ci]" || exit 0
|
||||
git push origin main --force
|
||||
git fetch origin main
|
||||
git checkout -B main origin/main
|
||||
|
||||
if [ ! -f "${MANIFEST}" ]; then
|
||||
echo "ERROR: no existe el archivo ${MANIFEST}."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -qE \
|
||||
"image:[[:space:]]*${IMAGE_REPOSITORY}:" \
|
||||
"${MANIFEST}"; then
|
||||
echo "ERROR: no se encontró la imagen ${IMAGE_REPOSITORY} en ${MANIFEST}."
|
||||
echo "Líneas image encontradas:"
|
||||
grep -nE "^[[:space:]]*image:" "${MANIFEST}" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed -i -E \
|
||||
"s|(image:[[:space:]]*${IMAGE_REPOSITORY}:).*|\\1${VERSION}|g" \
|
||||
"${MANIFEST}"
|
||||
|
||||
echo "Imagen resultante en el manifiesto:"
|
||||
grep -nE "^[[:space:]]*image:" "${MANIFEST}" || true
|
||||
|
||||
git add "${MANIFEST}"
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
echo "El manifiesto ya contiene la versión ${VERSION}."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git commit -m "chore: release ${VERSION} [skip ci]"
|
||||
|
||||
if git push origin HEAD:main; then
|
||||
echo "Manifiesto actualizado correctamente con ${VERSION}."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "origin/main cambió mientras se realizaba el push."
|
||||
|
||||
if [ "${intento}" -lt 3 ]; then
|
||||
espera=$((intento * 3))
|
||||
echo "Reintentando en ${espera} segundos..."
|
||||
sleep "${espera}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "ERROR: no fue posible actualizar main después de 3 intentos."
|
||||
exit 1
|
||||
Reference in New Issue
Block a user