feat:Format the code style automatically for PR #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check code style | |
on: | |
push: | |
branches: | |
- main | |
- feature/ci_setup | |
pull_request: | |
paths: | |
- '.github/workflows/code_style.yml' | |
- '**/*.kt' | |
- '**/*.kts' | |
jobs: | |
check-code-style: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-java@v3 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: Format code style | |
run: | | |
./gradlew ktlintFormat | |
- name: Commit files changed by ktlintFormat | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git add . | |
git diff --quiet && git diff --staged --quiet || git commit -m "Apply ktlint formatting" | |
- name: Check code style | |
shell: bash | |
run: ./gradlew ktlintCheck | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.event_name == 'push' && github.ref || github.event.pull_request.head.ref }} |