From bba514a10c1ec50b45a53739c2a775b18d322690 Mon Sep 17 00:00:00 2001 From: Javid Ahmed Date: Sat, 7 Mar 2026 19:57:00 +0000 Subject: [PATCH] Add frontend validation checks and conditional build steps in workflows --- .github/actions/ci/frontend/action.yml | 4 +- .../setup/check-frontend-exists/action.yml | 16 ++++++ .github/workflows/build.yml | 27 +++++++++ .github/workflows/ci.yml | 22 ++++++++ docs/WORKFLOWS.md | 56 ++++++++++++++++++- 5 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 .github/actions/setup/check-frontend-exists/action.yml diff --git a/.github/actions/ci/frontend/action.yml b/.github/actions/ci/frontend/action.yml index 17592e3..1283253 100644 --- a/.github/actions/ci/frontend/action.yml +++ b/.github/actions/ci/frontend/action.yml @@ -1,5 +1,5 @@ -name: Build Frontend -description: Build the frontend and upload the build artifacts for use in other jobs. +name: Frontend +description: Runs frontend validation checks (type-checking, linting, formatting, testing) and uploads coverage reports. runs: using: composite diff --git a/.github/actions/setup/check-frontend-exists/action.yml b/.github/actions/setup/check-frontend-exists/action.yml new file mode 100644 index 0000000..f429b42 --- /dev/null +++ b/.github/actions/setup/check-frontend-exists/action.yml @@ -0,0 +1,16 @@ +name: Check Frontend Exists +description: Check if the frontend directory exists in the repository. + +runs: + using: composite + steps: + - name: Check if frontend directory exists + id: check-frontend + run: | + if [ -d "${{ github.event.repository.name }}-frontend" ]; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Frontend directory does not exist, skipping frontend build" + fi + shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 536d9de..b00e03d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,36 @@ on: - main jobs: + build-frontend: + runs-on: ubuntu-latest + outputs: + frontend-exists: ${{ steps.check-frontend.outputs.exists }} + steps: + - uses: actions/checkout@v6 + + - uses: ./.github/actions/setup/check-frontend-exists + if: github.event.repository.name == 'python-template-server' + # - uses: javidahmed64592/python-template-server/.github/actions/setup/check-frontend-exists@main + # if: github.event.repository.name != 'python-template-server' + + - uses: ./.github/actions/build/build-frontend + if: steps.check-frontend.outputs.exists == 'true' && github.event.repository.name == 'python-template-server' + - uses: javidahmed64592/python-template-server/.github/actions/build/build-frontend@main + if: steps.check-frontend.outputs.exists == 'true' && github.event.repository.name != 'python-template-server' + build-wheel: runs-on: ubuntu-latest + needs: build-frontend steps: - uses: actions/checkout@v6 + + - name: Download frontend build + if: needs.build-frontend.outputs.frontend-exists == 'true' + uses: actions/download-artifact@v8 + with: + name: ${{ github.event.repository.name }}-frontend-build + path: static + - uses: ./.github/actions/build/build-wheel if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/build/build-wheel@main @@ -23,6 +49,7 @@ jobs: needs: build-wheel steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/build/verify-structure if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/build/verify-structure@main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c61f9e8..88e53e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/validate-pyproject if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/validate-pyproject@main @@ -22,6 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/ruff if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/ruff@main @@ -31,6 +33,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/mypy if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/mypy@main @@ -40,6 +43,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/pytest if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/pytest@main @@ -49,6 +53,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/bandit if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/bandit@main @@ -58,6 +63,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/pip-audit if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/pip-audit@main @@ -67,7 +73,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + - uses: ./.github/actions/ci/version-check if: github.event.repository.name == 'template-python' - uses: javidahmed64592/template-python/.github/actions/ci/version-check@main if: github.event.repository.name != 'template-python' + + frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - uses: ./.github/actions/setup/check-frontend-exists + if: github.event.repository.name == 'python-template-server' + # - uses: javidahmed64592/python-template-server/.github/actions/setup/check-frontend-exists@main + # if: github.event.repository.name != 'python-template-server' + + - uses: ./.github/actions/ci/frontend + if: steps.check-frontend.outputs.exists == 'true' && github.event.repository.name == 'python-template-server' + - uses: javidahmed64592/python-template-server/.github/actions/ci/frontend@main + if: steps.check-frontend.outputs.exists == 'true' && github.event.repository.name != 'python-template-server' diff --git a/docs/WORKFLOWS.md b/docs/WORKFLOWS.md index a563d6e..ca98cd4 100644 --- a/docs/WORKFLOWS.md +++ b/docs/WORKFLOWS.md @@ -16,6 +16,8 @@ This document focuses on the Docker-specific workflow and reusable actions uniqu - [Build Actions (`/build/**/action.yml`)](#build-actions-buildactionyml) - [Docker Actions (`docker/**/action.yml`)](#docker-actions-dockeractionyml) - [Workflows (`./github/workflows`)](#workflows-githubworkflows) + - [CI Workflow (`ci.yml`)](#ci-workflow-ciyml) + - [Build Workflow (`build.yml`)](#build-workflow-buildyml) - [Docker Workflow (`docker.yml`)](#docker-workflow-dockeryml) ## Reusable Actions (`./github/actions`) @@ -24,6 +26,26 @@ The following actions can be referenced from other repositories using `javidahme ### Setup Actions (`/setup/**/action.yml`) +**check-frontend-exists:** +- Description: Check if the frontend directory exists in the repository to conditionally execute frontend CI and build jobs. +- Location: `check-frontend-exists/action.yml` +- Outputs: + - `exists` - `"true"` if frontend directory exists, `"false"` otherwise +- Steps: + - Checks for directory named `-frontend` + - Sets output to `true` or `false` based on directory existence + - Logs message if directory doesn't exist +- Note: Used by CI and Build workflows to skip frontend jobs when no frontend directory is present + +Usage: +```yaml +steps: + - uses: javidahmed64592/python-template-server/.github/actions/setup/check-frontend-exists@main + id: check-frontend +``` + +--- + **setup-node:** - Description: Set up Node.js with npm cache and install dependencies. - Location: `setup-node/action.yml` @@ -41,7 +63,7 @@ steps: ### CI Actions (`/ci/**/action.yml`) **frontend:** -- Description: Build the frontend and upload the build artifacts for use in other jobs. +- Description: Runs frontend validation checks (type-checking, linting, formatting, testing) and uploads coverage reports. - Location: `frontend/action.yml` - Steps: - Uses the `setup-node` action @@ -54,7 +76,7 @@ steps: Usage: ```yaml steps: - - uses: javidahmed64592/template-python/.github/actions/ci/frontend@main + - uses: javidahmed64592/python-template-server/.github/actions/ci/frontend@main ``` ### Build Actions (`/build/**/action.yml`) @@ -70,7 +92,7 @@ steps: Usage: ```yaml steps: - - uses: javidahmed64592/template-python/.github/actions/build/build-frontend@main + - uses: javidahmed64592/python-template-server/.github/actions/build/build-frontend@main ``` ### Docker Actions (`docker/**/action.yml`) @@ -232,6 +254,34 @@ steps: ## Workflows (`./github/workflows`) +### CI Workflow (`ci.yml`) + +The CI workflow runs on pushes and pull requests to the `main` branch. +It inherits all Python validation jobs from `template-python` and adds frontend-specific validation. + +**Additional Jobs:** +- `frontend` - Conditionally executes validation checks on frontend if frontend directory exists + - Uses `check-frontend-exists` to detect frontend directory + - Runs `frontend` action only when frontend is present + +### Build Workflow (`build.yml`) + +The Build workflow runs on pushes and pull requests to the `main` branch. +It extends the base `template-python` build process with optional frontend building. + +**Additional Jobs:** +- `build-frontend` - Conditionally builds frontend and outputs existence flag + - Uses `check-frontend-exists` to detect frontend directory + - Builds frontend static files using `build-frontend` action if present + - Outputs `frontend-exists` flag for downstream jobs + - Uploads frontend build artifacts + +**Modified Jobs:** +- `build-wheel` - Enhanced to include frontend builds + - Depends on `build-frontend` job + - Downloads frontend build artifacts to `static/` directory if `frontend-exists` is `true` + - Proceeds with standard wheel building from `template-python` + ### Docker Workflow (`docker.yml`) The Docker workflow runs on pushes and pull requests to the `main` branch, and supports manual dispatch.