-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (190 loc) · 7.81 KB
/
Copy pathcode-style.yml
File metadata and controls
228 lines (190 loc) · 7.81 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
on:
workflow_call:
inputs:
php:
description: 'Enable PHP code style checks'
required: false
type: boolean
default: true
node:
description: 'Enable Node.js code style checks'
required: false
type: boolean
default: true
permissions:
contents: write
pull-requests: write
artifact-metadata: write
jobs:
php:
if: ${{ inputs.php }}
name: PHP
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
- name: Detecting to make changes
id: can_fix
shell: bash
run: |
CAN_FIX=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
echo "CAN_FIX=${CAN_FIX}" >> "$GITHUB_ENV"
- name: Setup Composer
run: |
composer global config --no-plugins allow-plugins.laravel/pint true
composer global config --no-plugins allow-plugins.ergebnis/composer-normalize true
composer config --no-plugins allow-plugins.laravel/pint true
composer config --no-plugins allow-plugins.ergebnis/composer-normalize true
- name: Install Composer dependencies
run: composer global require dragon-code/codestyler
- name: Publish config files
run: codestyle pint 8.2
- name: Normalize composer.json
if: env.CAN_FIX == 'true'
run: composer normalize
- name: Code-style
run: |
if [ $CAN_FIX == true ]; then
pint --parallel
else
pint --parallel --test
fi
- name: Collect changed files
if: env.CAN_FIX == 'true'
id: changed_php
shell: bash
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git ls-files -m > changed.txt || true
if [ -s changed.txt ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Stage changed files preserving paths
if: env.CAN_FIX == 'true' && steps.changed_php.outputs.has_changes == 'true'
shell: bash
run: |
mkdir -p .artifacts/php
while IFS= read -r f; do
[ -f "$f" ] || continue
mkdir -p ".artifacts/php/$(dirname "$f")"
cp "$f" ".artifacts/php/$f"
done < changed.txt
- name: Upload changed files
if: env.CAN_FIX == 'true' && steps.changed_php.outputs.has_changes == 'true'
uses: actions/upload-artifact@v7
with:
name: fixes-php
path: .artifacts/php
node:
if: ${{ inputs.node }}
name: Node
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
- uses: actions/setup-node@v7
with:
node-version: 'latest'
- name: Detecting to make changes
id: can_fix
shell: bash
run: |
CAN_FIX=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
echo "CAN_FIX=${CAN_FIX}" >> "$GITHUB_ENV"
- name: Detect package.json
id: has_pkg
shell: bash
run: |
if [ -f package.json ]; then
echo "HAS_PACKAGE_JSON=1" >> "$GITHUB_ENV"
else
echo "HAS_PACKAGE_JSON=0" >> "$GITHUB_ENV"
fi
- name: Install Composer dependencies
run: composer global require dragon-code/codestyler
- name: Install Node dependencies
run: npm i -D @biomejs/biome
- name: Publish config files
run: codestyle npm
- name: Code-style
run: |
if [ $CAN_FIX == true ]; then
npx @biomejs/biome lint --write
npx @biomejs/biome format --write
else
npx @biomejs/biome lint
npx @biomejs/biome format
fi
- name: Remove node_modules
if: env.CAN_FIX == 'true'
run: rm -rf node_modules
- name: Remove package.json
if: env.HAS_PACKAGE_JSON == '0'
run: |
rm package.json
rm package-lock.json
- name: Collect changed files
if: env.CAN_FIX == 'true'
id: changed_node
shell: bash
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git ls-files -m > changed.txt || true
if [ -s changed.txt ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Stage changed files preserving paths
if: env.CAN_FIX == 'true' && steps.changed_node.outputs.has_changes == 'true'
shell: bash
run: |
mkdir -p .artifacts/node
while IFS= read -r f; do
[ -f "$f" ] || continue
mkdir -p ".artifacts/node/$(dirname "$f")"
cp "$f" ".artifacts/node/$f"
done < changed.txt
- name: Upload changed files
if: env.CAN_FIX == 'true' && steps.changed_node.outputs.has_changes == 'true'
uses: actions/upload-artifact@v7
with:
name: fixes-node
path: .artifacts/node
pr:
needs:
- php
- node
name: PR
runs-on: ubuntu-latest
if: |
always() &&
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
(needs.php.result == 'success' || needs.node.result == 'success')
steps:
- uses: actions/checkout@v7
- name: Download all artifacts and merge
uses: actions/download-artifact@v8
with:
merge-multiple: true
path: .
- name: Create a Pull Request
uses: peter-evans/create-pull-request@v8
id: pullRequest
if: ${{ !cancelled() }}
with:
branch: code-style
branch-suffix: random
delete-branch: true
title: "🦋 The code style has been fixed"
commit-message: 🦋 The code style has been fixed
body: The code style has been fixed
labels: code-style
- name: Merge PR
if: steps.pullRequest.outputs.pull-request-number != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --merge --delete-branch ${{ steps.pullRequest.outputs.pull-request-number }} --admin