diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..55fd9ec --- /dev/null +++ b/.github/workflows/format.yml @@ -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 "actions@github.com" + 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 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e597340..466958c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -133,7 +111,6 @@ jobs: if: ${{ github.ref_type == 'tag' }} needs: - - format - test - pack @@ -156,7 +133,7 @@ jobs: deploy: needs: release - + strategy: matrix: rid: @@ -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