Skip to content

Commit

Permalink
Add auto-formatting workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Feb 3, 2025
1 parent 437bd6a commit e4e5359
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 25 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/format.yml
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
27 changes: 2 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
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
test:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -133,7 +111,6 @@ jobs:
if: ${{ github.ref_type == 'tag' }}

needs:
- format
- test
- pack

Expand All @@ -156,7 +133,7 @@ jobs:
deploy:
needs: release

strategy:
matrix:
rid:
Expand Down Expand Up @@ -187,7 +164,7 @@ jobs:
# Change into the artifacts directory to avoid including the directory itself in the zip archive
working-directory: LightBulb/
run: zip -r ../LightBulb.${{ matrix.rid }}.zip .

- name: Create package (installer)
run: mv LightBulb-Installer.exe LightBulb-Installer.${{ matrix.rid }}.exe

Expand Down

0 comments on commit e4e5359

Please sign in to comment.