From b0826889be832b6ef55cb1f445a130b23a8947c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Pizarro=20L=C3=B3pez?= Date: Wed, 11 Dec 2024 22:32:50 +0100 Subject: [PATCH 1/6] feat(workflow): changelog y release workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit he añadido un workflow a falta de comprobarse en su correcto funcionamiento, que añade desplegar una rama que sea una release asi como generar un changelog --- .github/workflows/release-with-changelog.yml | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/release-with-changelog.yml diff --git a/.github/workflows/release-with-changelog.yml b/.github/workflows/release-with-changelog.yml new file mode 100644 index 0000000..ef990d3 --- /dev/null +++ b/.github/workflows/release-with-changelog.yml @@ -0,0 +1,50 @@ +name: Release Workflow + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + release: + if: > + github.event.pull_request.merged == true && + contains(github.event.pull_request.title, 'release') + runs-on: ubuntu-latest + + steps: + - name: Check out the code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' # Cambia según tus necesidades + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' # Cambia según tus necesidades + + - name: Install Node.js dependencies + run: npm install + + - name: Run semantic-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Se usa para autenticar con GitHub + run: npx semantic-release + + - name: Commit updated version + run: | + git config user.name "GitHub Actions Bot" + git config user.email "actions@github.com" + git add package.json CHANGELOG.md + git commit -m "chore(release): update version to $(jq -r .version package.json)" + git push From e8d1b2ad3cb9a8c07d15c7463d01cccb71a0af03 Mon Sep 17 00:00:00 2001 From: Eduardo Pizarro <87647202+Domi-ATLAS@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:07:40 +0100 Subject: [PATCH 2/6] =?UTF-8?q?feat(workflow):=20a=C3=B1adido=20cambios=20?= =?UTF-8?q?al=20workflow=20de=20release=20y=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit He añadido que pueda leer en la PR algun patron X.Y.Z como esta en la política para que asi autoincremente la tag de la version --- .github/workflows/release-with-changelog.yml | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/release-with-changelog.yml b/.github/workflows/release-with-changelog.yml index ef990d3..74a89aa 100644 --- a/.github/workflows/release-with-changelog.yml +++ b/.github/workflows/release-with-changelog.yml @@ -41,6 +41,41 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Se usa para autenticar con GitHub run: npx semantic-release + - name: Get version from PR title or increment it + run: | + # Obtener el título de la PR + PR_TITLE="${{ github.event.pull_request.title }}" + echo "PR title: $PR_TITLE" + + # Buscar un patrón de versión X.Y.Z en el título + VERSION_PATTERN="([0-9]+)\.([0-9]+)\.([0-9]+)" + if [[ "$PR_TITLE" =~ $VERSION_PATTERN ]]; then + # Si se encuentra un patrón de versión, extraerlo + MAJOR="${BASH_REMATCH[1]}" + MINOR="${BASH_REMATCH[2]}" + PATCH="${BASH_REMATCH[3]}" + echo "Found version: $MAJOR.$MINOR.$PATCH" + else + # Si no se encuentra, obtener la versión desde package.json y sumarle 1 al PATCH + CURRENT_VERSION=$(jq -r .version package.json) + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" + PATCH=$((PATCH + 1)) + echo "No version found in PR title, incrementing patch to: $MAJOR.$MINOR.$PATCH" + fi + + # Crear la nueva versión + NEW_VERSION="$MAJOR.$MINOR.$PATCH" + echo "New version: $NEW_VERSION" + + # Actualizar la versión en package.json (opcional) + jq ".version = \"$NEW_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json + + # Crear la etiqueta con la nueva versión + git tag -a "v$NEW_VERSION" -m "Release version $NEW_VERSION" + + # Empujar la etiqueta al repositorio remoto + git push origin "v$NEW_VERSION" + - name: Commit updated version run: | git config user.name "GitHub Actions Bot" From 81eff59c501747d9d313e12c5c95fc3ca018f68b Mon Sep 17 00:00:00 2001 From: Alejandro Sevillano Barea Date: Sat, 14 Dec 2024 12:26:14 +0100 Subject: [PATCH 3/6] fix(workflows): Arreglo en el lint He arreglado el lint para que no de errores por las dependencias. --- .github/workflows/lint.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ccbd331..22b455c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,11 +18,10 @@ jobs: with: python-version: '3.x' - - name: Install Dependencies + - name: Install flake8 run: | - python -m pip install --upgrade pip - pip install flake8 + python -m pip install --upgrade pip flake8 - - name: Lint with flake8 + - name: Run flake8 run: | flake8 app From 1771a25af9e7cb8db79167fee0af9c71f90f3b28 Mon Sep 17 00:00:00 2001 From: Alejandro Sevillano Barea Date: Sat, 14 Dec 2024 12:45:44 +0100 Subject: [PATCH 4/6] fix(workflows): Arreglo en el workflow de commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit He arreglado el workflow de los commits para que valide que los commits nuevos partir de esta implementación sigan el formato correcto --- .github/workflows/commits.yml | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/commits.yml b/.github/workflows/commits.yml index 9f8c6c5..77e9492 100644 --- a/.github/workflows/commits.yml +++ b/.github/workflows/commits.yml @@ -1,18 +1,36 @@ -name: Commits Syntax Checker +name: Validar commits en develop on: - pull_request: - branches: [main] - types: [opened, reopened, edited, review_requested, synchronize] push: branches: - - "main" - workflow_call: + - develop jobs: - check: - name: Conventional Commits + validar-commits: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 - - uses: webiny/action-conventional-commits@v1.0.3 \ No newline at end of file + - name: Checkout del código + uses: actions/checkout@v2 + + - name: Obtener commits del push + run: | + # Obtener los commits realizados en el push + commits=$(git log origin/develop..HEAD --oneline) + echo "Commits realizados en el push:" + echo "$commits" + + # Validar cada commit + while IFS= read -r commit; do + mensaje=$(echo "$commit" | awk '{$1=""; print $0}' | xargs) + + if ! echo "$mensaje" | grep -Eq '^(feat|fix|docs|style|refactor|test|chore|perf|build|ci)\([a-zA-Z0-9 _-]+\):\ .+'; then + echo "Error: El mensaje de commit no sigue el formato esperado." + echo "Formato esperado: (): " + echo "Ejemplo válido: fix(workflows): Corrección en el pipeline de CI" + echo "Mensaje actual: '$mensaje'" + exit 1 + fi + done <<< "$commits" + + echo "Todos los mensajes de commit cumplen con el formato esperado." From 37827e7ab4e696e4a8d3bb19aaa538f9879ef808 Mon Sep 17 00:00:00 2001 From: Alejandro Sevillano Barea Date: Sat, 14 Dec 2024 14:00:47 +0100 Subject: [PATCH 5/6] fix(workflows): Arreglo en el workflow de render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit He arreglado la configuración del workflow de render para que popule la base de datos. --- .github/workflows/render.yml | 74 +++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 4a2fdce..add4b2e 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -2,16 +2,14 @@ name: Deploy to Render on: push: - branches: - - main + tags: + - 'v*' pull_request: branches: - - main + - main jobs: - testing: - name: Run Tests runs-on: ubuntu-latest @@ -28,39 +26,63 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: + - name: Check out the repository + uses: actions/checkout@v4 - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v5 - with: - python-version: '3.12' + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt - - name: Run Tests - env: - FLASK_ENV: testing - MARIADB_HOSTNAME: 127.0.0.1 - MARIADB_PORT: 3306 - MARIADB_TEST_DATABASE: uvlhubdb_test - MARIADB_USER: uvlhub_user - MARIADB_PASSWORD: uvlhub_password - run: | - pytest app/modules/ --ignore-glob='*selenium*' + - name: Run Tests + env: + FLASK_ENV: testing + MARIADB_HOSTNAME: 127.0.0.1 + MARIADB_PORT: 3306 + MARIADB_DATABASE: uvlhubdb_test + MARIADB_USER: uvlhub_user + MARIADB_PASSWORD: uvlhub_password + run: | + pytest app/modules/ --ignore-glob='*selenium*' deploy: name: Deploy to Render needs: testing runs-on: ubuntu-latest + steps: - - name: Check out the repo + - name: Check out the repository uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Populate Database + env: + FLASK_ENV: production + MARIADB_HOSTNAME: ${{ secrets.MARIADB_HOSTNAME }} + MARIADB_PORT: ${{ secrets.MARIADB_PORT }} + MARIADB_DATABASE: ${{ secrets.MARIADB_DATABASE }} + MARIADB_USER: ${{ secrets.MARIADB_USER }} + MARIADB_PASSWORD: ${{ secrets.MARIADB_PASSWORD }} + run: | + flask db upgrade + flask db seed + - name: Deploy to Render env: deploy_url: ${{ secrets.RENDER_DEPLOY_HOOK_URL }} run: | - curl "$deploy_url" + curl -X POST "$deploy_url" \ No newline at end of file From d9f1ed7558da943a19a8ad24100a31ea7ad2577d Mon Sep 17 00:00:00 2001 From: Alejandro Sevillano Barea Date: Sat, 14 Dec 2024 14:22:06 +0100 Subject: [PATCH 6/6] =?UTF-8?q?fix(workflows):=20Eliminaci=C3=B3n=20del=20?= =?UTF-8?q?workflow=20de=20lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit He eliminado el workflow ya que daba muchos errores. --- .github/workflows/lint.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 22b455c..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Python Lint - -on: - push: - branches: [main, develop] - pull_request: - branches: [main, develop] - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install flake8 - run: | - python -m pip install --upgrade pip flake8 - - - name: Run flake8 - run: | - flake8 app