This repository was archived by the owner on Oct 25, 2025. It is now read-only.
π€ Auto-Fix Common Issues #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: π€ Auto-Fix Common Issues | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| fix_type: | |
| description: 'Type of fix to apply' | |
| required: true | |
| default: 'all' | |
| type: choice | |
| options: | |
| - all | |
| - linting | |
| - dependencies | |
| - formatting | |
| - security | |
| schedule: | |
| # Run weekly maintenance on Sundays at 2 AM | |
| - cron: '0 2 * * 0' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| auto-fix: | |
| name: π§ Automated Maintenance | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - name: π₯ Checkout code | |
| uses: actions/checkout@v5.0.0 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: βοΈ Set up Node.js 22.x | |
| uses: actions/setup-node@v4.4.0 | |
| with: | |
| node-version: 22.x | |
| - name: π Set up Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: π¦ Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: π§Ή Auto-fix linting and formatting | |
| if: github.event.inputs.fix_type == 'all' || github.event.inputs.fix_type == 'linting' || github.event.inputs.fix_type == 'formatting' | |
| run: | | |
| echo "π§Ή Running auto-fix for linting and formatting..." | |
| # Save current state | |
| git stash push -m "Pre-autofix state" || true | |
| # Apply fixes | |
| bun run lint:fix || true | |
| bun run format || true | |
| # Check for changes | |
| if ! git diff --quiet; then | |
| echo "β Applied auto-fixes" | |
| echo "LINTING_FIXED=true" >> $GITHUB_ENV | |
| else | |
| echo "βΉοΈ No linting issues to fix" | |
| echo "LINTING_FIXED=false" >> $GITHUB_ENV | |
| fi | |
| - name: π Security updates | |
| if: github.event.inputs.fix_type == 'all' || github.event.inputs.fix_type == 'security' | |
| run: | | |
| echo "π Checking for security updates..." | |
| # Check for vulnerabilities | |
| if npm audit --audit-level=moderate; then | |
| echo "β No security vulnerabilities found" | |
| echo "SECURITY_FIXED=false" >> $GITHUB_ENV | |
| else | |
| echo "π§ Applying security fixes..." | |
| npm audit fix --force || true | |
| if ! git diff --quiet package*.json; then | |
| echo "β Applied security fixes" | |
| echo "SECURITY_FIXED=true" >> $GITHUB_ENV | |
| else | |
| echo "βΉοΈ No security fixes applied" | |
| echo "SECURITY_FIXED=false" >> $GITHUB_ENV | |
| fi | |
| fi | |
| - name: π¦ Update dependencies | |
| if: github.event.inputs.fix_type == 'all' || github.event.inputs.fix_type == 'dependencies' | |
| run: | | |
| echo "π¦ Checking for dependency updates..." | |
| # Check for outdated packages (excluding major versions) | |
| npm outdated --json > outdated.json || true | |
| if [ -s outdated.json ]; then | |
| echo "π¦ Found outdated dependencies" | |
| # Update patch and minor versions only | |
| npx npm-check-updates -u --target minor || true | |
| npm install || true | |
| if ! git diff --quiet package*.json; then | |
| echo "β Updated dependencies" | |
| echo "DEPS_UPDATED=true" >> $GITHUB_ENV | |
| else | |
| echo "βΉοΈ No dependency updates available" | |
| echo "DEPS_UPDATED=false" >> $GITHUB_ENV | |
| fi | |
| else | |
| echo "β All dependencies are up to date" | |
| echo "DEPS_UPDATED=false" >> $GITHUB_ENV | |
| fi | |
| rm -f outdated.json | |
| - name: π§ͺ Validate changes | |
| if: contains(github.env, 'LINTING_FIXED=true') || contains(github.env, 'SECURITY_FIXED=true') || contains(github.env, 'DEPS_UPDATED=true') | |
| run: | | |
| echo "π§ͺ Validating all changes..." | |
| # Run validation pipeline | |
| npm run validate | |
| if [ $? -eq 0 ]; then | |
| echo "β All validations passed" | |
| echo "VALIDATION_PASSED=true" >> $GITHUB_ENV | |
| else | |
| echo "β Validation failed, reverting changes" | |
| git reset --hard HEAD | |
| git clean -fd | |
| echo "VALIDATION_PASSED=false" >> $GITHUB_ENV | |
| exit 1 | |
| fi | |
| - name: π Generate change summary | |
| if: contains(github.env, 'VALIDATION_PASSED=true') | |
| id: changes | |
| run: | | |
| echo "π Generating change summary..." | |
| SUMMARY="" | |
| if [ "$LINTING_FIXED" = "true" ]; then | |
| SUMMARY="$SUMMARY\n- π§Ή Applied Biome linting and formatting fixes" | |
| fi | |
| if [ "$SECURITY_FIXED" = "true" ]; then | |
| SUMMARY="$SUMMARY\n- π Applied security updates" | |
| fi | |
| if [ "$DEPS_UPDATED" = "true" ]; then | |
| SUMMARY="$SUMMARY\n- π¦ Updated dependencies" | |
| fi | |
| if [ -n "$SUMMARY" ]; then | |
| echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT | |
| echo "SUMMARY<<EOF" >> $GITHUB_OUTPUT | |
| echo -e "$SUMMARY" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| else | |
| echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: π Commit and push changes | |
| if: steps.changes.outputs.HAS_CHANGES == 'true' | |
| run: | | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add . | |
| git commit -m "π€ Auto-maintenance: Weekly fixes and updates | |
| ${{ steps.changes.outputs.SUMMARY }} | |
| - π Automated by GitHub Actions (scheduled) | |
| - β All validations passed | |
| - π Run on: $(date +'%Y-%m-%d %H:%M:%S UTC') | |
| [skip ci]" | |
| git push | |
| - name: π Report results | |
| if: always() | |
| run: | | |
| echo "π Auto-fix Results Summary:" | |
| echo "π§Ή Linting fixes applied: ${LINTING_FIXED:-false}" | |
| echo "π Security fixes applied: ${SECURITY_FIXED:-false}" | |
| echo "π¦ Dependencies updated: ${DEPS_UPDATED:-false}" | |
| echo "β Validation passed: ${VALIDATION_PASSED:-false}" | |
| if [ "${{ steps.changes.outputs.HAS_CHANGES }}" = "true" ]; then | |
| echo "π Auto-maintenance completed successfully!" | |
| else | |
| echo "βΉοΈ No changes were needed" | |
| fi |