|
| 1 | +name: Code Formatter |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + format: |
| 8 | + name: Format Kotlin Code with ktfmt |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up JDK 22 |
| 16 | + uses: actions/setup-java@v4 |
| 17 | + with: |
| 18 | + distribution: 'oracle' |
| 19 | + java-version: '22' |
| 20 | + |
| 21 | + - name: Download ktfmt |
| 22 | + run: | |
| 23 | + wget https://github.com/facebook/ktfmt/releases/download/v0.53/ktfmt-0.53-jar-with-dependencies.jar -O ktfmt.jar |
| 24 | +
|
| 25 | + - name: Run ktfmt on Kotlin files |
| 26 | + run: | |
| 27 | + find . -name "*.kt" -exec java -jar ktfmt.jar --google-style {} + |
| 28 | +
|
| 29 | + - name: Commit and Push changes |
| 30 | + run: | |
| 31 | + rm ktfmt.jar |
| 32 | + git config --global user.name "trindadedev13" |
| 33 | + git config --global user.email "trindadedev13@gmail.com" |
| 34 | + git fetch origin ${GITHUB_REF_NAME}:temp |
| 35 | + git add . |
| 36 | + git commit -m "chore: Format Kotlin Code" -m "format code with ktfmt in github actions" |
| 37 | + git rebase temp |
| 38 | + git push origin HEAD:${GITHUB_REF_NAME} |
| 39 | + env: |
| 40 | + TOKEN: ${{ secrets.SUPER_TOKEN }} |
| 41 | + continue-on-error: true |
| 42 | + |
| 43 | + format-java: |
| 44 | + name: Format Java Code with Google Java Format |
| 45 | + runs-on: ubuntu-latest |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout repository |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Set up JDK 22 |
| 52 | + uses: actions/setup-java@v4 |
| 53 | + with: |
| 54 | + distribution: 'oracle' |
| 55 | + java-version: '22' |
| 56 | + |
| 57 | + - name: Download Google Java Format |
| 58 | + run: | |
| 59 | + wget https://github.com/google/google-java-format/releases/download/v1.24.0/google-java-format-1.24.0-all-deps.jar -O google-java-format.jar |
| 60 | +
|
| 61 | + - name: Run Google Java Format in Java files |
| 62 | + run: | |
| 63 | + find . -name "*.java" -exec java -jar google-java-format.jar --replace {} + |
| 64 | +
|
| 65 | + - name: Commit and Push changes |
| 66 | + run: | |
| 67 | + rm google-java-format.jar |
| 68 | + git config --global user.name "trindadedev13" |
| 69 | + git config --global user.email "trindadedev13@gmail.com" |
| 70 | + git fetch origin ${GITHUB_REF_NAME}:temp |
| 71 | + git add . |
| 72 | + git commit -m "chore: Format Java Code" -m "format code with google java format in github actions" |
| 73 | + git rebase temp |
| 74 | + git push origin HEAD:${GITHUB_REF_NAME} |
| 75 | + env: |
| 76 | + TOKEN: ${{ secrets.SUPER_TOKEN }} |
| 77 | + continue-on-error: true |
0 commit comments