Update .gitea/workflows/build.yaml
This commit is contained in:
+76
-13
@@ -11,15 +11,24 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout del código
|
- name: Checkout del código
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
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
|
- name: Definir Versión Semántica
|
||||||
id: vars
|
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
|
- name: Login en Gitea Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
@@ -38,18 +47,72 @@ jobs:
|
|||||||
gitea.cruzcloud.net/devops/ecommerce-frontend:latest
|
gitea.cruzcloud.net/devops/ecommerce-frontend:latest
|
||||||
|
|
||||||
- name: Actualizar Manifiesto GitOps (CD)
|
- 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: |
|
run: |
|
||||||
# 1. Configuración de identidad
|
set -euo pipefail
|
||||||
git config --global user.name "Gitea Actions"
|
|
||||||
git config --global user.email "[email protected]"
|
|
||||||
|
|
||||||
# 2. Sincronización agresiva: asegurar que estamos en la rama correcta
|
git config user.name "Cristian Felipe"
|
||||||
git checkout main
|
git config user.email "[email protected]"
|
||||||
|
|
||||||
# 3. Aplicar el cambio
|
# El repositorio remoto puede cambiar mientras se construye la imagen.
|
||||||
sed -i -E "s|(image: gitea.cruzcloud.net/devops/ecommerce-frontend:).*|\1${{ steps.vars.outputs.VERSION }}|g" workloads/ecommerce/frontend.yaml
|
# 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 fetch origin main
|
||||||
git add workloads/ecommerce/frontend.yaml
|
git checkout -B main origin/main
|
||||||
git commit -m "chore: release ${{ steps.vars.outputs.VERSION }} [skip ci]" || exit 0
|
|
||||||
git push origin main --force
|
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