From 3f942731a6a0e289b66d59356915943a27216303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Garc=C3=ADa=20L=C3=B3pez?= Date: Thu, 4 Dec 2025 12:36:14 +0100 Subject: [PATCH 1/2] Versionado mediante Tags --- .github/workflows/linter.yml | 77 +++++++++++++++++------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 7efce49..98a38d2 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,63 +1,60 @@ -name: Revision de Sintaxis PHP +name: Pipeline CI/CD -on: [push] +on: + push: + branches: ["main"] + tags: ["v*.*.*"] + pull_request: + branches: ["main"] jobs: - verificar-sintaxis: + quality-control: runs-on: ubuntu-latest steps: - - name: Descargar tu código (Checkout) - uses: actions/checkout@v4 - - - name: Instalar PHP - uses: shivammathur/setup-php@v2 + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 with: php-version: '8.2' + - run: find . -name "*.php" -print0 | xargs -0 -n1 php -l - - name: Ejecutar Linter (Modo Estricto) - run: | - find . -name "*.php" -print0 | xargs -0 -n1 php -l - - - name: Ejecutar Tests - run: php tests.php - - construir-y-publicar: - needs: verificar-sintaxis + unit-tests: + needs: quality-control runs-on: ubuntu-latest steps: - - name: Descargar el código - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - run: php tests.php - - name: Login en Docker Hub - uses: docker/login-action@v3 + build-push: + needs: unit-tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Construir y subir + - name: Construir y subir a DockerHub uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ secrets.DOCKERHUB_USERNAME}}/calculatorcli:latest + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/calculatorcli:latest + ${{ secrets.DOCKERHUB_USERNAME }}/calculatorcli:${{ github.ref_name }} - despliegue: - needs: [verificar-sintaxis, construir-y-publicar] + deploy: + needs: build-push runs-on: self-hosted steps: -# - name: Descargar el código -# uses: actions/checkout@v4 - -# - name: Construir la imagen -# run: docker build -t calculatorcli-prod . - - - name: Login en Docker Hub - run: echo "${{ secrets.DOCKERHUB_PASSWORD}}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME}} --password-stdin - - - name: Actualizar contenedor + - name: Deploy on Server run: | - docker stop calculatorcli-prod || true - docker rm calculatorcli-prod || true - # Descargamos usando secrets - docker pull ${{ secrets.DOCKERHUB_USERNAME}}/calculatorcli:latest - docker run -d --name calculatorcli-prod ${{ secrets.DOCKERHUB_USERNAME }}/calculatorcli:latest tail -f /dev/null + # Login + echo "${{ secrets.DOCKERHUB_PASSWORD}}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME}} --password-stdin + # Limpieza + docker stop calculatorcli-prod + docker rm calculatorcli-prod + # Usamos la versión específica del tag para mayor seguridad + docker pull ${{ secrets.DOCKERHUB_USERNAME}}/calculatorcli:${{ github.ref_name }} + # Lanzamos el contenedor + docker run -d --name calculatorcli-prod ${{ secrets.DOCKERHUB_USERNAME }}/calculatorcli:${{ github.ref_name }} tail -f /dev/null From 2a126eeff47ae21632b401a3c15b306f801fe675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Garc=C3=ADa=20L=C3=B3pez?= Date: Thu, 4 Dec 2025 12:41:07 +0100 Subject: [PATCH 2/2] Fixes YAML --- .github/workflows/linter.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 98a38d2..7f5b8f4 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -26,6 +26,7 @@ jobs: build-push: needs: unit-tests + if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -45,6 +46,7 @@ jobs: deploy: needs: build-push + if: startsWith(github.ref, 'refs/tags/v') runs-on: self-hosted steps: - name: Deploy on Server