ScalaFmt Fix #12
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: 'ScalaFmt Fix' | |
# This GitHub Action runs the ScalaFmt linting tool on the entire codebase. | |
# It will fix, commit, and push linted code. | |
# It will only run when someone comments "scalafmt" on a PR. | |
run-name: ScalaFmt Fix | |
on: | |
issue_comment: | |
types: | |
- created | |
workflow_dispatch: | |
branch_name: | |
description: 'Branch to run ScalaFmt against' | |
required: true | |
pull_request_target: | |
types: | |
- opened | |
- synchronize | |
jobs: | |
run-scalafmt-fix: | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
steps: | |
- name: Determine the target branch | |
id: determine-branch | |
run: | | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
echo "::set-output name=target_branch::${{ inputs.branch_name }}" | |
else | |
echo "::set-output name=target_branch::${{ github.event.pull_request.head.ref }}" | |
fi | |
shell: bash | |
env: | |
inputs.branch_name: ${{ inputs.branch_name }} | |
- name: Check for ScalaFmt Comment | |
id: check-comment | |
run: | | |
if [[ "${{ github.event_name }}" == "issue_comment" && "${{ github.event.comment.body }}" == *"scalafmt"* ]]; then | |
echo "::set-output name=comment-triggered::true" | |
echo "::set-output name=comment-author-email::${{ github.event.comment.user.login }}@users.noreply.github.com" | |
echo "::set-output name=comment-author-name::${{ github.event.comment.user.login }}" | |
else | |
echo "::set-output name=comment-triggered::false" | |
fi | |
shell: bash | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ steps.determine-branch.outputs.target_branch }} | |
token: ${{ secrets.BROADBOT_GITHUB_TOKEN }} | |
- uses: ./.github/set_up_cromwell_action | |
with: | |
cromwell_repo_token: ${{ secrets.BROADBOT_GITHUB_TOKEN }} | |
- name: Run ScalaFmt Fix | |
if: steps.check-comment.outputs.comment-triggered == 'true' || github.event_name == 'workflow_dispatch' | |
env: | |
BROADBOT_GITHUB_TOKEN: ${{ secrets.BROADBOT_GITHUB_TOKEN }} | |
run: | | |
sbt scalafmtAll | |
git config --global user.email "[email protected]" | |
git config --global user.name "ScalaFmt Fixer" | |
git add . | |
git commit -m "Auto-format code with ScalaFmt" | |
git push origin ${{ steps.determine-branch.outputs.target_branch }} | |
working-directory: ${{ github.workspace }} |