Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WX-1395] Scala formatter Github Action #7341

Merged
merged 17 commits into from
Dec 19, 2023
2 changes: 1 addition & 1 deletion .github/workflows/scalafmt-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Scalafmt'
name: 'ScalaFmt Check'

# This GitHub Action runs the ScalaFmt linting tool on the entire codebase.
# It fails if any files are not formatted properly.
Expand Down
58 changes: 37 additions & 21 deletions .github/workflows/scalafmt-fix.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
name: 'Scalafmt'
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: ${{ format('ScalaFmt Fix on {0}', github.ref_name) }}
run-name: ScalaFmt Fix

on:
workflow_dispatch:
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:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.target-branch }}
- uses: ./.github/set_up_cromwell_action
with:
cromwell_repo_token: ${{ secrets.BROADBOT_GITHUB_TOKEN }}
- name: Determine 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
- name: Run ScalaFmt
- uses: actions/checkout@v3 # checkout the cromwell repo
with:
ref: ${{ inputs.target-branch }}
- uses: ./.github/set_up_cromwell_action
with:
cromwell_repo_token: ${{ secrets.BROADBOT_GITHUB_TOKEN }}
- name: Run ScalaFmt Fixup
if: steps.check-comment.outputs.comment-triggered == 'true' || github.event_name == 'workflow_dispatch'
env:
BROADBOT_GITHUB_TOKEN: ${{ secrets.BROADBOT_GITHUB_TOKEN }}
run: |
if [[ ${{ steps.check-comment.outputs.comment-triggered }} == true ]]; then
echo "PR Comment Detected. Formatting, committing, and pushing formatted scala code."
sbt scalaFmtAll
git config --global user.email "${{ steps.check-comment.outputs.comment-author-email }}"
git config --global user.name "${{ steps.check-comment.outputs.comment-author-name }}"
git add .
git commit -m "Auto-format code with ScalaFmt"
git push origin ${{ github.ref }}
fi
sbt scalafmtAll
git config --global user.email "broadbot@broadinstitute.org"
git config --global user.name "Broad Bot"
git add .
git commit -m "ScalaFmt fixup via Broad Bot"
git push origin ${{ steps.determine-branch.outputs.target_branch }}
working-directory: ${{ github.workspace }}
Loading