From 523c14795789247f12bc75b11f5287680831274c Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:10:41 +0200 Subject: [PATCH 1/8] workflow --- .gitea/workflows/merge-dev.yaml | 30 +++++++++++++++++++ docs/gitflow.md | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .gitea/workflows/merge-dev.yaml create mode 100644 docs/gitflow.md diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml new file mode 100644 index 0000000..98f5d4f --- /dev/null +++ b/.gitea/workflows/merge-dev.yaml @@ -0,0 +1,30 @@ +name: Auto-Merge Dev +run-name: Merging changes from dev + +on: + pull_request: + types: [opened, synchronize, reopened] + branches: ["feature/*"] + push: + branches: ["feature/*"] + workflow_dispatch: + inputs: + branch: + description: "Branch to merge from dev" + required: true + default: "feature/example" + +jobs: + auto-merge-dev: + runs-on: windows # Ejecutar directamente en el host Windows + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Merge changes from dev + run: | + git switch dev + git pull origin dev + git switch - + git merge dev + git push origin diff --git a/docs/gitflow.md b/docs/gitflow.md new file mode 100644 index 0000000..e5072b7 --- /dev/null +++ b/docs/gitflow.md @@ -0,0 +1,51 @@ +# Galerias Fotograficas -- Git flow + +Para poder aportar al desarrollo de nuevas funcionalidades en las galerías fotográficas, todos los cambios pasan un flujo de tests al hacer push sobre cualqueir rama. + +Cuando se hace push sobre una rama, se hará un merge de `dev` automaticamente. Tras este merge, se comprobará que no hayan conflictos. +Justo después, se compilará el back, el front, los tests y los documentos. En caso de que alguno de estos pasos falle, se notificará al desarrollador responsable para que pueda solucionarlo. +Una vez al dia, se realizará una revisión de las ramas en `dev` para generar una rama `staging/{date}` que se publicará con los cambios del día anterior, siempre y cuando hayan conseguido pasar todos los tests. + +Para poder aportar sobre nuevas funcionalidades, se deben seguir los siguientes pasos: + +1. Crear una nueva rama a partir de `dev` que se llame `feature/[nombre-de-la-funcionalidad]`. +2. Realizar los cambios necesarios en la nueva rama. +3. Hacer push de la rama al repositorio remoto. +4. Crear un Pull Request (PR) para que los cambios sean revisados e integrados en `dev`. + +Una vez que el PR sea aprobado, los cambios se fusionarán en `dev`. + +Se seguirá el siguiente flujo: + +gitGraph + commit + branch develop + checkout develop + commit + commit + checkout develop + branch "feature/one" + checkout develop + commit + checkout "feature/one" + commit + checkout develop + branch "feature/two" + checkout develop + commit + commit + commit + checkout "feature/two" + commit + commit + merge develop + checkout develop + merge "feature/two" + checkout "feature/one" + commit + merge develop + checkout develop + merge "feature/one" + commit + checkout main + merge develop id: "release" tag: "release/{date}" -- 2.47.1.windows.1 From f121899b3bfb10525fcb0720a7b6f2c6699fa116 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:13:33 +0200 Subject: [PATCH 2/8] workflow --- .gitea/workflows/merge-dev.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml index 98f5d4f..8a3c0e0 100644 --- a/.gitea/workflows/merge-dev.yaml +++ b/.gitea/workflows/merge-dev.yaml @@ -23,8 +23,12 @@ jobs: - name: Merge changes from dev run: | - git switch dev - git pull origin dev - git switch - - git merge dev - git push origin + git fetch origin + git checkout $GITHUB_REF # la rama feature/* + git merge origin/dev + if [ $? -eq 0 ]; then + git push origin $GITHUB_REF + else + echo "Merge conflict detected, please resolve." + exit 1 + fi -- 2.47.1.windows.1 From c173cc3b3babe29ec8969e4c4c4648d0f03db60a Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:16:26 +0200 Subject: [PATCH 3/8] workflow --- .gitea/workflows/merge-dev.yaml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml index 8a3c0e0..360dc7c 100644 --- a/.gitea/workflows/merge-dev.yaml +++ b/.gitea/workflows/merge-dev.yaml @@ -23,12 +23,21 @@ jobs: - name: Merge changes from dev run: | + # Obtener la última versión de todas las ramas git fetch origin - git checkout $GITHUB_REF # la rama feature/* + + # Cambiar a la rama feature actual (sustituye $env:GITHUB_REF por la variable que uses con el nombre de rama) + $branch = $env:GITHUB_REF -replace 'refs/heads/', '' + git checkout $branch + + # Intentar hacer merge de dev a la rama feature actual git merge origin/dev - if [ $? -eq 0 ]; then - git push origin $GITHUB_REF - else - echo "Merge conflict detected, please resolve." - exit 1 - fi + + if ($LASTEXITCODE -eq 0) { + # Si el merge fue exitoso (sin conflictos), hacer push + git push origin $branch + } else { + # Si hubo conflictos, mostrar mensaje y salir con error para detener el pipeline + Write-Host "Conflictos detectados en el merge de dev a $branch, por favor resolver manualmente." + exit 1 + } -- 2.47.1.windows.1 From a223dfc7c081bd398e8dc7373424a8d17dbfd5c1 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:20:09 +0200 Subject: [PATCH 4/8] workflow --- .gitea/workflows/merge-dev.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml index 360dc7c..98fa0dd 100644 --- a/.gitea/workflows/merge-dev.yaml +++ b/.gitea/workflows/merge-dev.yaml @@ -24,18 +24,14 @@ jobs: - name: Merge changes from dev run: | # Obtener la última versión de todas las ramas - git fetch origin - - # Cambiar a la rama feature actual (sustituye $env:GITHUB_REF por la variable que uses con el nombre de rama) - $branch = $env:GITHUB_REF -replace 'refs/heads/', '' - git checkout $branch + git pull origin dev # Intentar hacer merge de dev a la rama feature actual - git merge origin/dev + git merge dev if ($LASTEXITCODE -eq 0) { # Si el merge fue exitoso (sin conflictos), hacer push - git push origin $branch + git push } else { # Si hubo conflictos, mostrar mensaje y salir con error para detener el pipeline Write-Host "Conflictos detectados en el merge de dev a $branch, por favor resolver manualmente." -- 2.47.1.windows.1 From 67e7fe35f9b4b92af3cf9ea167434f934a947634 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:22:34 +0200 Subject: [PATCH 5/8] workflow --- .gitea/workflows/merge-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml index 98fa0dd..fdfcb9b 100644 --- a/.gitea/workflows/merge-dev.yaml +++ b/.gitea/workflows/merge-dev.yaml @@ -27,7 +27,7 @@ jobs: git pull origin dev # Intentar hacer merge de dev a la rama feature actual - git merge dev + git merge origin/dev if ($LASTEXITCODE -eq 0) { # Si el merge fue exitoso (sin conflictos), hacer push -- 2.47.1.windows.1 From 1ded384fd76e6a7f66b20ddf5735bea365becf57 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:46:34 +0200 Subject: [PATCH 6/8] workflows --- .gitea/workflows/cleanup-tests-branches.yaml | 35 +++++++++ .gitea/workflows/construct-test.yaml | 74 ++++++++++++++++++++ .gitea/workflows/deploy-back.yaml | 49 +++++++++++++ .gitea/workflows/deploy-docs.yaml | 5 +- .gitea/workflows/deploy-front.yaml | 48 +++++++++++++ .gitea/workflows/merge-dev.yaml | 10 ++- 6 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/cleanup-tests-branches.yaml create mode 100644 .gitea/workflows/construct-test.yaml create mode 100644 .gitea/workflows/deploy-back.yaml create mode 100644 .gitea/workflows/deploy-front.yaml diff --git a/.gitea/workflows/cleanup-tests-branches.yaml b/.gitea/workflows/cleanup-tests-branches.yaml new file mode 100644 index 0000000..988573c --- /dev/null +++ b/.gitea/workflows/cleanup-tests-branches.yaml @@ -0,0 +1,35 @@ +name: Cleanup old test branches + +on: + schedule: + - cron: "0 12 * * *" + workflow_dispatch: + +jobs: + cleanup_branch: + runs-on: windows + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Delete test branches older than 7 days + shell: powershell + run: | + # Obtener la fecha límite (7 días antes) + $limitDate = (Get-Date).AddDays(-7) + + # Obtener todas las ramas remotas test/* + $branches = git branch -r | Where-Object { $_ -match 'origin/test/' } + + foreach ($branch in $branches) { + $branchName = $branch.Trim() -replace '^origin/', '' + # Obtener fecha de creación de la rama (aproximación por el primer commit) + $firstCommitDate = git log $branchName --reverse --format="%ci" | Select-Object -First 1 + $branchDate = Get-Date $firstCommitDate + + if ($branchDate -lt $limitDate) { + Write-Host "Eliminando rama $branchName creada el $branchDate" + git push origin --delete $branchName + } + } diff --git a/.gitea/workflows/construct-test.yaml b/.gitea/workflows/construct-test.yaml new file mode 100644 index 0000000..665cab9 --- /dev/null +++ b/.gitea/workflows/construct-test.yaml @@ -0,0 +1,74 @@ +name: Create Test Construct +run-name: Creating test construct + +on: + workflow_dispatch: + inputs: + branch: + description: "Branch to build" + required: true + default: "dev" + schedule: + - cron: "0 12 * * *" + +jobs: + create_test_branch_and_build: + runs-on: windows + + steps: + - name: Checkout dev branch + uses: actions/checkout@v4 + with: + ref: dev + + - name: Create test branch with date + id: create_branch + shell: powershell + run: | + $date = Get-Date -Format "yyyyMMdd" + $branchName = "test/$date" + git checkout -b $branchName + git push origin $branchName + Write-Output "::set-output name=branch::$branchName" + + deploy_docs: + needs: create_test_branch_and_build + runs-on: windows + steps: + - name: Checkout test branch + uses: actions/checkout@v4 + with: + ref: ${{ steps.create_branch.outputs.branch }} + + - name: Deploy documentation + uses: ./.gitea/workflows/deploy-docs.yaml + with: + branch: ${{ steps.create_branch.outputs.branch }} + + deploy_back: + needs: create_test_branch_and_build + runs-on: windows + steps: + - name: Checkout test branch + uses: actions/checkout@v4 + with: + ref: ${{ steps.create_branch.outputs.branch }} + + - name: Deploy .net project + uses: ./.gitea/workflows/deploy-back.yaml + with: + branch: ${{ steps.create_branch.outputs.branch }} + + deploy_front: + needs: create_test_branch_and_build + runs-on: windows + steps: + - name: Checkout test branch + uses: actions/checkout@v4 + with: + ref: ${{ steps.create_branch.outputs.branch }} + + - name: Deploy front project + uses: ./.gitea/workflows/deploy-front.yaml + with: + branch: ${{ steps.create_branch.outputs.branch }} diff --git a/.gitea/workflows/deploy-back.yaml b/.gitea/workflows/deploy-back.yaml new file mode 100644 index 0000000..94d9a3a --- /dev/null +++ b/.gitea/workflows/deploy-back.yaml @@ -0,0 +1,49 @@ +name: Create Test Construct +run-name: Creating test construct + +on: + pull_request: + types: [closed] + branches: [dev, "test/**"] + paths: ["back/**"] + workflow_dispatch: + inputs: + branch: + description: "Branch to deploy" + required: true + default: "dev" + workflow_call: + +jobs: + build_and_deploy: + runs-on: windows + + steps: + - name: Checkout branch + uses: actions/checkout@v4 + + # build .net project + - name: Build .NET Project + run: | + dotnet restore + dotnet build + + # deploy .net to iis site with path = "D:\iis\es\mcvingenieros\mmorales.photo\back" + - name: Deploy .net project to iis + shell: powershell + run: | + # deploy to iis site back.mmorales.photo that has path = D:\iis\es\mcvingenieros\mmorales.photo\back\ + $sourcePath = "D:\iis\es\mcvingenieros\mmorales.photo\back\bin\Release\net9.0\publish" + $destinationPath = "D:\iis\es\mcvingenieros\mmorales.photo\back\" + + # Stop IIS site + Stop-WebAppPool -Name "mmorales.photo.back" + + # Remove old files + Remove-Item -Path $destinationPath\* -Recurse -Force + + # Copy new files + Copy-Item -Path $sourcePath\* -Destination $destinationPath -Recurse + + # Start IIS site + Start-WebAppPool -Name "mmorales.photo.back" diff --git a/.gitea/workflows/deploy-docs.yaml b/.gitea/workflows/deploy-docs.yaml index 5dbfd2a..77a3cd5 100644 --- a/.gitea/workflows/deploy-docs.yaml +++ b/.gitea/workflows/deploy-docs.yaml @@ -4,10 +4,10 @@ run-name: Deploying ${{ gitea.repository }} docs locally on: pull_request: types: [closed] - branches: [main] + branches: [master] paths: ["docs/**", "mkdocs.yml", ".gitea/workflows/deploy-docs.yaml"] push: - branches: [main] + branches: [master] paths: ["docs/**", "mkdocs.yml", ".gitea/workflows/deploy-docs.yaml"] workflow_dispatch: inputs: @@ -15,6 +15,7 @@ on: description: "Branch to deploy" required: true default: "master" + workflow_call: jobs: deploy-docs: diff --git a/.gitea/workflows/deploy-front.yaml b/.gitea/workflows/deploy-front.yaml new file mode 100644 index 0000000..30237ec --- /dev/null +++ b/.gitea/workflows/deploy-front.yaml @@ -0,0 +1,48 @@ +name: deploy front +run-name: Deploy Frontend + +on: + pull_request: + types: [closed] + branches: [dev, "test/**"] + paths: ["front/**"] + workflow_dispatch: + inputs: + branch: + description: "Branch to deploy" + required: true + default: "dev" + workflow_call: + +jobs: + build_and_deploy: + runs-on: windows + + steps: + - name: Checkout branch + uses: actions/checkout@v4 + + # build angular + - name: Build Angular + run: | + npm install + npm run build + + - name: Deploy to IIS + shell: powershell + run: | + # deploy to iis site front.mmorales.photo that has path = D:\iis\es\mcvingenieros\mmorales.photo\front\ + $sourcePath = "D:\iis\es\mcvingenieros\mmorales.photo\front\dist" + $destinationPath = "D:\iis\es\mcvingenieros\mmorales.photo\front\" + + # Stop IIS site + Stop-WebAppPool -Name "mmorales.photo.front" + + # Remove old files + Remove-Item -Path $destinationPath\* -Recurse -Force + + # Copy new files + Copy-Item -Path $sourcePath\* -Destination $destinationPath -Recurse + + # Start IIS site + Start-WebAppPool -Name "mmorales.photo.front" diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml index fdfcb9b..2d3e4b3 100644 --- a/.gitea/workflows/merge-dev.yaml +++ b/.gitea/workflows/merge-dev.yaml @@ -19,7 +19,15 @@ jobs: runs-on: windows # Ejecutar directamente en el host Windows steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - name: Configure git user + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + shell: powershell - name: Merge changes from dev run: | -- 2.47.1.windows.1 From 2360630544b4146e651ba911ff3794d1caca180b Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:52:01 +0200 Subject: [PATCH 7/8] --allow-unrelated-histories --- .gitea/workflows/merge-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml index 2d3e4b3..fb91b00 100644 --- a/.gitea/workflows/merge-dev.yaml +++ b/.gitea/workflows/merge-dev.yaml @@ -35,7 +35,7 @@ jobs: git pull origin dev # Intentar hacer merge de dev a la rama feature actual - git merge origin/dev + git merge origin/dev --allow-unrelated-histories if ($LASTEXITCODE -eq 0) { # Si el merge fue exitoso (sin conflictos), hacer push -- 2.47.1.windows.1 From 258b4ebfec501f3daffa608717d48454bd654ab2 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 2 Sep 2025 00:54:09 +0200 Subject: [PATCH 8/8] --allow-unrelated-histories --- .gitea/workflows/merge-dev.yaml | 47 --------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 .gitea/workflows/merge-dev.yaml diff --git a/.gitea/workflows/merge-dev.yaml b/.gitea/workflows/merge-dev.yaml deleted file mode 100644 index fb91b00..0000000 --- a/.gitea/workflows/merge-dev.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Auto-Merge Dev -run-name: Merging changes from dev - -on: - pull_request: - types: [opened, synchronize, reopened] - branches: ["feature/*"] - push: - branches: ["feature/*"] - workflow_dispatch: - inputs: - branch: - description: "Branch to merge from dev" - required: true - default: "feature/example" - -jobs: - auto-merge-dev: - runs-on: windows # Ejecutar directamente en el host Windows - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.ref }} - - - name: Configure git user - run: | - git config user.name "github-actions" - git config user.email "github-actions@github.com" - shell: powershell - - - name: Merge changes from dev - run: | - # Obtener la última versión de todas las ramas - git pull origin dev - - # Intentar hacer merge de dev a la rama feature actual - git merge origin/dev --allow-unrelated-histories - - if ($LASTEXITCODE -eq 0) { - # Si el merge fue exitoso (sin conflictos), hacer push - git push - } else { - # Si hubo conflictos, mostrar mensaje y salir con error para detener el pipeline - Write-Host "Conflictos detectados en el merge de dev a $branch, por favor resolver manualmente." - exit 1 - } -- 2.47.1.windows.1