forked from signalapp/Signal-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (79 loc) · 2.87 KB
/
precommit.yml
File metadata and controls
94 lines (79 loc) · 2.87 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: precommit
on:
pull_request:
paths:
- '.github/workflows/precommit.yml'
- 'Scripts/lint/lint-license-headers'
- 'Scripts/lint/util.py'
- 'Scripts/precommit.py'
- 'Scripts/sort-Xcode-project-file'
- '**/*.cpp'
- '**/*.h'
- '**/*.hpp'
- '**/*.m'
- '**/*.mm'
- '**/*.pbxproj'
- '**/*.pch'
- '**/*.proto'
- '**/*.swift'
push:
branches:
- main
paths:
- '.github/workflows/precommit.yml'
# On PRs, "head_ref" is defined and is consistent across updates. On
# pushes, it's not defined, so we use "run_id", which is unique across
# every run; as a result, all actions on pushes will run to completion.
#
# Reference: https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
# Path format pulled from https://github.com/actions/runner-images/blob/main/images/macos/macos-26-arm64-Readme.md#xcode
DEVELOPER_DIR: /Applications/Xcode_26.4.app
# v0.60.1
swiftformat-ref: c8e50ff2cfc2eab46246c072a9ae25ab656c6ec3
jobs:
precommit:
name: precommit
timeout-minutes: 10
runs-on: macos-26
steps:
- uses: actions/checkout@v6
with:
path: 'Signal-iOS'
- name: Fetch base commit
if: github.event_name == 'pull_request'
working-directory: Signal-iOS
run: git fetch origin --depth 1 ${{ github.base_ref }}
- name: Install dependencies
if: github.event_name == 'pull_request'
run: brew install clang-format
- name: Cache SwiftFormat
id: cache-swiftformat
uses: actions/cache@v5
with:
path: SwiftFormat/.build
key: SwiftFormat-${{ env.swiftformat-ref }}-${{ env.DEVELOPER_DIR }}
- uses: actions/checkout@v6
if: steps.cache-swiftformat.outputs.cache-hit != 'true'
with:
path: 'SwiftFormat'
ref: ${{ env.swiftformat-ref }}
repository: 'nicklockwood/SwiftFormat'
- name: Build SwiftFormat
if: steps.cache-swiftformat.outputs.cache-hit != 'true'
working-directory: SwiftFormat
run: swift build -c release --product swiftformat
- name: Add binaries to PATH
if: github.event_name == 'pull_request'
run: echo "$GITHUB_WORKSPACE/SwiftFormat/.build/release" >> "$GITHUB_PATH"
- name: Run precommit on files changed in the PR
if: github.event_name == 'pull_request'
working-directory: Signal-iOS
run: |
Scripts/precommit.py --ref origin/${{ github.base_ref }}
# https://help.github.com/en/actions/reference/development-tools-for-github-actions#logging-commands
git diff --name-only | sed -E 's|(.*)|::error file=\1::Incorrectly formatted (Scripts/precommit.py)|'
git diff --exit-code || exit 1