Skip to content

feat: modernize cross-env with TypeScript, Vitest, and ESM-only build #16

feat: modernize cross-env with TypeScript, Vitest, and ESM-only build

feat: modernize cross-env with TypeScript, Vitest, and ESM-only build #16

Workflow file for this run

name: Auto Format
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
format:
name: πŸ”§ Auto Format
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref || github.ref_name }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
cache: 'npm'
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Check current formatting
id: format-check
run: |
if npm run format:check; then
echo "format_needed=false" >> $GITHUB_OUTPUT
echo "βœ… Code is already properly formatted"
else
echo "format_needed=true" >> $GITHUB_OUTPUT
echo "⚠️ Code formatting issues found"
fi
- name: Format code
if: steps.format-check.outputs.format_needed == 'true'
run: npm run format
- name: Check for changes
id: changes
if: steps.format-check.outputs.format_needed == 'true'
run: |
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "ℹ️ No formatting changes to commit"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "πŸ“ Formatting changes detected"
fi
# CI cannot commit to workflow files, so we need to check for non-workflow changes
- name: Check for non-workflow changes
id: non-workflow-changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git add -A
git reset .github/workflows/
if git diff --cached --quiet; then
echo "has_non_workflow_changes=false" >> $GITHUB_OUTPUT
echo "ℹ️ Only workflow files have formatting changes - skipping commit"
else
echo "has_non_workflow_changes=true" >> $GITHUB_OUTPUT
echo "πŸ“ Non-workflow formatting changes detected"
fi
- name: Configure Git
if:
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Commit and push changes
if:
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'true'
run: |
git commit -m "chore: πŸ”§ Auto-format code with Prettier [skip ci]
This commit was automatically generated by the auto-format workflow.
Changes include:
- Code formatting fixes
- Consistent indentation
- Proper line endings"
git push origin HEAD:${{ github.head_ref || github.ref_name }}
- name: Comment on PR
if:
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'true'
&& github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'πŸ”§ **Auto-formatting applied!**\n\nI\'ve automatically formatted the code using Prettier and pushed the changes. The formatting is now consistent with the project standards.'
})
- name: Success message
if:
steps.changes.outputs.has_changes == 'false' ||
steps.format-check.outputs.format_needed == 'false' ||
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'false'
run: |
if [ "${{ steps.changes.outputs.has_changes }}" == "true" ] && [ "${{ steps.non-workflow-changes.outputs.has_non_workflow_changes }}" == "false" ]; then
echo "βœ… Only workflow files had formatting changes - no commit needed!"
else
echo "βœ… No formatting changes needed - code is already properly formatted!"
fi