diff --git a/.editorconfig b/.editorconfig index 6696ba18..0a4031d4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,23 +1,20 @@ -# editorconfig.org - -# top-most EditorConfig file root = true -# Default settings: -# A newline ending every file -# Use 4 spaces as indentation [*] +end_of_line = lf insert_final_newline = true indent_style = space indent_size = 4 trim_trailing_whitespace = true [{*.yaml,*.yml}] +charset = utf-8 indent_size = 2 [*.json] -ij_formatter_enabled = true +charset = utf-8 indent_size = 2 +ij_formatter_enabled = true # C# files [*.cs] @@ -152,4 +149,4 @@ resharper_merge_into_pattern_highlighting = none indent_size = 2 [*.{csproj,vbproj,proj,nativeproj,locproj}] -charset = utf-8 \ No newline at end of file +charset = utf-8 diff --git a/.github/workflows/dotnet-format.yml b/.github/workflows/dotnet-format.yml deleted file mode 100644 index e9c9d8e4..00000000 --- a/.github/workflows/dotnet-format.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..78eb2639 --- /dev/null +++ b/.github/workflows/format.yml @@ -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