-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
118 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
name: format | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- master | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- labeled | ||
|
||
env: | ||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | ||
DOTNET_NOLOGO: true | ||
DOTNET_CLI_TELEMETRY_OPTOUT: true | ||
|
||
jobs: | ||
verify: | ||
# Don't run both jobs for the same event | ||
if: ${{ github.event_name != 'pull_request' || github.event.action != 'labeled' || !contains(github.event.label.name, 'format') }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Install .NET | ||
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0 | ||
with: | ||
dotnet-version: 9.0.x | ||
|
||
- name: Verify formatting | ||
run: > | ||
dotnet build | ||
-t:CSharpierFormat | ||
--configuration Release | ||
fix: | ||
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'format') }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Switch to PR branch | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: > | ||
gh pr checkout ${{ github.event.pull_request.number }} | ||
--repo ${{ github.event.repository.full_name }} | ||
- name: Install .NET | ||
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0 | ||
with: | ||
dotnet-version: 9.0.x | ||
|
||
- name: Fix formatting | ||
run: > | ||
dotnet build | ||
-t:CSharpierFormat | ||
--configuration Debug | ||
- name: Check for changes | ||
id: check-for-changes | ||
run: | | ||
git diff --exit-code | ||
if [ $? -eq 0 ]; then | ||
echo "any=false" >> $GITHUB_OUTPUT | ||
else | ||
echo "any=true" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Commit changes | ||
if: ${{ fromJson(steps.check-for-changes.outputs.any) }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub Actions" | ||
git add . | ||
git commit -m "Fix formatting" | ||
git push | ||
- name: Leave comment | ||
if: ${{ fromJson(steps.check-for-changes.outputs.any) }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: > | ||
gh pr comment ${{ github.event.pull_request.number }} | ||
--repo ${{ github.event.repository.full_name }} | ||
--body "Formatting has been verified and fixed. Please pull the latest changes to avoid conflicts." | ||
- name: Remove label | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: > | ||
gh pr edit ${{ github.event.pull_request.number }} | ||
--repo ${{ github.event.repository.full_name }} | ||
--remove-label format |
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