Coleção de GitHub Actions personalizadas para automação de CI/CD, análise de código, deploy e notificações.
Deploy inteligente com rollback automático e health checks
Análise de qualidade de código com múltiplas ferramentas
Scanner de segurança abrangente para código e dependências
Testes de performance automatizados com relatórios
Deploy para múltiplos provedores de cloud
Sistema de notificações para múltiplas plataformas
Deploy inteligente com health checks e rollback automático.
- name: Smart Deploy
uses: lucasbehrooz/custom-github-action/smart-deploy@v1
with:
environment: 'production'
health-check-url: 'https://api.example.com/health'
rollback-on-failure: 'true'
deployment-timeout: '300'
notification-webhook: ${{ secrets.SLACK_WEBHOOK }}
Input | Description | Required | Default |
---|---|---|---|
environment |
Target environment | Yes | - |
health-check-url |
URL for health checks | Yes | - |
rollback-on-failure |
Auto rollback on failure | No | true |
deployment-timeout |
Timeout in seconds | No | 300 |
notification-webhook |
Webhook for notifications | No | - |
Output | Description |
---|---|
deployment-id |
Unique deployment identifier |
deployment-url |
URL of deployed application |
deployment-status |
Final deployment status |
name: Smart Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Application
run: |
docker build -t myapp:${{ github.sha }} .
docker push myapp:${{ github.sha }}
- name: Deploy to Production
uses: lucasbehrooz/custom-github-action/smart-deploy@v1
with:
environment: 'production'
health-check-url: 'https://myapp.com/health'
rollback-on-failure: 'true'
deployment-timeout: '600'
notification-webhook: ${{ secrets.SLACK_WEBHOOK }}
env:
KUBECONFIG: ${{ secrets.KUBECONFIG }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Análise abrangente de qualidade de código.
- name: Code Quality Gate
uses: lucasbehrooz/custom-github-action/quality-gate@v1
with:
sonar-token: ${{ secrets.SONAR_TOKEN }}
coverage-threshold: '80'
complexity-threshold: '10'
duplication-threshold: '3'
fail-on-quality-gate: 'true'
- SonarQube integration
- Code coverage analysis
- Complexity metrics
- Duplication detection
- Security hotspots
- Technical debt calculation
name: Quality Gate
on:
pull_request:
branches: [main]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
run: npm run test:coverage
- name: Code Quality Gate
uses: lucasbehrooz/custom-github-action/quality-gate@v1
with:
sonar-token: ${{ secrets.SONAR_TOKEN }}
coverage-threshold: '80'
complexity-threshold: '10'
duplication-threshold: '3'
fail-on-quality-gate: 'true'
github-token: ${{ secrets.GITHUB_TOKEN }}
Scanner de segurança abrangente.
- name: Security Scanner
uses: lucasbehrooz/custom-github-action/security-scanner@v1
with:
scan-type: 'full'
sarif-upload: 'true'
fail-on-high: 'true'
exclude-paths: 'tests/,docs/'
- SAST (Static Application Security Testing)
- Dependency vulnerability scanning
- Container image scanning
- Infrastructure as Code scanning
- Secret detection
- License compliance
name: Security Scan
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 2 * * *'
jobs:
security:
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Security Scanner
uses: lucasbehrooz/custom-github-action/security-scanner@v1
with:
scan-type: 'full'
sarif-upload: 'true'
fail-on-high: 'true'
exclude-paths: 'tests/,docs/'
snyk-token: ${{ secrets.SNYK_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
Testes de performance automatizados.
- name: Performance Test
uses: lucasbehrooz/custom-github-action/performance-tester@v1
with:
target-url: 'https://api.example.com'
test-duration: '60s'
virtual-users: '50'
ramp-up-time: '10s'
success-criteria: 'avg_response_time<500ms,error_rate<1%'
- Load testing with K6
- Performance regression detection
- Detailed HTML reports
- Slack/Teams notifications
- Performance budgets
- Trend analysis
name: Performance Test
on:
deployment_status:
jobs:
performance:
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Performance Test
uses: lucasbehrooz/custom-github-action/performance-tester@v1
with:
target-url: ${{ github.event.deployment_status.target_url }}
test-duration: '120s'
virtual-users: '100'
ramp-up-time: '30s'
success-criteria: 'avg_response_time<500ms,error_rate<1%,p95_response_time<1000ms'
notification-webhook: ${{ secrets.SLACK_WEBHOOK }}
- name: Upload Performance Report
uses: actions/upload-artifact@v3
if: always()
with:
name: performance-report
path: performance-report.html
Deploy para múltiplos provedores de cloud.
- name: Multi-Cloud Deploy
uses: lucasbehrooz/custom-github-action/multi-cloud-deploy@v1
with:
providers: 'aws,azure,gcp'
strategy: 'blue-green'
health-check-enabled: 'true'
rollback-on-failure: 'true'
- AWS (ECS, EKS, Lambda, Elastic Beanstalk)
- Azure (AKS, Container Instances, App Service)
- GCP (GKE, Cloud Run, App Engine)
- DigitalOcean (Kubernetes, App Platform)
name: Multi-Cloud Deploy
on:
release:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
cloud: [aws, azure, gcp]
steps:
- uses: actions/checkout@v4
- name: Deploy to ${{ matrix.cloud }}
uses: lucasbehrooz/custom-github-action/multi-cloud-deploy@v1
with:
provider: ${{ matrix.cloud }}
strategy: 'blue-green'
health-check-enabled: 'true'
rollback-on-failure: 'true'
config-file: 'deploy-config.yaml'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }}
Sistema de notificações para múltiplas plataformas.
- name: Send Notifications
uses: lucasbehrooz/custom-github-action/notification-hub@v1
with:
platforms: 'slack,teams,email,discord'
template: 'deployment-success'
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
teams-webhook: ${{ secrets.TEAMS_WEBHOOK }}
email-smtp-server: 'smtp.gmail.com'
email-username: ${{ secrets.EMAIL_USERNAME }}
email-password: ${{ secrets.EMAIL_PASSWORD }}
- Slack
- Microsoft Teams
- Discord
- Email (SMTP)
- Telegram
- WhatsApp Business API
- Custom webhooks
name: Notification Example
on:
workflow_run:
workflows: ["CI/CD Pipeline"]
types: [completed]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Notify Success
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: lucasbehrooz/custom-github-action/notification-hub@v1
with:
platforms: 'slack,teams,email'
template: 'deployment-success'
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
teams-webhook: ${{ secrets.TEAMS_WEBHOOK }}
email-recipients: 'team@company.com'
email-smtp-server: 'smtp.gmail.com'
email-username: ${{ secrets.EMAIL_USERNAME }}
email-password: ${{ secrets.EMAIL_PASSWORD }}
custom-data: |
{
"repository": "${{ github.repository }}",
"branch": "${{ github.ref_name }}",
"commit": "${{ github.sha }}",
"author": "${{ github.actor }}"
}
- name: Notify Failure
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
uses: lucasbehrooz/custom-github-action/notification-hub@v1
with:
platforms: 'slack,email'
template: 'deployment-failure'
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
email-recipients: 'devops@company.com'
email-smtp-server: 'smtp.gmail.com'
email-username: ${{ secrets.EMAIL_USERNAME }}
email-password: ${{ secrets.EMAIL_PASSWORD }}
smart-deploy/
├── action.yml # Action metadata
├── Dockerfile # Container definition
├── entrypoint.sh # Entry point script
├── src/
│ ├── deploy.py # Main deployment logic
│ ├── health_check.py # Health check utilities
│ ├── rollback.py # Rollback functionality
│ └── notifications.py # Notification system
├── tests/
│ ├── test_deploy.py
│ └── test_health_check.py
└── README.md
name: 'Smart Deploy'
description: 'Intelligent deployment with health checks and automatic rollback'
author: 'Lucas Behrooz'
inputs:
environment:
description: 'Target deployment environment'
required: true
health-check-url:
description: 'URL for health checks'
required: true
rollback-on-failure:
description: 'Enable automatic rollback on failure'
required: false
default: 'true'
deployment-timeout:
description: 'Deployment timeout in seconds'
required: false
default: '300'
notification-webhook:
description: 'Webhook URL for notifications'
required: false
outputs:
deployment-id:
description: 'Unique deployment identifier'
deployment-url:
description: 'URL of deployed application'
deployment-status:
description: 'Final deployment status'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.environment }}
- ${{ inputs.health-check-url }}
- ${{ inputs.rollback-on-failure }}
- ${{ inputs.deployment-timeout }}
- ${{ inputs.notification-webhook }}
branding:
icon: 'upload-cloud'
color: 'blue'
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
jq \
git \
&& rm -rf /var/lib/apt/lists/*
# Install kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
&& chmod +x kubectl \
&& mv kubectl /usr/local/bin/
# Install AWS CLI
RUN pip install awscli
# Copy action code
COPY src/ /app/src/
COPY requirements.txt /app/
COPY entrypoint.sh /app/
# Install Python dependencies
RUN pip install -r /app/requirements.txt
# Make entrypoint executable
RUN chmod +x /app/entrypoint.sh
WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]
#!/bin/bash
set -e
# Parse inputs
ENVIRONMENT=$1
HEALTH_CHECK_URL=$2
ROLLBACK_ON_FAILURE=$3
DEPLOYMENT_TIMEOUT=$4
NOTIFICATION_WEBHOOK=$5
echo "Starting deployment to $ENVIRONMENT"
echo "Health check URL: $HEALTH_CHECK_URL"
echo "Rollback on failure: $ROLLBACK_ON_FAILURE"
echo "Deployment timeout: $DEPLOYMENT_TIMEOUT seconds"
# Set GitHub outputs
echo "deployment-id=$(uuidgen)" >> $GITHUB_OUTPUT
echo "deployment-url=$HEALTH_CHECK_URL" >> $GITHUB_OUTPUT
# Execute Python deployment script
python /app/src/deploy.py \
--environment "$ENVIRONMENT" \
--health-check-url "$HEALTH_CHECK_URL" \
--rollback-on-failure "$ROLLBACK_ON_FAILURE" \
--deployment-timeout "$DEPLOYMENT_TIMEOUT" \
--notification-webhook "$NOTIFICATION_WEBHOOK"
# Set final status
if [ $? -eq 0 ]; then
echo "deployment-status=success" >> $GITHUB_OUTPUT
echo "✅ Deployment completed successfully"
else
echo "deployment-status=failure" >> $GITHUB_OUTPUT
echo "❌ Deployment failed"
exit 1
fi
# Install act
curl https://github.com/nektos/act/master/install.sh | sudo bash
# Test action locally
act -j test-action --secret-file .secrets
# Test with specific event
act push --secret-file .secrets
# tests/test_deploy.py
import unittest
from unittest.mock import patch, MagicMock
from src.deploy import DeploymentManager
class TestDeploymentManager(unittest.TestCase):
def setUp(self):
self.deployment_manager = DeploymentManager(
environment='test',
health_check_url='http://test.com/health',
rollback_on_failure=True,
deployment_timeout=300
)
@patch('src.deploy.requests.get')
def test_health_check_success(self, mock_get):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {'status': 'healthy'}
mock_get.return_value = mock_response
result = self.deployment_manager.health_check()
self.assertTrue(result)
@patch('src.deploy.subprocess.run')
def test_deployment_success(self, mock_run):
mock_run.return_value.returncode = 0
result = self.deployment_manager.deploy()
self.assertTrue(result)
if __name__ == '__main__':
unittest.main()
# .github/workflows/test-actions.yml
name: Test Actions
on:
push:
paths:
- 'smart-deploy/**'
- 'quality-gate/**'
- 'security-scanner/**'
jobs:
test-smart-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test Smart Deploy Action
uses: ./smart-deploy
with:
environment: 'test'
health-check-url: 'https://httpbin.org/status/200'
rollback-on-failure: 'false'
deployment-timeout: '60'
test-quality-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Create test project
run: |
npm init -y
echo "console.log('Hello World');" > index.js
- name: Test Quality Gate Action
uses: ./quality-gate
with:
coverage-threshold: '0'
complexity-threshold: '20'
fail-on-quality-gate: 'false'
# Action Name
Brief description of what the action does.
## Usage
```yaml
- uses: lucasbehrooz/custom-github-action/action-name@v1
with:
input1: 'value1'
input2: 'value2'
Name | Description | Required | Default |
---|---|---|---|
input1 |
Description of input1 | Yes | - |
input2 |
Description of input2 | No | default |
Name | Description |
---|---|
output1 |
Description of output1 |
[Example workflow]
[Advanced example workflow]
Common issues and solutions.
## 🚀 Publishing Actions
### GitHub Marketplace
1. Create release with semantic versioning
2. Add marketplace metadata to `action.yml`
3. Submit to GitHub Marketplace
4. Add marketplace badges to README
### Versioning Strategy
```bash
# Create and push tags
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin v1.0.0
# Update major version tag
git tag -fa v1 -m "Update v1 tag"
git push origin v1 --force
# src/analytics.py
import requests
import json
from datetime import datetime
def track_usage(action_name, inputs, outputs, duration):
"""Track action usage for analytics"""
data = {
'action': action_name,
'timestamp': datetime.utcnow().isoformat(),
'inputs': inputs,
'outputs': outputs,
'duration': duration,
'repository': os.getenv('GITHUB_REPOSITORY'),
'workflow': os.getenv('GITHUB_WORKFLOW'),
'run_id': os.getenv('GITHUB_RUN_ID')
}
# Send to analytics endpoint (optional)
analytics_url = os.getenv('ANALYTICS_WEBHOOK')
if analytics_url:
try:
requests.post(analytics_url, json=data, timeout=5)
except:
pass # Don't fail action if analytics fails
# Clone repository
git clone https://github.com/lucasbehrooz/custom-github-action.git
cd custom-github-action
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
python -m pytest tests/
# Run linting
flake8 src/
black src/
- Fork o projeto
- Crie uma feature branch
- Adicione testes para novas funcionalidades
- Commit suas mudanças
- Push para a branch
- Abra um Pull Request
MIT License