-
Notifications
You must be signed in to change notification settings - Fork 5
71 lines (70 loc) · 2.53 KB
/
swift-format.yml
File metadata and controls
71 lines (70 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Run swift-format
on:
workflow_dispatch:
push:
branches:
- main
jobs:
swiftformat:
name: "swift-format"
runs-on: ubuntu-latest
container:
image: swift:latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Check out UBKit
run: |
git clone https://github.com/UbiqueInnovation/ubkit-ios __ubkit
mv __ubkit/.swift-format .
- name: Run swift-format
run: swift format --in-place --parallel --recursive .
- name: Delete UBKit
run: |
rm -rf __ubkit
# Keep .swift-format in project
- name: Configure git
run: |
git config --global --add safe.directory "$(pwd)"
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Check for changes
id: check_changes
run: |
if git status --porcelain .swift-format | grep -q .; then
echo "swift_format_changes=true" >> $GITHUB_ENV
else
echo "swift_format_changes=false" >> $GITHUB_ENV
fi
if git status --porcelain '*.swift' | grep -q .; then
echo "swift_files_changes=true" >> $GITHUB_ENV
else
echo "swift_files_changes=false" >> $GITHUB_ENV
fi
- name: Add commit for swift-format file
if: env.swift_format_changes == 'true'
run: |
git add .swift-format
git commit -m "Update .swift-format"
- name: Add commit for swift-format
if: env.swift_files_changes == 'true'
run: |
git add '**/*.swift'
git commit -m "[Generated] swift-format"
# Store the commit hash for later use
echo "FORMAT_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Update git-blame-ignore-revs
if: env.swift_files_changes == 'true'
run: |
# Add the formatting commit hash to .git-blame-ignore-revs
echo "$FORMAT_COMMIT_HASH" >> .git-blame-ignore-revs
git add .git-blame-ignore-revs
git commit -m "Add swift-format commit to .git-blame-ignore-revs"
- name: Create pull request
if: env.swift_files_changes == 'true' || env.swift_format_changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
branch: "generated/swift-format"
delete-branch: true
title: "[Generated] swift-format"
body: "This action automatically runs swift-format on the project. Check the changes and merge them!"