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." diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index ccbd331..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,28 +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 Dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 - - - name: Lint with flake8 - run: | - flake8 app diff --git a/.github/workflows/release-with-changelog.yml b/.github/workflows/release-with-changelog.yml new file mode 100644 index 0000000..74a89aa --- /dev/null +++ b/.github/workflows/release-with-changelog.yml @@ -0,0 +1,85 @@ +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: 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" + 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 diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 6c10cdf..10c844d 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,40 +26,66 @@ 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 + - 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 - - 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: 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*' - - name: Run Tests - env: - FLASK_ENV: testing - MARIADB_HOSTNAME: 127.0.0.1 - MARIADB_PORT: 3306 - MARIADB_TEST_DATABASE: uvlhubdb_test - MARIADB_USER: uvlhubdb_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