-
Notifications
You must be signed in to change notification settings - Fork 2.8k
89 lines (74 loc) · 2.72 KB
/
format.yml
File metadata and controls
89 lines (74 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Format
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
format:
if: "${{ github.repository == 'remix-run/remix' && !startsWith(github.event.head_commit.message, 'chore: format') }}"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.FORMAT_PAT }}
fetch-depth: 0
- name: Detect formatting-relevant changes
id: changes
run: |
base="${{ github.event.before }}"
if [ "$base" = "0000000000000000000000000000000000000000" ]; then
files="$(git ls-files)"
else
files="$(git diff --name-only "$base" "$GITHUB_SHA")"
fi
if [ -z "$files" ]; then
echo "No changed files detected"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi
while IFS= read -r file; do
case "$file" in
.prettierignore|.prettierrc|.prettierrc.json|.prettierrc.yml|.prettierrc.yaml|.prettierrc.js|.prettierrc.cjs|.prettierrc.mjs|*.js|*.jsx|*.cjs|*.mjs|*.ts|*.tsx|*.cts|*.mts|*.json|*.jsonc|*.md|*.mdx|*.yaml|*.yml|*.css|*.scss|*.html)
echo "Formatting-relevant change: $file"
echo "should_run=true" >> "$GITHUB_OUTPUT"
exit 0
;;
esac
done <<EOF
$files
EOF
echo "No formatting-relevant files changed"
echo "should_run=false" >> "$GITHUB_OUTPUT"
- name: Install pnpm
if: steps.changes.outputs.should_run == 'true'
uses: pnpm/action-setup@v4
- name: Install Node.js
if: steps.changes.outputs.should_run == 'true'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: pnpm
- name: Install dependencies
if: steps.changes.outputs.should_run == 'true'
run: pnpm install --frozen-lockfile
- name: Format
if: steps.changes.outputs.should_run == 'true'
run: pnpm format
- name: Commit
if: steps.changes.outputs.should_run == 'true'
run: |
git config --local user.email "hello@remix.run"
git config --local user.name "Remix Run Bot"
git add .
git restore .github/workflows # PAT doesn't have permission to push workflow changes
if [ -z "$(git status --porcelain)" ]; then
echo "No formatting changes"
exit 0
fi
git commit -m "chore: format"
git push
echo "Pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)"