Skip to content

Commit 3a7c8f4

Browse files
authored
optimize gha (#84)
* Create cancel.yml * Update swift.yml * Delete cancel.yml * Update swift.yml * Update swift.yml
1 parent e845872 commit 3a7c8f4

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

.github/workflows/swift.yml

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ on:
77
branches: [ main ]
88

99
jobs:
10+
cancel_previous:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: styfle/[email protected]
14+
with:
15+
workflow_id: ${{ github.event.workflow.id }}
16+
1017
build_and_test_spm_mac:
18+
needs: cancel_previous
1119
runs-on: macos-11
1220
steps:
1321
- uses: maxim-lobanov/setup-xcode@v1
@@ -25,6 +33,7 @@ jobs:
2533
run: swift test
2634

2735
build_and_test_spm_linux:
36+
needs: cancel_previous
2837
runs-on: ubuntu-latest
2938
steps:
3039
- uses: fwal/setup-swift@v1
@@ -42,6 +51,7 @@ jobs:
4251
run: swift test --enable-test-discovery
4352

4453
build_and_test_ios:
54+
needs: cancel_previous
4555
runs-on: macos-11
4656
steps:
4757
- uses: maxim-lobanov/setup-xcode@v1
@@ -50,12 +60,20 @@ jobs:
5060
- uses: actions/checkout@v2
5161
with:
5262
ref: ${{ github.event.pull_request.head.sha }}
63+
- uses: actions/cache@v2
64+
with:
65+
path: /Users/runner/Library/Developer/Xcode/DerivedData/**/SourcePackages/checkouts
66+
key: ${{ runner.os }}-spm-ios-${{ hashFiles('**/Package.resolved') }}
67+
restore-keys: |
68+
${{ runner.os }}-spm-ios
5369
- uses: webfactory/[email protected]
5470
with:
5571
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
5672
- run: xcodebuild -scheme Segment-Package test -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11'
5773

74+
5875
build_and_test_tvos:
76+
needs: cancel_previous
5977
runs-on: macos-11
6078
steps:
6179
- uses: maxim-lobanov/setup-xcode@v1
@@ -64,12 +82,19 @@ jobs:
6482
- uses: actions/checkout@v2
6583
with:
6684
ref: ${{ github.event.pull_request.head.sha }}
85+
- uses: actions/cache@v2
86+
with:
87+
path: /Users/runner/Library/Developer/Xcode/DerivedData/**/SourcePackages/checkouts
88+
key: ${{ runner.os }}-spm-tvos-${{ hashFiles('**/Package.resolved') }}
89+
restore-keys: |
90+
${{ runner.os }}-spm-tvos
6791
- uses: webfactory/[email protected]
6892
with:
6993
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
7094
- run: xcodebuild -scheme Segment-Package test -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV'
7195

7296
build_and_test_watchos:
97+
needs: cancel_previous
7398
runs-on: macos-11
7499
steps:
75100
- uses: maxim-lobanov/setup-xcode@v1
@@ -78,12 +103,19 @@ jobs:
78103
- uses: actions/checkout@v2
79104
with:
80105
ref: ${{ github.event.pull_request.head.sha }}
106+
- uses: actions/cache@v2
107+
with:
108+
path: /Users/runner/Library/Developer/Xcode/DerivedData/**/SourcePackages/checkouts
109+
key: ${{ runner.os }}-spm-watchos-${{ hashFiles('**/Package.resolved') }}
110+
restore-keys: |
111+
${{ runner.os }}-spm-watchos
81112
- uses: webfactory/[email protected]
82113
with:
83114
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
84115
- run: xcodebuild -scheme Segment-Package test -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 5 - 40mm'
85116

86-
build_examples:
117+
build_and_test_examples:
118+
needs: cancel_previous
87119
runs-on: macos-11
88120
steps:
89121
- uses: maxim-lobanov/setup-xcode@v1
@@ -92,17 +124,19 @@ jobs:
92124
- uses: actions/checkout@v2
93125
with:
94126
ref: ${{ github.event.pull_request.head.sha }}
127+
- uses: actions/cache@v2
128+
with:
129+
path: /Users/runner/Library/Developer/Xcode/DerivedData
130+
key: ${{ runner.os }}-spm-examples-${{ hashFiles('**/Package.resolved') }}
131+
restore-keys: |
132+
${{ runner.os }}-spm-examples
95133
- uses: webfactory/[email protected]
96134
with:
97135
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
98136
- name: build for ios simulator
99137
run: |
100138
cd Examples/apps/BasicExample
101139
xcodebuild -workspace "BasicExample.xcworkspace" -scheme "BasicExample" -sdk iphonesimulator
102-
- name: build for ios simulator
103-
run: |
104-
cd Examples/apps/DestinationsExample
105-
xcodebuild -workspace "DestinationsExample.xcworkspace" -scheme "DestinationsExample" -sdk iphonesimulator
106140
- name: build for ios simulator
107141
run: |
108142
cd Examples/apps/ObjCExample
@@ -115,3 +149,28 @@ jobs:
115149
run: |
116150
cd Examples/apps/SegmentUIKitExample
117151
xcodebuild -workspace "SegmentUIKitExample.xcworkspace" -scheme "SegmentUIKitExample" -destination 'platform=macOS,variant=Mac Catalyst'
152+
153+
154+
build_and_test_dest_examples:
155+
needs: cancel_previous
156+
runs-on: macos-11
157+
steps:
158+
- uses: maxim-lobanov/setup-xcode@v1
159+
with:
160+
xcode-version: '13.0'
161+
- uses: actions/checkout@v2
162+
with:
163+
ref: ${{ github.event.pull_request.head.sha }}
164+
- uses: actions/cache@v2
165+
with:
166+
path: /Users/runner/Library/Developer/Xcode/DerivedData
167+
key: ${{ runner.os }}-spm-dest-example-${{ hashFiles('**/Package.resolved') }}
168+
restore-keys: |
169+
${{ runner.os }}-spm-dest-example
170+
- uses: webfactory/[email protected]
171+
with:
172+
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
173+
- name: build for ios simulator
174+
run: |
175+
cd Examples/apps/DestinationsExample
176+
xcodebuild -workspace "DestinationsExample.xcworkspace" -scheme "DestinationsExample" -sdk iphonesimulator

0 commit comments

Comments
 (0)