Skip to content

Commit ff0372a

Browse files
Add Xcode-selector (#2)
* add xcode-selector * update readme * fix checkout
1 parent 80746dd commit ff0372a

21 files changed

+641
-258
lines changed

.github/workflows/test-full.yml

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,54 @@
1+
# Some of these test cases should fail, it is expected
2+
13
name: Validate 'setup-xamarin' (all test cases)
24
on:
35
pull_request:
46
types: [ labeled ]
57

68
jobs:
7-
partial-versions:
8-
name: valid versions (should pass)
9+
invalid-version-format:
10+
name: invalid version format (should fail)
911
runs-on: macos-latest
1012
steps:
1113
- name: Checkout
12-
uses: actions/checkout@master
13-
14+
uses: actions/checkout@v2
1415
- name: setup-xamarin
16+
id: test
1517
uses: ./
1618
with:
17-
mono-version: 6.6
18-
xamarin-ios-version: 13.8
19-
xamarin-mac-version: 6.6
20-
xamarin-android-version: 10.1
21-
22-
- name: Validate versions
23-
run: ./__tests__/validate-versions.sh '6.6' '13.8' '6.6' '10.1'
19+
xamarin-mac-version: 6_6_0 # this version has invalid format
2420

25-
latest-keyword:
26-
name: latest keyword (should pass)
21+
xamarin-version-not-found:
22+
name: Xamarin.iOS version is not found (should fail)
2723
runs-on: macos-latest
2824
steps:
2925
- name: Checkout
30-
uses: actions/checkout@master
31-
26+
uses: actions/checkout@v2
3227
- name: setup-xamarin
28+
id: test
3329
uses: ./
3430
with:
35-
mono-version: latest
36-
xamarin-ios-version: latest
37-
xamarin-mac-version: latest
38-
xamarin-android-version: latest
31+
mono-version: 6.6
32+
xamarin-ios-version: 11.1 # this versino doesn't exist
3933

40-
full-versions:
41-
name: valid full versions (should warn)
34+
xcode-version-not-found:
35+
name: Xcode version is not found (should fail)
4236
runs-on: macos-latest
4337
steps:
4438
- name: Checkout
45-
uses: actions/checkout@master
46-
47-
- name: setup-xamarin
48-
uses: ./
49-
with:
50-
xamarin-ios-version: 13.10.0.21
51-
xamarin-mac-version: 6.6.0.12
52-
53-
- name: Validate versions
54-
run: ./__tests__/validate-versions.sh '6.6.0' '13.10.0.21' '6.6.0.12' '10.1.3'
55-
56-
invalid-version-format:
57-
name: invalid version format (should fail)
58-
runs-on: macos-latest
59-
steps:
60-
- name: setup-xamarin
61-
id: test
62-
uses: ./
63-
with:
64-
xamarin-mac-version: 6_6_0 # this version has invalid format
39+
uses: actions/checkout@v2
6540

66-
xamarin-version-not-found:
67-
name: Xamarin.iOS version is not found (should fail)
68-
runs-on: macos-latest
69-
steps:
7041
- name: setup-xamarin
71-
id: test
7242
uses: ./
7343
with:
74-
mono-version: 6.6
75-
xamarin-ios-version: 11.1 # this versino doesn't exist
44+
xcode-version: 10.3
7645

7746
invalid-platform:
7847
name: invalid platform (should fail)
7948
runs-on: ubuntu-latest
8049
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v2
8152
- name: setup-xamarin
8253
id: test
8354
uses: ./

.github/workflows/test.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
- cron: 0 0 * * *
66

77
jobs:
8-
partial-versions:
9-
name: valid versions (should pass)
8+
xamarin-partial-versions:
9+
name: xamarin - valid versions
1010
runs-on: macos-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@master
13+
uses: actions/checkout@v2
1414

1515
- name: setup-xamarin
1616
uses: ./
@@ -21,14 +21,14 @@ jobs:
2121
xamarin-android-version: 10.1
2222

2323
- name: Validate versions
24-
run: ./__tests__/validate-versions.sh '6.6' '13.8' '6.6' '10.1'
24+
run: pwsh ./__tests__/validate-xamarin-versions.ps1 "6.6" "13.8" "6.6" "10.1"
2525

26-
latest-keyword:
27-
name: latest keyword (should pass)
26+
xamarin-latest-keyword:
27+
name: xamarin - latest keyword
2828
runs-on: macos-latest
2929
steps:
3030
- name: Checkout
31-
uses: actions/checkout@master
31+
uses: actions/checkout@v2
3232

3333
- name: setup-xamarin
3434
uses: ./
@@ -38,12 +38,12 @@ jobs:
3838
xamarin-mac-version: latest
3939
xamarin-android-version: latest
4040

41-
full-versions:
42-
name: valid full versions (should warn)
41+
xamarin-full-versions:
42+
name: xamarin - valid full versions (should warn)
4343
runs-on: macos-latest
4444
steps:
4545
- name: Checkout
46-
uses: actions/checkout@master
46+
uses: actions/checkout@v2
4747

4848
- name: setup-xamarin
4949
uses: ./
@@ -52,4 +52,31 @@ jobs:
5252
xamarin-mac-version: 6.6.0.12
5353

5454
- name: Validate versions
55-
run: ./__tests__/validate-versions.sh '6.6.0' '13.10.0.21' '6.6.0.12' '10.1.3'
55+
run: pwsh ./__tests__/validate-xamarin-versions.ps1 -XamarinIOSVersion "13.10.0.21" -XamarinMacVersion "6.6.0.12"
56+
57+
xcode-full-version:
58+
name: xcode - valid version
59+
runs-on: macos-latest
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v2
63+
64+
- name: setup-xamarin
65+
uses: ./
66+
with:
67+
xcode-version: 11.4
68+
69+
- name: Validate versions
70+
run: pwsh ./__tests__/validate-xcode-version.ps1 -XcodeVersion "11.4"
71+
72+
xcode-wildcard-version:
73+
name: xcode - wildcard version
74+
runs-on: macos-latest
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v2
78+
79+
- name: setup-xamarin
80+
uses: ./
81+
with:
82+
xcode-version: 11.x

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# setup-xamarin
2-
This action is intended to switch between pre-installed versions Xamarin & Mono on macos-10.15 image in GitHub Actions.
3-
The list of available versions can be found in [virtual-environments](https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#mono) repository.
2+
This action is intended to switch between pre-installed versions of Xamarin and Mono for macOS images in GitHub Actions.
3+
44
# Available parameters
5-
| Argument | Required | Description |
6-
|-------------------------|----------|--------------------------------------------------|
7-
| mono-version | False | Specify the version of Mono to switch |
8-
| xamarin-ios-version | False | Specify the version of Xamarin.iOS to switch |
9-
| xamarin-mac-version | False | Specify the version of Xamarin.Mac to switch |
10-
| xamarin-android-version | False | Specify the version of Xamarin.Android to switch |
5+
| Argument | Required | Description | Available versions |
6+
|-------------------------|----------|-----------------------------------------------------------|--------------------|
7+
| mono-version | False | Specify the version of Mono to switch | [Link](https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#mono) |
8+
| xamarin-ios-version | False | Specify the version of Xamarin.iOS to switch | [Link](https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#xamarinios) |
9+
| xamarin-mac-version | False | Specify the version of Xamarin.Mac to switch | [Link](https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#xamarinmac) |
10+
| xamarin-android-version | False | Specify the version of Xamarin.Android to switch | [Link](https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#xamarinandroid) |
11+
| xcode-version | False | Specify the Xcode to use with Xamarin.iOS and Xamarin.Mac | [Link](https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#xcode) |
1112

12-
All fields support the following format: `latest`, `13`, `13.2`, `13.2.1.4`
13+
- `mono-version`, `xamarin-ios-version`, `xamarin-mac-version`, `xamarin-android-version` parameters support the following format: `latest`, `13`, `13.2`, `13.2.1.4`
14+
- `xcode-version` parameter supports the following format: `latest`, `11.4`, `11.x`, `11.2.1`
1315

1416
# Usage
1517
```
@@ -30,6 +32,7 @@ jobs:
3032
xamarin-ios-version: 13 # specify version in '<major>' format
3133
xamarin-mac-version: latest # specify 'latest' keyword to pick up the latest available version
3234
xamarin-android-version: 10.1.3.7 # specify full version; it is not recomended option because your pipeline can be broken suddenly in future
35+
xcode-version: 11.x # set the latest available Xcode 11
3336
```
3437

3538
# License

__tests__/validate-versions.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
param (
2+
[string]$MonoVersion,
3+
[string]$XamarinIOSVersion,
4+
[string]$XamarinMacVersion,
5+
[string]$XamarinAndroidVersion
6+
)
7+
8+
function Test-ToolVersion {
9+
param (
10+
[string]$ToolName,
11+
[string]$ExpectedVersion
12+
)
13+
14+
if ([string]::IsNullOrEmpty($ExpectedVersion)) {
15+
return
16+
}
17+
18+
Write-Host "Check $ToolName Version..."
19+
20+
$versionFilePath = "/Library/Frameworks/$ToolName.framework/Versions/Current/Version"
21+
$actualVersion = Get-Content $versionFilePath
22+
if (!$actualVersion.StartsWith($ExpectedVersion)) {
23+
Write-Error("Incorrect $ToolName version: $actualVersion")
24+
exit 1
25+
}
26+
27+
Write-Host "Correct $ToolName version: $ExpectedVersion"
28+
}
29+
30+
if (![string]::IsNullOrEmpty($MonoVersion)) {
31+
Write-Host "Check Mono Version..."
32+
$actualVersion = & mono --version
33+
if (!$actualVersion[0].StartsWith("Mono JIT compiler version $MonoVersion")) {
34+
Write-Error("Incorrect Mono version: $actualVersion")
35+
exit 1
36+
}
37+
}
38+
39+
Test-ToolVersion -ToolName "Mono" -ExpectedVersion $MonoVersion
40+
Test-ToolVersion -ToolName "Xamarin.IOS" -ExpectedVersion $XamarinIOSVersion
41+
Test-ToolVersion -ToolName "Xamarin.Mac" -ExpectedVersion $XamarinMacVersion
42+
Test-ToolVersion -ToolName "Xamarin.Android" -ExpectedVersion $XamarinAndroidVersion

__tests__/validate-xcode-version.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
param (
2+
[string]$XcodeVersion
3+
)
4+
5+
$expectedXcodePath = "/Applications/Xcode_$XcodeVersion.app"
6+
7+
Write-Host "Check Xcode version"
8+
$actualXcodePath = & xcode-select -p
9+
if (!$actualXcodePath.StartsWith($expectedXcodePath)) {
10+
Write-Error "Incorrect Xcode: $actualXcodePath"
11+
exit 1
12+
}
13+
14+
if ($env:MD_APPLE_SDK_ROOT -ne $expectedXcodePath) {
15+
Write-Error "Incorrect Xcode: $($env:MD_APPLE_SDK_ROOT)"
16+
exit 1
17+
}
18+
19+
Write-Host "Correct Xcode: $XcodeVersion"

__tests__/version-utils.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,38 @@ describe("VersionUtils", () => {
1515
});
1616
});
1717

18+
it("sortVersions", () => {
19+
const actual = VersionUtils.sortVersions([
20+
"11.2",
21+
"11.4",
22+
"10.1",
23+
"11.2.1",
24+
"10.2"
25+
]);
26+
expect(actual).toEqual([
27+
"11.4",
28+
"11.2.1",
29+
"11.2",
30+
"10.2",
31+
"10.1"
32+
]);
33+
});
34+
35+
describe("isVersionsEqual", () => {
36+
it.each([
37+
["11.2", "11.2", true],
38+
["11.x", "11.2", true],
39+
["11.x.x", "11.2", true],
40+
["11.x.x", "11.2.1", true],
41+
["11", "11.2", false],
42+
["11", "11.2.1", false],
43+
["10", "11.2", false]
44+
])("'%s', '%s' -> %s", (firstVersion: string, secondVersion: string, expected: boolean) => {
45+
const actual = VersionUtils.isVersionsEqual(firstVersion, secondVersion);
46+
expect(actual).toBe(expected);
47+
});
48+
});
49+
1850
describe("normalizeVersion", () => {
1951
it.each([
2052
["5", "5.x.x.x"],

0 commit comments

Comments
 (0)