-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (121 loc) · 4.95 KB
/
test.yml
File metadata and controls
143 lines (121 loc) · 4.95 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
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
135
136
137
138
139
140
141
142
143
name: Test
on:
pull_request:
push:
branches:
- main
workflow_call:
jobs:
# ─── Happy-path: version resolved via xcode-version input ────────────────────
test-via-input:
name: Test – xcode-version input
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Detect latest available Xcode version
id: detect
run: |
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Run action with xcode-version input
uses: ./
with:
xcode-version: ${{ steps.detect.outputs.version }}
- name: Assert correct Xcode was selected
run: |
SELECTED=$(xcode-select -p)
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
if [ "$SELECTED" != "$EXPECTED" ]; then
echo "Expected: $EXPECTED"
echo "Got: $SELECTED"
exit 1
fi
# ─── Version resolved via .xcode-version file ────────────────────────────────
test-via-xcode-version-file:
name: Test – .xcode-version file
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Detect latest available Xcode version
id: detect
run: |
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Write .xcode-version file
run: echo "${{ steps.detect.outputs.version }}" > .xcode-version
- name: Run action with no input (reads .xcode-version file)
uses: ./
- name: Assert correct Xcode was selected
run: |
SELECTED=$(xcode-select -p)
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
if [ "$SELECTED" != "$EXPECTED" ]; then
echo "Expected: $EXPECTED"
echo "Got: $SELECTED"
exit 1
fi
# ─── Version resolved via pre-set XCODE_VERSION environment variable ─────────
test-via-env-var:
name: Test – XCODE_VERSION env var
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Detect latest available Xcode version and export as env var
id: detect
run: |
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "XCODE_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Run action with no input (reads XCODE_VERSION env var)
uses: ./
- name: Assert correct Xcode was selected
run: |
SELECTED=$(xcode-select -p)
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
if [ "$SELECTED" != "$EXPECTED" ]; then
echo "Expected: $EXPECTED"
echo "Got: $SELECTED"
exit 1
fi
# ─── Priority: xcode-version input wins over .xcode-version file ─────────────
test-input-overrides-file:
name: Test – input takes priority over .xcode-version file
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Detect latest available Xcode version
id: detect
run: |
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Write invalid version to .xcode-version file
run: echo "0.0.0" > .xcode-version
- name: Run action with valid input (overrides invalid .xcode-version file)
uses: ./
with:
xcode-version: ${{ steps.detect.outputs.version }}
- name: Assert correct Xcode was selected (input version, not file version)
run: |
SELECTED=$(xcode-select -p)
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
if [ "$SELECTED" != "$EXPECTED" ]; then
echo "Expected: $EXPECTED"
echo "Got: $SELECTED"
exit 1
fi
# ─── Failure path: no version source → action must fail ──────────────────────
test-no-version-fails:
name: Test – action fails when no version is configured
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Run action with no version source
id: action
uses: ./
continue-on-error: true
- name: Assert action failed
run: |
if [ "${{ steps.action.outcome }}" != "failure" ]; then
echo "Expected action to fail, but it succeeded"
exit 1
fi