diff --git a/.github/workflows/gofmt.yml b/.github/workflows/gofmt.yml index 5ceaec66..2c940c22 100644 --- a/.github/workflows/gofmt.yml +++ b/.github/workflows/gofmt.yml @@ -2,10 +2,7 @@ name: Go Fmt on: pull_request: - types: [labeled] - push: - branches: - - main + types: [opened, reopened, synchronize, labeled, unlabeled] permissions: contents: write @@ -13,11 +10,7 @@ permissions: jobs: gofmt: - if: > - github.event_name == 'push' || - (github.event_name == 'pull_request' && - github.event.action == 'labeled' && - github.event.label.name == 'style') + if: "!contains(github.event.pull_request.labels.*.name, 'no-fmt')" runs-on: ubuntu-latest strategy: matrix: @@ -39,16 +32,8 @@ jobs: - name: Run Formatter run: git ls-files '*.go' | xargs gofmt -w -s - - name: Check for formatting changes (dry run) - run: | - git diff --exit-code || echo "::warning::Formatting changes would be applied in normal mode" - continue-on-error: true - - - name: Commit Changes - if: > - github.event.pull_request.draft && - github.event.pull_request.head.repo.full_name == github.repository && - contains(github.event.pull_request.labels.*.name, 'style') + - name: Commit Formatting Changes + if: github.event.pull_request.head.repo.full_name == github.repository uses: stefanzweifel/git-auto-commit-action@v6.0.1 with: commit_message: apply coding style fixes @@ -59,34 +44,3 @@ jobs: commit_user_email: ${{ secrets.GUS_GH_EMAIL }} commit_author: gocanto branch: ${{ github.event.pull_request.head.ref }} - - - name: Create branch for formatting changes - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - run: | - if ! git diff --quiet; then - BRANCH_NAME="gofmt-fixes-$(date +%Y%m%d-%H%M%S)" - git checkout -b $BRANCH_NAME - git config user.name "GitHub Actions" - git config user.email "${{ secrets.GUS_GH_EMAIL }}" - git add . - git commit -m "Apply Go formatting fixes" - git push origin $BRANCH_NAME - echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - echo "HAS_CHANGES=true" >> $GITHUB_ENV - else - echo "No formatting changes needed" - echo "HAS_CHANGES=false" >> $GITHUB_ENV - fi - - - name: Create Pull Request - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && env.HAS_CHANGES == 'true' }} - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Apply Go formatting fixes - title: "Auto: Apply Go formatting fixes" - body: | - This PR was automatically created by the Go Fmt GitHub Action. - It applies Go formatting standards to the codebase. - branch: ${{ env.BRANCH_NAME }} - base: main diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5d9807ae..181b1a0a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: pull_request: types: [opened, reopened, ready_for_review, synchronize, labeled] push: - branches: [main, master] + branches: [main] jobs: test: