From 823936c8f6a437d065f8a1119c1ebf943e89c140 Mon Sep 17 00:00:00 2001 From: Abhijeet Date: Fri, 16 May 2025 15:34:04 +0530 Subject: [PATCH] refactor: replace binary validation tools with Maven-based checkstyle workflow --- .github/workflows/checkstyle.yml | 68 +++++++++++++++++++++++++++---- .github/workflows/commit-lint.yml | 8 +++- package.json | 4 +- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index bcae2b38..2e548f57 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -1,13 +1,63 @@ -name: Call Checkstyle +name: Checkstyle on: pull_request: - branches: ["master", "develop"] - paths: - - '**/*.java' - + types: [opened, synchronize, reopened] + workflow_call: + inputs: + java-version: + required: false + type: string + default: '17' + jobs: - style-check: - uses: PSMRI/.github/.github/workflows/checkstyle.yml@main - with: - java-version: '17' \ No newline at end of file + checkstyle: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'adopt' + + - name: Get Changed Files + id: changed-files + uses: tj-actions/changed-files@v39 + with: + files: '**/*.java,**/*.xml' + + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-maven + + - name: Install Dependencies + run: mvn install -DskipTests + + - name: Run Checkstyle on Changed Files + if: steps.changed-files.outputs.any_changed == 'true' + run: | + echo "${{ steps.changed-files.outputs.all_changed_files }}" > changed_files.txt + mvn checkstyle:check \ + -Dcheckstyle.config.location=checkstyle.xml \ + -Dcheckstyle.includeResources=false \ + -Dcheckstyle.includeTestResources=false \ + -Dcheckstyle.includes=@changed_files.txt + + - name: Block PR on Checkstyle Failure + if: failure() + uses: actions/github-script@v7 + with: + script: | + core.setFailed('Checkstyle checks failed. Please fix the code formatting issues.') \ No newline at end of file diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml index 856fcc2f..ee615347 100644 --- a/.github/workflows/commit-lint.yml +++ b/.github/workflows/commit-lint.yml @@ -23,8 +23,12 @@ jobs: node-version: 18 - name: Install dependencies - run: npm ci --legacy-peer-deps + run: | + npm ci --legacy-peer-deps + npm i --legacy-peer-deps - name: Run commitlint on PR run: | - npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose \ No newline at end of file + npx commitlint --from ${{ github.event.pull_request.base.sha }} \ + --to ${{ github.event.pull_request.head.sha }} \ + --verbose \ No newline at end of file diff --git a/package.json b/package.json index 78f95d7d..d50e2824 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ } }, "lint-staged": { - "src/**/*.{ts,css,html}": [ + "src/**/*.{ts,js}": [ "eslint --fix" ] }, @@ -24,4 +24,4 @@ "husky": "^9.1.7", "lint-staged": "^15.5.1" } -} +} \ No newline at end of file