Skip to content

Commit 6e23981

Browse files
ci: Format code Workflow (MAPCO-6656) (#9)
* Formate code on save * Add format ci job * rename file path * Add formate test script * Fail process if format check fails * Fix format job * Fix indentation issue * Print fail reason * print files * Print files to console * Fix manully * Change to format only * Only format * Fix action name * Exclude idea files * Remove sln and cproj * Remove test script * Remove needs * Add Code styles
1 parent 4696226 commit 6e23981

File tree

5 files changed

+258
-2
lines changed

5 files changed

+258
-2
lines changed

.github/workflows/format.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Format
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
format_check:
8+
name: Verify Rider formatting
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup .NET
15+
uses: actions/setup-dotnet@v4
16+
with:
17+
dotnet-version: '8.0.x'
18+
19+
- name: Install JetBrains ReSharper Global Tools (jb)
20+
run: |
21+
dotnet tool install --global JetBrains.ReSharper.GlobalTools
22+
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
23+
24+
- name: Run Rider cleanup (dry-check via diff)
25+
run: |
26+
jb cleanupcode \
27+
--profile="Built-in: Reformat Code" \
28+
--no-build \
29+
--verbosity=WARN \
30+
--include="**/*.cs" \
31+
--exclude="**/bin/**" \
32+
--exclude="**/obj/**" \
33+
--exclude="**/.idea/**" \
34+
.
35+
36+
- name: Detect formatting changes (code files only)
37+
id: diff
38+
run: |
39+
LIST_FILE="$RUNNER_TEMP/files_needing_format.txt"
40+
CHANGED="$(git status --porcelain --untracked-files=no -- '*.cs' '*.csproj' '*.sln' | awk '{print $2}' | sort -u)"
41+
if [[ -n "$CHANGED" ]]; then
42+
echo "changed=true" >> "$GITHUB_OUTPUT"
43+
echo "$CHANGED" | tee "$LIST_FILE"
44+
echo "list_file=$LIST_FILE" >> "$GITHUB_OUTPUT"
45+
else
46+
echo "changed=false" >> "$GITHUB_OUTPUT"
47+
echo "list_file=" >> "$GITHUB_OUTPUT"
48+
fi
49+
50+
- name: Summarize unformatted files
51+
if: steps.diff.outputs.changed == 'true'
52+
run: |
53+
{
54+
echo "### ❌ Formatting check failed"
55+
echo
56+
echo "The following code files are not formatted properly:"
57+
echo
58+
echo '```'
59+
cat "${{ steps.diff.outputs.list_file }}"
60+
echo '```'
61+
echo
62+
echo "➡️ Run Rider **Code Cleanup** (Built-in: *Reformat Code*) locally and commit."
63+
} >> "$GITHUB_STEP_SUMMARY"
64+
65+
- name: Annotate files in Checks UI
66+
if: steps.diff.outputs.changed == 'true'
67+
run: |
68+
while IFS= read -r f; do
69+
echo "::error file=$f,title=Not formatted::Run Rider Code Cleanup (Built-in: Reformat Code) and commit."
70+
done < "${{ steps.diff.outputs.list_file }}"
71+
72+
- name: Revert any changes (always clean workspace)
73+
if: always()
74+
run: |
75+
git restore --staged .
76+
git checkout -- .
77+
git clean -fd
78+
79+
- name: Fail job if formatting needed
80+
if: steps.diff.outputs.changed == 'true'
81+
run: exit 1

.github/workflows/test-and-build.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ jobs:
2525
echo "is_unity_license_set=false" >> $GITHUB_OUTPUT
2626
fi
2727
28+
format_check:
29+
uses: ./.github/workflows/format.yaml
30+
2831
test:
2932
name: Run Unity Tests
30-
needs: checklicense
33+
needs: [checklicense, format_check]
3134
if: needs.checklicense.outputs.is_unity_license_set == 'true'
3235
runs-on: windows-latest
3336
steps:
@@ -49,7 +52,7 @@ jobs:
4952

5053
buildForAllSupportedPlatforms:
5154
name: Build for ${{ matrix.targetPlatform }}
52-
needs: [checklicense, test]
55+
needs: [test]
5356
if: needs.checklicense.outputs.is_unity_license_set == 'true'
5457
runs-on: windows-latest
5558
strategy:

.idea/.idea.yahalom/.idea/codeStyles/Project.xml

Lines changed: 141 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.yahalom/.idea/codeStyles/codeStyleConfig.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.yahalom/.idea/workspace.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)