mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 11:34:00 +00:00
This commit updates all internal action references to point to the current commit SHA in preparation for release v2025.10.26.
185 lines
5.6 KiB
YAML
185 lines
5.6 KiB
YAML
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
|
|
# permissions:
|
|
# - contents: write # Required for pushing fixes back to repository
|
|
---
|
|
name: ESLint Fix
|
|
description: Fixes ESLint violations in a project.
|
|
author: 'Ismo Vuorinen'
|
|
|
|
branding:
|
|
icon: 'code'
|
|
color: 'blue'
|
|
|
|
inputs:
|
|
token:
|
|
description: 'GitHub token for authentication'
|
|
required: false
|
|
default: ${{ github.token }}
|
|
username:
|
|
description: 'GitHub username for commits'
|
|
required: false
|
|
default: 'github-actions'
|
|
email:
|
|
description: 'GitHub email for commits'
|
|
required: false
|
|
default: 'github-actions@github.com'
|
|
max-retries:
|
|
description: 'Maximum number of retry attempts for npm install operations'
|
|
required: false
|
|
default: '3'
|
|
|
|
outputs:
|
|
files_changed:
|
|
description: 'Number of files changed by ESLint'
|
|
value: ${{ steps.lint.outputs.files_changed }}
|
|
lint_status:
|
|
description: 'Linting status (success/failure)'
|
|
value: ${{ steps.lint.outputs.status }}
|
|
errors_fixed:
|
|
description: 'Number of errors fixed'
|
|
value: ${{ steps.lint.outputs.errors_fixed }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Validate Inputs
|
|
id: validate
|
|
uses: ivuorinen/actions/validate-inputs@e2222afff180ee77f330ef4325f60d6e85477c01
|
|
with:
|
|
action-type: 'eslint-fix'
|
|
token: ${{ inputs.token }}
|
|
email: ${{ inputs.email }}
|
|
username: ${{ inputs.username }}
|
|
max-retries: ${{ inputs.max-retries }}
|
|
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
with:
|
|
token: ${{ inputs.token }}
|
|
|
|
- name: Set Git Config
|
|
uses: ivuorinen/actions/set-git-config@e2222afff180ee77f330ef4325f60d6e85477c01
|
|
with:
|
|
token: ${{ inputs.token }}
|
|
username: ${{ inputs.username }}
|
|
email: ${{ inputs.email }}
|
|
|
|
- name: Node Setup
|
|
id: node-setup
|
|
uses: ivuorinen/actions/node-setup@e2222afff180ee77f330ef4325f60d6e85477c01
|
|
|
|
- name: Cache Node Dependencies
|
|
id: cache
|
|
uses: ivuorinen/actions/common-cache@e2222afff180ee77f330ef4325f60d6e85477c01
|
|
with:
|
|
type: 'npm'
|
|
paths: 'node_modules'
|
|
key-files: 'package-lock.json,yarn.lock,pnpm-lock.yaml,bun.lockb'
|
|
key-prefix: 'eslint-fix-${{ steps.node-setup.outputs.package-manager }}'
|
|
|
|
- name: Install Dependencies
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
shell: bash
|
|
env:
|
|
PACKAGE_MANAGER: ${{ steps.node-setup.outputs.package-manager }}
|
|
MAX_RETRIES: ${{ inputs.max-retries }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
echo "Installing dependencies using $PACKAGE_MANAGER..."
|
|
|
|
for attempt in $(seq 1 "$MAX_RETRIES"); do
|
|
echo "Attempt $attempt of $MAX_RETRIES"
|
|
|
|
case "$PACKAGE_MANAGER" in
|
|
"pnpm")
|
|
if pnpm install --frozen-lockfile; then
|
|
echo "✅ Dependencies installed successfully with pnpm"
|
|
exit 0
|
|
fi
|
|
;;
|
|
"yarn")
|
|
if [ -f ".yarnrc.yml" ]; then
|
|
if yarn install --immutable; then
|
|
echo "✅ Dependencies installed successfully with Yarn Berry"
|
|
exit 0
|
|
fi
|
|
else
|
|
if yarn install --frozen-lockfile; then
|
|
echo "✅ Dependencies installed successfully with Yarn Classic"
|
|
exit 0
|
|
fi
|
|
fi
|
|
;;
|
|
"bun")
|
|
if bun install --frozen-lockfile; then
|
|
echo "✅ Dependencies installed successfully with Bun"
|
|
exit 0
|
|
fi
|
|
;;
|
|
"npm"|*)
|
|
if npm ci; then
|
|
echo "✅ Dependencies installed successfully with npm"
|
|
exit 0
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
if [ $attempt -lt "$MAX_RETRIES" ]; then
|
|
echo "❌ Installation failed, retrying in 5 seconds..."
|
|
sleep 5
|
|
fi
|
|
done
|
|
|
|
echo "::error::Failed to install dependencies after $MAX_RETRIES attempts"
|
|
exit 1
|
|
|
|
- name: Run ESLint Fix
|
|
id: lint
|
|
shell: bash
|
|
env:
|
|
PACKAGE_MANAGER: ${{ steps.node-setup.outputs.package-manager }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
echo "Running ESLint fix with $PACKAGE_MANAGER..."
|
|
|
|
# Count files before fix
|
|
files_before=$(git status --porcelain | wc -l || echo "0")
|
|
|
|
# Run ESLint fix based on package manager
|
|
case "$PACKAGE_MANAGER" in
|
|
"pnpm")
|
|
pnpm exec eslint . --fix || true
|
|
;;
|
|
"yarn")
|
|
yarn eslint . --fix || true
|
|
;;
|
|
"bun")
|
|
bunx eslint . --fix || true
|
|
;;
|
|
"npm"|*)
|
|
npx eslint . --fix || true
|
|
;;
|
|
esac
|
|
|
|
# Count files after fix
|
|
files_after=$(git status --porcelain | wc -l || echo "0")
|
|
files_changed=$((files_after - files_before))
|
|
|
|
# Get number of staged changes
|
|
errors_fixed=$(git diff --cached --numstat | wc -l || echo "0")
|
|
|
|
echo "files_changed=$files_changed" >> $GITHUB_OUTPUT
|
|
echo "errors_fixed=$errors_fixed" >> $GITHUB_OUTPUT
|
|
echo "status=success" >> $GITHUB_OUTPUT
|
|
|
|
echo "✅ ESLint fix completed. Files changed: $files_changed, Errors fixed: $errors_fixed"
|
|
|
|
- name: Push Fixes
|
|
if: always()
|
|
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0
|
|
with:
|
|
commit_message: 'style: autofix ESLint violations'
|
|
add_options: '-u'
|