Skip to content

Add Xcode-selector #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 19 additions & 48 deletions .github/workflows/test-full.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,54 @@
# Some of these test cases should fail, it is expected

name: Validate 'setup-xamarin' (all test cases)
on:
pull_request:
types: [ labeled ]

jobs:
partial-versions:
name: valid versions (should pass)
invalid-version-format:
name: invalid version format (should fail)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master

uses: actions/checkout@v2
- name: setup-xamarin
id: test
uses: ./
with:
mono-version: 6.6
xamarin-ios-version: 13.8
xamarin-mac-version: 6.6
xamarin-android-version: 10.1

- name: Validate versions
run: ./__tests__/validate-versions.sh '6.6' '13.8' '6.6' '10.1'
xamarin-mac-version: 6_6_0 # this version has invalid format

latest-keyword:
name: latest keyword (should pass)
xamarin-version-not-found:
name: Xamarin.iOS version is not found (should fail)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master

uses: actions/checkout@v2
- name: setup-xamarin
id: test
uses: ./
with:
mono-version: latest
xamarin-ios-version: latest
xamarin-mac-version: latest
xamarin-android-version: latest
mono-version: 6.6
xamarin-ios-version: 11.1 # this versino doesn't exist

full-versions:
name: valid full versions (should warn)
xcode-version-not-found:
name: Xcode version is not found (should fail)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: setup-xamarin
uses: ./
with:
xamarin-ios-version: 13.10.0.21
xamarin-mac-version: 6.6.0.12

- name: Validate versions
run: ./__tests__/validate-versions.sh '6.6.0' '13.10.0.21' '6.6.0.12' '10.1.3'

invalid-version-format:
name: invalid version format (should fail)
runs-on: macos-latest
steps:
- name: setup-xamarin
id: test
uses: ./
with:
xamarin-mac-version: 6_6_0 # this version has invalid format
uses: actions/checkout@v2

xamarin-version-not-found:
name: Xamarin.iOS version is not found (should fail)
runs-on: macos-latest
steps:
- name: setup-xamarin
id: test
uses: ./
with:
mono-version: 6.6
xamarin-ios-version: 11.1 # this versino doesn't exist
xcode-version: 10.3

invalid-platform:
name: invalid platform (should fail)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: setup-xamarin
id: test
uses: ./
Expand Down
49 changes: 38 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
- cron: 0 0 * * *

jobs:
partial-versions:
name: valid versions (should pass)
xamarin-partial-versions:
name: xamarin - valid versions
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v2

- name: setup-xamarin
uses: ./
Expand All @@ -21,14 +21,14 @@ jobs:
xamarin-android-version: 10.1

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

latest-keyword:
name: latest keyword (should pass)
xamarin-latest-keyword:
name: xamarin - latest keyword
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v2

- name: setup-xamarin
uses: ./
Expand All @@ -38,12 +38,12 @@ jobs:
xamarin-mac-version: latest
xamarin-android-version: latest

full-versions:
name: valid full versions (should warn)
xamarin-full-versions:
name: xamarin - valid full versions (should warn)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v2

- name: setup-xamarin
uses: ./
Expand All @@ -52,4 +52,31 @@ jobs:
xamarin-mac-version: 6.6.0.12

- name: Validate versions
run: ./__tests__/validate-versions.sh '6.6.0' '13.10.0.21' '6.6.0.12' '10.1.3'
run: pwsh ./__tests__/validate-xamarin-versions.ps1 -XamarinIOSVersion "13.10.0.21" -XamarinMacVersion "6.6.0.12"

xcode-full-version:
name: xcode - valid version
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: setup-xamarin
uses: ./
with:
xcode-version: 11.4

- name: Validate versions
run: pwsh ./__tests__/validate-xcode-version.ps1 -XcodeVersion "11.4"

xcode-wildcard-version:
name: xcode - wildcard version
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: setup-xamarin
uses: ./
with:
xcode-version: 11.x
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# setup-xamarin
This action is intended to switch between pre-installed versions Xamarin & Mono on macos-10.15 image in GitHub Actions.
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.
This action is intended to switch between pre-installed versions of Xamarin and Mono for macOS images in GitHub Actions.

# Available parameters
| Argument | Required | Description |
|-------------------------|----------|--------------------------------------------------|
| mono-version | False | Specify the version of Mono to switch |
| xamarin-ios-version | False | Specify the version of Xamarin.iOS to switch |
| xamarin-mac-version | False | Specify the version of Xamarin.Mac to switch |
| xamarin-android-version | False | Specify the version of Xamarin.Android to switch |
| Argument | Required | Description | Available versions |
|-------------------------|----------|-----------------------------------------------------------|--------------------|
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |

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

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

# License
Expand Down
19 changes: 0 additions & 19 deletions __tests__/validate-versions.sh

This file was deleted.

42 changes: 42 additions & 0 deletions __tests__/validate-xamarin-versions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
param (
[string]$MonoVersion,
[string]$XamarinIOSVersion,
[string]$XamarinMacVersion,
[string]$XamarinAndroidVersion
)

function Test-ToolVersion {
param (
[string]$ToolName,
[string]$ExpectedVersion
)

if ([string]::IsNullOrEmpty($ExpectedVersion)) {
return
}

Write-Host "Check $ToolName Version..."

$versionFilePath = "/Library/Frameworks/$ToolName.framework/Versions/Current/Version"
$actualVersion = Get-Content $versionFilePath
if (!$actualVersion.StartsWith($ExpectedVersion)) {
Write-Error("Incorrect $ToolName version: $actualVersion")
exit 1
}

Write-Host "Correct $ToolName version: $ExpectedVersion"
}

if (![string]::IsNullOrEmpty($MonoVersion)) {
Write-Host "Check Mono Version..."
$actualVersion = & mono --version
if (!$actualVersion[0].StartsWith("Mono JIT compiler version $MonoVersion")) {
Write-Error("Incorrect Mono version: $actualVersion")
exit 1
}
}

Test-ToolVersion -ToolName "Mono" -ExpectedVersion $MonoVersion
Test-ToolVersion -ToolName "Xamarin.IOS" -ExpectedVersion $XamarinIOSVersion
Test-ToolVersion -ToolName "Xamarin.Mac" -ExpectedVersion $XamarinMacVersion
Test-ToolVersion -ToolName "Xamarin.Android" -ExpectedVersion $XamarinAndroidVersion
19 changes: 19 additions & 0 deletions __tests__/validate-xcode-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
param (
[string]$XcodeVersion
)

$expectedXcodePath = "/Applications/Xcode_$XcodeVersion.app"

Write-Host "Check Xcode version"
$actualXcodePath = & xcode-select -p
if (!$actualXcodePath.StartsWith($expectedXcodePath)) {
Write-Error "Incorrect Xcode: $actualXcodePath"
exit 1
}

if ($env:MD_APPLE_SDK_ROOT -ne $expectedXcodePath) {
Write-Error "Incorrect Xcode: $($env:MD_APPLE_SDK_ROOT)"
exit 1
}

Write-Host "Correct Xcode: $XcodeVersion"
32 changes: 32 additions & 0 deletions __tests__/version-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ describe("VersionUtils", () => {
});
});

it("sortVersions", () => {
const actual = VersionUtils.sortVersions([
"11.2",
"11.4",
"10.1",
"11.2.1",
"10.2"
]);
expect(actual).toEqual([
"11.4",
"11.2.1",
"11.2",
"10.2",
"10.1"
]);
});

describe("isVersionsEqual", () => {
it.each([
["11.2", "11.2", true],
["11.x", "11.2", true],
["11.x.x", "11.2", true],
["11.x.x", "11.2.1", true],
["11", "11.2", false],
["11", "11.2.1", false],
["10", "11.2", false]
])("'%s', '%s' -> %s", (firstVersion: string, secondVersion: string, expected: boolean) => {
const actual = VersionUtils.isVersionsEqual(firstVersion, secondVersion);
expect(actual).toBe(expected);
});
});

describe("normalizeVersion", () => {
it.each([
["5", "5.x.x.x"],
Expand Down
Loading