-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
134 lines (123 loc) · 4.86 KB
/
action.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: 'Swift - Build and Test'
description: 'Builds and tests a Swift package on the current platform'
inputs:
working-directory:
description: 'Directory containing the Swift package'
required: false
default: '.'
scheme:
description: 'The scheme to build and test'
required: true
type:
description: 'Build type for Apple platforms (ios, watchos, visionos, tvos)'
required: false
xcode:
description: 'Xcode version path for Apple platforms'
required: false
deviceName:
description: 'Simulator device name for Apple platforms'
required: false
osVersion:
description: 'Simulator OS version for Apple platforms'
required: false
runs:
using: "composite"
steps:
- name: Detect OS
shell: bash
id: detect-os
working-directory: ${{ inputs.working-directory }}
run: |
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "os=macos" >> $GITHUB_OUTPUT
echo "DERIVED_DATA_PATH=$RUNNER_TEMP/DerivedData" >> $GITHUB_ENV
else
echo "os=ubuntu" >> $GITHUB_OUTPUT
fi
# macOS specific steps
- name: Set Xcode Name
if: steps.detect-os.outputs.os == 'macos' && inputs.xcode
shell: bash
working-directory: ${{ inputs.working-directory }}
run: echo "XCODE_NAME=$(basename -- ${{ inputs.xcode }} | sed 's/\.[^.]*$//' | cut -d'_' -f2)" >> $GITHUB_ENV
- name: Setup Xcode
if: steps.detect-os.outputs.os == 'macos' && inputs.xcode
shell: bash
working-directory: ${{ inputs.working-directory }}
run: sudo xcode-select -s ${{ inputs.xcode }}/Contents/Developer
- name: Set SDK and Platform
if: steps.detect-os.outputs.os == 'macos' && inputs.type
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
case ${{ inputs.type }} in
ios)
echo "PLATFORM=iOS Simulator" >> $GITHUB_ENV
echo "SDK=iphonesimulator" >> $GITHUB_ENV
;;
watchos)
echo "PLATFORM=watchOS Simulator" >> $GITHUB_ENV
echo "SDK=watchsimulator" >> $GITHUB_ENV
;;
visionos)
echo "PLATFORM=visionOS Simulator" >> $GITHUB_ENV
echo "SDK=xrsimulator" >> $GITHUB_ENV
;;
tvos)
echo "PLATFORM=tvOS Simulator" >> $GITHUB_ENV
echo "SDK=appletvsimulator" >> $GITHUB_ENV
;;
esac
- uses: irgaly/xcode-cache@v1
if: steps.detect-os.outputs.os == 'macos' && inputs.type
with:
key: xcode-deriveddata-${{ runner.os }}-${{ env.XCODE_NAME }}-${{ hashFiles('${{ inputs.working-directory }}/Package.resolved') }}-${{ github.sha }}
restore-keys: |
xcode-deriveddata-${{ runner.os }}-${{ env.XCODE_NAME }}-${{ hashFiles('${{ inputs.working-directory }}/Package.resolved') }}-
deriveddata-directory: ${{ env.DERIVED_DATA_PATH }}
swiftpm-package-resolved-file: |
${{ inputs.working-directory }}/Package.resolved
# Ubuntu specific steps
- name: Get Swift and OS versions
if: steps.detect-os.outputs.os == 'ubuntu'
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
SWIFT_VERSION=$(swift --version | head -n 1 | cut -d ' ' -f 3)
OS_VERSION=$(. /etc/os-release && echo $VERSION_CODENAME)
echo "SWIFT_VERSION=$SWIFT_VERSION" >> $GITHUB_ENV
echo "OS_VERSION=$OS_VERSION" >> $GITHUB_ENV
# Caching steps
- name: Cache swift package modules (macOS)
if: steps.detect-os.outputs.os == 'macos' && !inputs.type
uses: actions/cache@v4
with:
path: ${{ inputs.working-directory }}/.build
key: spm-${{ runner.os }}-${{ env.XCODE_NAME }}-${{ hashFiles('Package.resolved') }}
restore-keys: |
spm-${{ runner.os }}-${{ env.XCODE_NAME }}-
- name: Cache swift package modules (Ubuntu)
if: steps.detect-os.outputs.os == 'ubuntu'
uses: actions/cache@v4
with:
path: ${{ inputs.working-directory }}/.build
key: spm-${{ env.OS_VERSION }}-${{ env.SWIFT_VERSION }}-${{ hashFiles('Package.resolved') }}
# Build and test steps
- name: Build and Test
if: steps.detect-os.outputs.os == 'macos' && !inputs.type || steps.detect-os.outputs.os == 'ubuntu'
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
swift build
swift test --enable-code-coverage
- name: Build and Test (macOS Device)
if: steps.detect-os.outputs.os == 'macos' && inputs.type
shell: bash
working-directory: ${{ inputs.working-directory }}
run: >
xcodebuild test
-scheme ${{ inputs.scheme }}
-sdk ${{ env.SDK }}
-destination 'platform=${{ env.PLATFORM }},name=${{ inputs.deviceName }},OS=${{ inputs.osVersion }}'
-enableCodeCoverage YES
-derivedDataPath ${{ env.DERIVED_DATA_PATH }}