fix: delete retired workflows and fix duplicate env: [skip ci]
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,325 +0,0 @@
|
||||
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# This file is part of a Moko Consulting project.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: GitHub.Workflow
|
||||
# INGROUP: MokoStandards.Quality
|
||||
# REPO: https://github.com/mokoconsulting-tech/MokoStandards
|
||||
# PATH: /templates/workflows/generic/code-quality.yml
|
||||
# VERSION: 01.00.00
|
||||
# BRIEF: Comprehensive code quality analysis workflow
|
||||
# NOTE: Supports multiple linters, formatters, and static analysis tools
|
||||
|
||||
name: Code Quality
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev/**
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- dev/**
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
security-events: write
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Linting & Formatting
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Detect project type
|
||||
id: detect
|
||||
run: |
|
||||
if [ -f "package.json" ]; then
|
||||
echo "type=nodejs" >> $GITHUB_OUTPUT
|
||||
elif [ -f "requirements.txt" ] || [ -f "setup.py" ]; then
|
||||
echo "type=python" >> $GITHUB_OUTPUT
|
||||
elif [ -f "composer.json" ]; then
|
||||
echo "type=php" >> $GITHUB_OUTPUT
|
||||
elif [ -f "go.mod" ]; then
|
||||
echo "type=go" >> $GITHUB_OUTPUT
|
||||
elif [ -f "Cargo.toml" ]; then
|
||||
echo "type=rust" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "type=unknown" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# Node.js linting
|
||||
- name: Setup Node.js
|
||||
if: steps.detect.outputs.type == 'nodejs'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20.x'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Node dependencies
|
||||
if: steps.detect.outputs.type == 'nodejs'
|
||||
run: npm ci
|
||||
|
||||
- name: Run ESLint
|
||||
if: steps.detect.outputs.type == 'nodejs'
|
||||
run: |
|
||||
npm run lint || npx eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 || true
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run Prettier
|
||||
if: steps.detect.outputs.type == 'nodejs'
|
||||
run: |
|
||||
npx prettier --check . || true
|
||||
continue-on-error: true
|
||||
|
||||
# Python linting
|
||||
- name: Setup Python
|
||||
if: steps.detect.outputs.type == 'python'
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install Python linters
|
||||
if: steps.detect.outputs.type == 'python'
|
||||
run: |
|
||||
pip install flake8 black isort mypy pylint bandit
|
||||
|
||||
- name: Run Flake8
|
||||
if: steps.detect.outputs.type == 'python'
|
||||
run: |
|
||||
flake8 . --count --statistics --show-source
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run Black
|
||||
if: steps.detect.outputs.type == 'python'
|
||||
run: |
|
||||
black --check .
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run isort
|
||||
if: steps.detect.outputs.type == 'python'
|
||||
run: |
|
||||
isort --check-only .
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run Pylint
|
||||
if: steps.detect.outputs.type == 'python'
|
||||
run: |
|
||||
pylint **/*.py || true
|
||||
continue-on-error: true
|
||||
|
||||
# PHP linting
|
||||
- name: Setup PHP
|
||||
if: steps.detect.outputs.type == 'php'
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
tools: composer, phpcs, php-cs-fixer, phpstan, psalm
|
||||
|
||||
- name: Install PHP dependencies
|
||||
if: steps.detect.outputs.type == 'php'
|
||||
run: composer install --prefer-dist
|
||||
|
||||
- name: Run PHP_CodeSniffer
|
||||
if: steps.detect.outputs.type == 'php'
|
||||
run: |
|
||||
phpcs --standard=PSR12 --report=summary . || true
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run PHP-CS-Fixer
|
||||
if: steps.detect.outputs.type == 'php'
|
||||
run: |
|
||||
php-cs-fixer fix --dry-run --diff . || true
|
||||
continue-on-error: true
|
||||
|
||||
# Go linting
|
||||
- name: Setup Go
|
||||
if: steps.detect.outputs.type == 'go'
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.22'
|
||||
|
||||
- name: Run golangci-lint
|
||||
if: steps.detect.outputs.type == 'go'
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- name: Run go fmt
|
||||
if: steps.detect.outputs.type == 'go'
|
||||
run: |
|
||||
if [ -n "$(gofmt -l .)" ]; then
|
||||
echo "Go files are not formatted:"
|
||||
gofmt -l .
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Rust linting
|
||||
- name: Setup Rust
|
||||
if: steps.detect.outputs.type == 'rust'
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
components: clippy, rustfmt
|
||||
|
||||
- name: Run cargo fmt
|
||||
if: steps.detect.outputs.type == 'rust'
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
- name: Run cargo clippy
|
||||
if: steps.detect.outputs.type == 'rust'
|
||||
run: cargo clippy --all-targets --all-features -- -D warnings
|
||||
|
||||
static-analysis:
|
||||
name: Static Analysis
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Run CodeQL Analysis
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: javascript, python, go
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v4
|
||||
|
||||
dependency-check:
|
||||
name: Dependency Security Check
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Run Snyk Security Check
|
||||
uses: snyk/actions/node@master
|
||||
continue-on-error: true
|
||||
env:
|
||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
|
||||
- name: Run npm audit
|
||||
if: hashFiles('package-lock.json') != ''
|
||||
run: npm audit --audit-level=moderate || true
|
||||
|
||||
- name: Run pip safety check
|
||||
if: hashFiles('requirements.txt') != ''
|
||||
run: |
|
||||
pip install safety
|
||||
safety check -r requirements.txt || true
|
||||
|
||||
complexity:
|
||||
name: Code Complexity Analysis
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install radon
|
||||
run: pip install radon
|
||||
|
||||
- name: Calculate cyclomatic complexity
|
||||
run: |
|
||||
if [ -d "src" ] || [ -d "lib" ]; then
|
||||
radon cc . -a -nb || true
|
||||
fi
|
||||
|
||||
- name: Calculate maintainability index
|
||||
run: |
|
||||
if [ -d "src" ] || [ -d "lib" ]; then
|
||||
radon mi . -nb || true
|
||||
fi
|
||||
|
||||
coverage:
|
||||
name: Code Coverage Analysis
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Detect project type
|
||||
id: detect
|
||||
run: |
|
||||
if [ -f "package.json" ]; then
|
||||
echo "type=nodejs" >> $GITHUB_OUTPUT
|
||||
elif [ -f "requirements.txt" ]; then
|
||||
echo "type=python" >> $GITHUB_OUTPUT
|
||||
elif [ -f "go.mod" ]; then
|
||||
echo "type=go" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Setup and run coverage
|
||||
run: |
|
||||
TYPE="${{ steps.detect.outputs.type }}"
|
||||
|
||||
case $TYPE in
|
||||
nodejs)
|
||||
npm ci
|
||||
npm test -- --coverage || true
|
||||
;;
|
||||
python)
|
||||
pip install pytest pytest-cov
|
||||
pytest --cov=. --cov-report=xml || true
|
||||
;;
|
||||
go)
|
||||
go test -coverprofile=coverage.out ./... || true
|
||||
;;
|
||||
esac
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./coverage.xml,./coverage.out
|
||||
flags: quality-check
|
||||
|
||||
summary:
|
||||
name: Quality Summary
|
||||
runs-on: ubuntu-latest
|
||||
needs: [lint, static-analysis, dependency-check, complexity, coverage]
|
||||
if: always()
|
||||
|
||||
steps:
|
||||
- name: Generate quality report
|
||||
run: |
|
||||
echo "### Code Quality Summary" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Repository: $GITHUB_REPOSITORY" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Branch: $GITHUB_REF_NAME" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Commit: $GITHUB_SHA" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Quality checks completed:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Linting: ${{ needs.lint.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Static Analysis: ${{ needs.static-analysis.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Dependencies: ${{ needs.dependency-check.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Complexity: ${{ needs.complexity.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Coverage: ${{ needs.coverage.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -1,281 +0,0 @@
|
||||
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# This file is part of a Moko Consulting project.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: GitHub.Workflow
|
||||
# INGROUP: MokoStandards.Deploy
|
||||
# REPO: https://github.com/mokoconsulting-tech/MokoStandards
|
||||
# PATH: /templates/workflows/generic/deploy.yml
|
||||
# VERSION: 03.01.03
|
||||
# BRIEF: Deployment workflow for various environments
|
||||
# NOTE: Supports staging, production, and other custom environments
|
||||
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- staging
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
description: 'Deployment environment'
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- staging
|
||||
- production
|
||||
version:
|
||||
description: 'Version to deploy (optional)'
|
||||
required: false
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
deployments: write
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
name: Prepare Deployment
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
environment: ${{ steps.determine-env.outputs.environment }}
|
||||
version: ${{ steps.determine-version.outputs.version }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Determine environment
|
||||
id: determine-env
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
||||
ENV="${{ inputs.environment }}"
|
||||
elif [ "${{ github.event_name }}" == "release" ]; then
|
||||
ENV="production"
|
||||
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||
ENV="production"
|
||||
elif [ "${{ github.ref }}" == "refs/heads/staging" ]; then
|
||||
ENV="staging"
|
||||
else
|
||||
ENV="development"
|
||||
fi
|
||||
echo "environment=${ENV}" >> $GITHUB_OUTPUT
|
||||
echo "Deploying to: ${ENV}"
|
||||
|
||||
- name: Determine version
|
||||
id: determine-version
|
||||
run: |
|
||||
if [ "${{ inputs.version }}" != "" ]; then
|
||||
VERSION="${{ inputs.version }}"
|
||||
elif [ "${{ github.event_name }}" == "release" ]; then
|
||||
VERSION="${{ github.event.release.tag_name }}"
|
||||
else
|
||||
VERSION="$(git describe --tags --always)"
|
||||
fi
|
||||
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||
echo "Version: ${VERSION}"
|
||||
|
||||
build:
|
||||
name: Build Application
|
||||
runs-on: ubuntu-latest
|
||||
needs: prepare
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup build environment
|
||||
run: |
|
||||
if [ -f "package.json" ]; then
|
||||
echo "BUILD_TYPE=nodejs" >> $GITHUB_ENV
|
||||
elif [ -f "requirements.txt" ]; then
|
||||
echo "BUILD_TYPE=python" >> $GITHUB_ENV
|
||||
elif [ -f "go.mod" ]; then
|
||||
echo "BUILD_TYPE=go" >> $GITHUB_ENV
|
||||
elif [ -f "Cargo.toml" ]; then
|
||||
echo "BUILD_TYPE=rust" >> $GITHUB_ENV
|
||||
else
|
||||
echo "BUILD_TYPE=generic" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
if: env.BUILD_TYPE == 'nodejs'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20.x'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Setup Python
|
||||
if: env.BUILD_TYPE == 'python'
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Setup Go
|
||||
if: env.BUILD_TYPE == 'go'
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.22'
|
||||
|
||||
- name: Build application
|
||||
run: |
|
||||
case $BUILD_TYPE in
|
||||
nodejs)
|
||||
npm ci
|
||||
npm run build
|
||||
;;
|
||||
python)
|
||||
pip install -r requirements.txt
|
||||
python setup.py build 2>/dev/null || echo "No setup.py found"
|
||||
;;
|
||||
go)
|
||||
go build -o app ./...
|
||||
;;
|
||||
rust)
|
||||
cargo build --release
|
||||
;;
|
||||
generic)
|
||||
echo "Generic build - no specific build steps"
|
||||
;;
|
||||
esac
|
||||
|
||||
- name: Create deployment package
|
||||
run: |
|
||||
mkdir -p dist
|
||||
|
||||
case $BUILD_TYPE in
|
||||
nodejs)
|
||||
if [ -d "build" ]; then cp -r build/* dist/; fi
|
||||
if [ -d "dist" ]; then cp -r dist/* dist/; fi
|
||||
;;
|
||||
python)
|
||||
if [ -d "build" ]; then cp -r build/* dist/; fi
|
||||
;;
|
||||
go)
|
||||
if [ -f "app" ]; then cp app dist/; fi
|
||||
;;
|
||||
rust)
|
||||
if [ -f "target/release/app" ]; then cp target/release/app dist/; fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Add version file
|
||||
echo "${{ needs.prepare.outputs.version }}" > dist/VERSION
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: deployment-package
|
||||
path: dist/
|
||||
retention-days: 7
|
||||
|
||||
deploy-staging:
|
||||
name: Deploy to Staging
|
||||
runs-on: ubuntu-latest
|
||||
needs: [prepare, build]
|
||||
if: needs.prepare.outputs.environment == 'staging' || needs.prepare.outputs.environment == 'development'
|
||||
environment:
|
||||
name: staging
|
||||
url: https://staging.example.com
|
||||
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4.1.3
|
||||
with:
|
||||
name: deployment-package
|
||||
path: ./dist
|
||||
|
||||
- name: Deploy to staging
|
||||
run: |
|
||||
echo "Deploying version ${{ needs.prepare.outputs.version }} to staging"
|
||||
# Add your staging deployment commands here
|
||||
# Examples:
|
||||
# - rsync to staging server
|
||||
# - kubectl apply for Kubernetes
|
||||
# - aws s3 sync for S3
|
||||
# - heroku git:remote for Heroku
|
||||
echo "Deployment completed"
|
||||
|
||||
- name: Run smoke tests
|
||||
run: |
|
||||
echo "Running smoke tests on staging..."
|
||||
# Add smoke test commands here
|
||||
# curl https://staging.example.com/health || exit 1
|
||||
|
||||
deploy-production:
|
||||
name: Deploy to Production
|
||||
runs-on: ubuntu-latest
|
||||
needs: [prepare, build]
|
||||
if: needs.prepare.outputs.environment == 'production'
|
||||
environment:
|
||||
name: production
|
||||
url: https://example.com
|
||||
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4.1.3
|
||||
with:
|
||||
name: deployment-package
|
||||
path: ./dist
|
||||
|
||||
- name: Deploy to production
|
||||
run: |
|
||||
echo "Deploying version ${{ needs.prepare.outputs.version }} to production"
|
||||
# Add your production deployment commands here
|
||||
echo "Deployment completed"
|
||||
|
||||
- name: Run smoke tests
|
||||
run: |
|
||||
echo "Running smoke tests on production..."
|
||||
# Add smoke test commands here
|
||||
|
||||
- name: Notify deployment
|
||||
run: |
|
||||
echo "### Deployment Successful! 🚀" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Environment: production" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Version: ${{ needs.prepare.outputs.version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- URL: https://example.com" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Deployed by: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
rollback:
|
||||
name: Rollback on Failure
|
||||
runs-on: ubuntu-latest
|
||||
needs: [deploy-staging, deploy-production]
|
||||
if: failure()
|
||||
|
||||
steps:
|
||||
- name: Rollback deployment
|
||||
run: |
|
||||
echo "Deployment failed. Initiating rollback..."
|
||||
# Add rollback commands here
|
||||
echo "Rollback completed"
|
||||
|
||||
- name: Notify failure
|
||||
run: |
|
||||
echo "### Deployment Failed ❌" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Rollback has been initiated." >> $GITHUB_STEP_SUMMARY
|
||||
echo "Please check the logs for more details." >> $GITHUB_STEP_SUMMARY
|
||||
@@ -1,292 +0,0 @@
|
||||
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# This file is part of a Moko Consulting project.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: GitHub.Workflow
|
||||
# INGROUP: MokoStandards.Testing
|
||||
# REPO: https://github.com/mokoconsulting-tech/MokoStandards
|
||||
# PATH: /templates/workflows/generic/test.yml
|
||||
# VERSION: 01.00.00
|
||||
# BRIEF: Comprehensive testing workflow for generic projects
|
||||
# NOTE: Supports unit, integration, and end-to-end testing
|
||||
|
||||
name: Test Suite
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev/**
|
||||
- rc/**
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- dev/**
|
||||
- rc/**
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
checks: write
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup environment
|
||||
run: |
|
||||
# Detect project type and setup accordingly
|
||||
if [ -f "package.json" ]; then
|
||||
echo "PROJECT_TYPE=nodejs" >> $GITHUB_ENV
|
||||
elif [ -f "requirements.txt" ] || [ -f "setup.py" ]; then
|
||||
echo "PROJECT_TYPE=python" >> $GITHUB_ENV
|
||||
elif [ -f "composer.json" ]; then
|
||||
echo "PROJECT_TYPE=php" >> $GITHUB_ENV
|
||||
elif [ -f "go.mod" ]; then
|
||||
echo "PROJECT_TYPE=go" >> $GITHUB_ENV
|
||||
elif [ -f "Gemfile" ]; then
|
||||
echo "PROJECT_TYPE=ruby" >> $GITHUB_ENV
|
||||
elif [ -f "Cargo.toml" ]; then
|
||||
echo "PROJECT_TYPE=rust" >> $GITHUB_ENV
|
||||
else
|
||||
echo "PROJECT_TYPE=unknown" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
if: env.PROJECT_TYPE == 'nodejs'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20.x'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Setup Python
|
||||
if: env.PROJECT_TYPE == 'python'
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
cache: 'pip'
|
||||
|
||||
- name: Setup PHP
|
||||
if: env.PROJECT_TYPE == 'php'
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
coverage: xdebug
|
||||
tools: composer:v2
|
||||
|
||||
- name: Setup Go
|
||||
if: env.PROJECT_TYPE == 'go'
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.22'
|
||||
cache: true
|
||||
|
||||
- name: Setup Ruby
|
||||
if: env.PROJECT_TYPE == 'ruby'
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: '3.2'
|
||||
bundler-cache: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
case $PROJECT_TYPE in
|
||||
nodejs) npm ci ;;
|
||||
python) pip install -r requirements.txt -r requirements-dev.txt 2>/dev/null || pip install pytest pytest-cov ;;
|
||||
php) composer install --prefer-dist ;;
|
||||
go) go mod download ;;
|
||||
ruby) bundle install ;;
|
||||
rust) cargo fetch ;;
|
||||
esac
|
||||
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
case $PROJECT_TYPE in
|
||||
nodejs) npm test ;;
|
||||
python) pytest tests/ --cov=. --cov-report=xml --cov-report=term ;;
|
||||
php) vendor/bin/phpunit --coverage-clover coverage.xml ;;
|
||||
go) go test -v -coverprofile=coverage.out ./... ;;
|
||||
ruby) bundle exec rspec || bundle exec rake test ;;
|
||||
rust) cargo test --all-features ;;
|
||||
*) echo "No tests configured for this project type" ;;
|
||||
esac
|
||||
|
||||
- name: Upload coverage reports
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./coverage.xml,./coverage.out
|
||||
flags: unittests
|
||||
name: codecov-unit
|
||||
|
||||
integration-tests:
|
||||
name: Integration Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15
|
||||
env:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: test_db
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
redis:
|
||||
image: redis:7
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 6379:6379
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup environment
|
||||
run: |
|
||||
if [ -f "package.json" ]; then
|
||||
echo "PROJECT_TYPE=nodejs" >> $GITHUB_ENV
|
||||
elif [ -f "requirements.txt" ]; then
|
||||
echo "PROJECT_TYPE=python" >> $GITHUB_ENV
|
||||
elif [ -f "composer.json" ]; then
|
||||
echo "PROJECT_TYPE=php" >> $GITHUB_ENV
|
||||
elif [ -f "go.mod" ]; then
|
||||
echo "PROJECT_TYPE=go" >> $GITHUB_ENV
|
||||
else
|
||||
echo "PROJECT_TYPE=unknown" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Setup runtime
|
||||
run: |
|
||||
case $PROJECT_TYPE in
|
||||
nodejs)
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
;;
|
||||
python)
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y python3 python3-pip
|
||||
;;
|
||||
php)
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y php php-cli php-mbstring php-xml
|
||||
;;
|
||||
go)
|
||||
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
|
||||
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz
|
||||
echo "/usr/local/go/bin" >> $GITHUB_PATH
|
||||
;;
|
||||
esac
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
case $PROJECT_TYPE in
|
||||
nodejs) npm ci ;;
|
||||
python) pip install -r requirements.txt ;;
|
||||
php) composer install ;;
|
||||
go) go mod download ;;
|
||||
esac
|
||||
|
||||
- name: Run integration tests
|
||||
env:
|
||||
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
|
||||
REDIS_URL: redis://localhost:6379
|
||||
run: |
|
||||
if [ -d "tests/integration" ] || [ -d "tests/Integration" ]; then
|
||||
case $PROJECT_TYPE in
|
||||
nodejs) npm run test:integration || npx jest tests/integration ;;
|
||||
python) pytest tests/integration/ -v ;;
|
||||
php) vendor/bin/phpunit --testsuite Integration ;;
|
||||
go) go test -v ./tests/integration/... ;;
|
||||
*) echo "No integration tests found" ;;
|
||||
esac
|
||||
else
|
||||
echo "No integration tests directory found"
|
||||
fi
|
||||
|
||||
e2e-tests:
|
||||
name: End-to-End Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20.x'
|
||||
|
||||
- name: Install Playwright
|
||||
run: |
|
||||
if [ -f "package.json" ] && grep -q "playwright" package.json; then
|
||||
npm ci
|
||||
npx playwright install --with-deps
|
||||
else
|
||||
echo "Playwright not configured, skipping"
|
||||
fi
|
||||
|
||||
- name: Run E2E tests
|
||||
run: |
|
||||
if [ -d "tests/e2e" ] || [ -d "e2e" ]; then
|
||||
npm run test:e2e || npx playwright test || echo "No E2E tests configured"
|
||||
else
|
||||
echo "No E2E tests directory found"
|
||||
fi
|
||||
|
||||
- name: Upload Playwright report
|
||||
uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
||||
|
||||
test-summary:
|
||||
name: Test Summary
|
||||
runs-on: ubuntu-latest
|
||||
needs: [unit-tests, integration-tests, e2e-tests]
|
||||
if: always()
|
||||
|
||||
steps:
|
||||
- name: Generate summary
|
||||
run: |
|
||||
echo "### Test Execution Summary" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Repository: $GITHUB_REPOSITORY" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Branch: $GITHUB_REF_NAME" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Commit: $GITHUB_SHA" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Test suites completed:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Unit tests: ${{ needs.unit-tests.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Integration tests: ${{ needs.integration-tests.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- E2E tests: ${{ needs.e2e-tests.result }}" >> $GITHUB_STEP_SUMMARY
|
||||
Reference in New Issue
Block a user