From f79ed44fbc2109c1c6eea9d1fa99b574b194ffeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20B=C4=85k?= Date: Sat, 29 Jun 2024 16:33:49 +0200 Subject: [PATCH] Update GitHub Format Action to create a PR with swift-format changes --- .github/workflows/Format.yml | 55 +++++++++++++++++++++++++++--------- Makefile | 8 ------ 2 files changed, 42 insertions(+), 21 deletions(-) delete mode 100644 Makefile diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index b824fe8..50f2089 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -11,19 +11,48 @@ concurrency: jobs: swift_format: - name: swift-format - runs-on: macos-13 + name: Swift Format + runs-on: macos-14 + steps: - - uses: actions/checkout@v3 - - name: Xcode Select - run: sudo xcode-select -s /Applications/Xcode_14.3.1.app - - name: Tap + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Select Xcode + run: sudo xcode-select -s /Applications/Xcode_15.4.app + + - name: Install swift-format run: brew install swift-format - - name: Format - run: make format - - uses: stefanzweifel/git-auto-commit-action@v4 + + - name: Run swift-format + id: swift_format + run: | + swift format \ + --ignore-unparsable-files \ + --in-place \ + --recursive \ + ./Package.swift ./Sources ./Tests ./Examples + + if ! git diff --exit-code; then + echo "Formatting changes detected." + else + echo "No formatting changes detected." + exit 0 + fi + + - name: Commit changes + if: steps.swift_format.outputs.format_changes == 'true' + run: | + git config user.name "Mateusz Bąk" + git config user.email "bakmatthew@icloud.com" + git checkout -b format-changes + git add -A + git commit -m "Apply swift-format changes" +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Pull Request + if: steps.swift_format.outputs.format_changes == 'true' + uses: peter-evans/create-pull-request@v5 with: - commit_message: Run swift-format - branch: 'main' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + title: "Apply swift-format changes" diff --git a/Makefile b/Makefile deleted file mode 100644 index 3a58a9e..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -format: - swift format \ - --ignore-unparsable-files \ - --in-place \ - --recursive \ - ./Package.swift ./Sources ./Tests ./Examples - -.PHONY: format