Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 4 additions & 50 deletions .github/workflows/gofmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ name: Go Fmt

on:
pull_request:
types: [labeled]
push:
branches:
- main
types: [opened, reopened, synchronize, labeled, unlabeled]

permissions:
contents: write
pull-requests: write

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:
Expand All @@ -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
Expand All @@ -59,34 +44,3 @@ jobs:
commit_user_email: ${{ secrets.GUS_GH_EMAIL }}
commit_author: gocanto <gocanto@users.noreply.github.com>
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize, labeled]
push:
branches: [main, master]
branches: [main]

jobs:
test:
Expand Down
Loading