Skip to content

Commit 42043cd

Browse files
Merge pull request #1 from LucaTools/test-workflow
Add `test.yml` workflow
2 parents 5b9aca7 + b5428b1 commit 42043cd

1 file changed

Lines changed: 142 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
# ─── Happy-path: version resolved via xcode-version input ────────────────────
11+
test-via-input:
12+
name: Test – xcode-version input
13+
runs-on: macos-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Detect latest available Xcode version
18+
id: detect
19+
run: |
20+
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
21+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
22+
23+
- name: Run action with xcode-version input
24+
uses: ./
25+
with:
26+
xcode-version: ${{ steps.detect.outputs.version }}
27+
28+
- name: Assert correct Xcode was selected
29+
run: |
30+
SELECTED=$(xcode-select -p)
31+
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
32+
if [ "$SELECTED" != "$EXPECTED" ]; then
33+
echo "Expected: $EXPECTED"
34+
echo "Got: $SELECTED"
35+
exit 1
36+
fi
37+
38+
# ─── Version resolved via .xcode-version file ────────────────────────────────
39+
test-via-xcode-version-file:
40+
name: Test – .xcode-version file
41+
runs-on: macos-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- name: Detect latest available Xcode version
46+
id: detect
47+
run: |
48+
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
49+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
50+
51+
- name: Write .xcode-version file
52+
run: echo "${{ steps.detect.outputs.version }}" > .xcode-version
53+
54+
- name: Run action with no input (reads .xcode-version file)
55+
uses: ./
56+
57+
- name: Assert correct Xcode was selected
58+
run: |
59+
SELECTED=$(xcode-select -p)
60+
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
61+
if [ "$SELECTED" != "$EXPECTED" ]; then
62+
echo "Expected: $EXPECTED"
63+
echo "Got: $SELECTED"
64+
exit 1
65+
fi
66+
67+
# ─── Version resolved via pre-set XCODE_VERSION environment variable ─────────
68+
test-via-env-var:
69+
name: Test – XCODE_VERSION env var
70+
runs-on: macos-latest
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Detect latest available Xcode version and export as env var
75+
id: detect
76+
run: |
77+
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
78+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
79+
echo "XCODE_VERSION=$VERSION" >> "$GITHUB_ENV"
80+
81+
- name: Run action with no input (reads XCODE_VERSION env var)
82+
uses: ./
83+
84+
- name: Assert correct Xcode was selected
85+
run: |
86+
SELECTED=$(xcode-select -p)
87+
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
88+
if [ "$SELECTED" != "$EXPECTED" ]; then
89+
echo "Expected: $EXPECTED"
90+
echo "Got: $SELECTED"
91+
exit 1
92+
fi
93+
94+
# ─── Priority: xcode-version input wins over .xcode-version file ─────────────
95+
test-input-overrides-file:
96+
name: Test – input takes priority over .xcode-version file
97+
runs-on: macos-latest
98+
steps:
99+
- uses: actions/checkout@v4
100+
101+
- name: Detect latest available Xcode version
102+
id: detect
103+
run: |
104+
VERSION=$(ls /Applications/ | grep -E '^Xcode_[0-9]' | sed 's/Xcode_//;s/\.app//' | sort -V | tail -1)
105+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
106+
107+
- name: Write invalid version to .xcode-version file
108+
run: echo "0.0.0" > .xcode-version
109+
110+
- name: Run action with valid input (overrides invalid .xcode-version file)
111+
uses: ./
112+
with:
113+
xcode-version: ${{ steps.detect.outputs.version }}
114+
115+
- name: Assert correct Xcode was selected (input version, not file version)
116+
run: |
117+
SELECTED=$(xcode-select -p)
118+
EXPECTED="/Applications/Xcode_${{ steps.detect.outputs.version }}.app/Contents/Developer"
119+
if [ "$SELECTED" != "$EXPECTED" ]; then
120+
echo "Expected: $EXPECTED"
121+
echo "Got: $SELECTED"
122+
exit 1
123+
fi
124+
125+
# ─── Failure path: no version source → action must fail ──────────────────────
126+
test-no-version-fails:
127+
name: Test – action fails when no version is configured
128+
runs-on: macos-latest
129+
steps:
130+
- uses: actions/checkout@v4
131+
132+
- name: Run action with no version source
133+
id: action
134+
uses: ./
135+
continue-on-error: true
136+
137+
- name: Assert action failed
138+
run: |
139+
if [ "${{ steps.action.outcome }}" != "failure" ]; then
140+
echo "Expected action to fail, but it succeeded"
141+
exit 1
142+
fi

0 commit comments

Comments
 (0)