Automatic JSON Formatting Workflow

This change alters the existing format workflow to include another job that handles formatting JSON files. The JSON files are formatted using BiomeJS. The BiomeJS config file is dynamically created before Biome runs and removed after. This uses the existing `.editorconfig` settings as defaults, allowing overwrites and additional Biome configurations within the workflow file.

Current JSON formatting rules:
- end_of_line = lf
- insert_final_newline = true
- indent_style = space
- trim_trailing_whitespace = true
- charset = utf-8
- indent_size = 2
- trailingCommas = none
- bracketSpacing = true
- expand = always

The existing Csharpier job runs at the same time as the new Biome job. The results (changes made) in each job are compressed into an artifact and downloaded into a final job that combines them and commits them back into the project (if there are changes, and if the workflow is not triggered within a PR).
This commit is contained in:
Refringe
2025-07-26 19:20:46 -04:00
parent b74adca201
commit c5198ccd22
3 changed files with 196 additions and 58 deletions
+4 -7
View File
@@ -1,23 +1,20 @@
# editorconfig.org
# top-most EditorConfig file
root = true root = true
# Default settings:
# A newline ending every file
# Use 4 spaces as indentation
[*] [*]
end_of_line = lf
insert_final_newline = true insert_final_newline = true
indent_style = space indent_style = space
indent_size = 4 indent_size = 4
trim_trailing_whitespace = true trim_trailing_whitespace = true
[{*.yaml,*.yml}] [{*.yaml,*.yml}]
charset = utf-8
indent_size = 2 indent_size = 2
[*.json] [*.json]
ij_formatter_enabled = true charset = utf-8
indent_size = 2 indent_size = 2
ij_formatter_enabled = true
# C# files # C# files
[*.cs] [*.cs]
-50
View File
@@ -1,50 +0,0 @@
name: .NET Format
on:
push:
branches:
- develop
pull_request:
branches-ignore:
- main
jobs:
dotnet-format:
if: "!contains(github.event.head_commit.message, '.NET Format Style Fixes')"
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.BYPASS_WORKFLOW_PAT || github.token }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0
- name: Restore Tool Dependencies
run: dotnet tool install -g csharpier
- name: CSharpier Format
run: csharpier format .
- name: Check PR Formatting
if: github.event_name == 'pull_request'
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "::error::Code formatting issues found. Please run 'csharpier format .' locally and push the changes to your PR branch. Read the 'README.md' file for more information."
git status --porcelain
exit 1
fi
- name: Auto Commit Changes (Push)
if: github.event_name != 'pull_request'
uses: stefanzweifel/git-auto-commit-action@v6
with:
commit_message: .NET Format Style Fixes
commit_user_name: sp-tarkov-bot
commit_user_email: singleplayertarkov@gmail.com
commit_author: sp-tarkov-bot <singleplayertarkov@gmail.com>
+191
View File
@@ -0,0 +1,191 @@
name: Format
on:
push:
branches:
- develop
pull_request:
branches-ignore:
- main
jobs:
dotnet-format:
if: "!contains(github.event.head_commit.message, 'Format Style Fixes')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.BYPASS_WORKFLOW_PAT || github.token }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0
- name: Restore Tool Dependencies
run: dotnet tool install -g csharpier
- name: CSharpier Format
run: csharpier format .
- name: Check for Changes
id: check-changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Upload Changes as Artifact
if: steps.check-changes.outputs.changes == 'true' && github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: dotnet-changes
path: |
**/*.cs
**/*.csproj
retention-days: 1
compression-level: 1
- name: Fail PR if Changes Detected
if: steps.check-changes.outputs.changes == 'true' && github.event_name == 'pull_request'
run: |
echo "::error::Code formatting issues found. Please run 'csharpier format .' locally and push the changes to your PR branch. Read the 'README.md' file for more information."
git status --porcelain
exit 1
biome-format:
if: "!contains(github.event.head_commit.message, 'Format Style Fixes')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.BYPASS_WORKFLOW_PAT || github.token }}
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- name: Create Biome Config
run: |
cat > biome.json << 'EOF'
{
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"maxSize": 20971520,
"includes": [
"**/*.json",
"!**/looseLoot.json",
"!**/items.json"
]
},
"formatter": {
"useEditorconfig": true
},
"javascript": {
"formatter": {
"enabled": false
}
},
"json": {
"formatter": {
"enabled": true,
"lineWidth": 120,
"trailingCommas": "none",
"bracketSpacing": true,
"expand": "always"
},
"parser": {
"allowComments": true,
"allowTrailingCommas": true
},
"linter": {
"enabled": false
}
}
}
EOF
- name: Format JSON Files
run: |
biome format --write . || true
- name: Remove Biome Config
if: always()
run: rm -f biome.json
- name: Check for Changes
id: check-changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Upload Changes as Artifact
if: steps.check-changes.outputs.changes == 'true' && github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: biome-changes
path: |
**/*.json
retention-days: 1
compression-level: 1
- name: Fail PR if Changes Detected
if: steps.check-changes.outputs.changes == 'true' && github.event_name == 'pull_request'
run: |
echo "::error::JSON formatting issues found. Please run BiomeJS locally to format your JSON files and push the changes to your PR branch."
git status --porcelain
exit 1
commit-changes:
if: github.event_name != 'pull_request' && !contains(github.event.head_commit.message, 'Format Style Fixes')
needs: [dotnet-format, biome-format]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.BYPASS_WORKFLOW_PAT || github.token }}
- name: Download Dotnet Changes
uses: actions/download-artifact@v4
with:
name: dotnet-changes
continue-on-error: true
- name: Download Biome Changes
uses: actions/download-artifact@v4
with:
name: biome-changes
continue-on-error: true
- name: Check for Any Changes
id: check-changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Auto Commit Changes
if: steps.check-changes.outputs.changes == 'true'
uses: stefanzweifel/git-auto-commit-action@v6
with:
commit_message: Format Style Fixes
commit_user_name: sp-tarkov-bot
commit_user_email: singleplayertarkov@gmail.com
commit_author: sp-tarkov-bot <singleplayertarkov@gmail.com>