Skip to content

Commit 14da431

Browse files
committed
Update test.yml
1 parent d93ff73 commit 14da431

File tree

7 files changed

+53
-35
lines changed

7 files changed

+53
-35
lines changed

.github/workflows/test.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build: # make sure build/ci work properly
1010
strategy:
1111
matrix:
12-
os: [ubuntu-18.04]
12+
os: [ubuntu-16.04, ubuntu-18.04, macOS-10.14, macOS-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- uses: actions/checkout@v2
@@ -20,14 +20,13 @@ jobs:
2020
needs: [build]
2121
strategy:
2222
matrix:
23-
os: [ubuntu-18.04]
23+
os: [ubuntu-16.04, ubuntu-18.04, macOS-10.14, macOS-latest]
2424
runs-on: ${{ matrix.os }}
2525
steps:
2626
- uses: actions/checkout@v2
2727
- uses: ./
2828
with:
2929
version: '5.1.3'
30-
platform: ubuntu-18.04
3130
- run: swift --version
3231
publish:
3332
needs: [build, test]

README.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# setup-swift
22

3-
This action sets up a swift environment for use in actions by:
4-
5-
- optionally downloading and caching a version of swift by version and adding to PATH.
3+
This action sets up a swift environment for use in actions.
4+
Supported platforms are: macOS, ubuntu-16.04, ubuntu-18.04
5+
For available versions check the release section on [swift.org](https://swift.org/download/#releases).
66

77
# Usage
88

9-
See [action.yml](action.yml)
10-
11-
Basic:
129
```yaml
1310
steps:
1411
- uses: actions/checkout@latest
1512
- uses: TG908/setup-swift@v0
1613
with:
1714
version: '5.1.3'
18-
platform: 'ubuntu18.04'
1915
- run: swift build
2016
```

action.yml

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ inputs:
99
description: 'Swift version to use.'
1010
required: true
1111
default: '5.1.3'
12-
platform:
13-
description: 'Platform'
14-
required: true
15-
default: 'osx'
1612
runs:
1713
using: 'node12'
1814
main: 'dist/index.js'

dist/index.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,7 @@ function run() {
12531253
return __awaiter(this, void 0, void 0, function* () {
12541254
try {
12551255
const version = core.getInput('version');
1256-
const platform = core.getInput('platform');
1257-
yield installer.getSwift(version, platform);
1256+
yield installer.getSwift(version);
12581257
}
12591258
catch (error) {
12601259
core.setFailed(error.message);
@@ -4565,24 +4564,37 @@ const tc = __importStar(__webpack_require__(533));
45654564
const exec = __importStar(__webpack_require__(986));
45664565
const io = __importStar(__webpack_require__(1));
45674566
const path = __importStar(__webpack_require__(622));
4568-
function getSwift(version, platform) {
4567+
function getSwift(version) {
45694568
return __awaiter(this, void 0, void 0, function* () {
4569+
// determine os
45704570
if (process.platform === 'darwin') {
4571-
return getSwiftMacOS(version, platform);
4571+
return getSwiftMacOS(version);
45724572
}
45734573
else if (process.platform === 'linux') {
4574-
return getSwiftLinux(version, platform);
4574+
return getSwiftLinux(version);
45754575
}
45764576
else {
45774577
core.setFailed('Platform not supported');
45784578
}
45794579
});
45804580
}
45814581
exports.getSwift = getSwift;
4582-
function getSwiftLinux(version, platform) {
4582+
function getSwiftLinux(version) {
45834583
return __awaiter(this, void 0, void 0, function* () {
45844584
const swiftBranch = `swift-${version}-release`;
45854585
const swiftVersion = `swift-${version}-RELEASE`;
4586+
// determine os release
4587+
let lsbReleaseStdOut = '';
4588+
const options = {
4589+
listeners: {
4590+
stdout: (data) => {
4591+
lsbReleaseStdOut += data.toString();
4592+
}
4593+
}
4594+
};
4595+
yield exec.exec('lsb_release', ['-rs'], options);
4596+
const platform = `ubuntu${lsbReleaseStdOut.trim()}`;
4597+
// check cache
45864598
let toolPath = tc.find('Swift', version, platform);
45874599
if (toolPath) {
45884600
core.debug(`Tool found in cache ${toolPath}`);
@@ -4601,11 +4613,12 @@ function getSwiftLinux(version, platform) {
46014613
core.addPath(swiftBin);
46024614
});
46034615
}
4604-
function getSwiftMacOS(version, platform) {
4616+
function getSwiftMacOS(version) {
46054617
return __awaiter(this, void 0, void 0, function* () {
46064618
const swiftBranch = `swift-${version}-release`;
46074619
const swiftVersion = `swift-${version}-RELEASE`;
4608-
let toolPath = tc.find('Swift', version, platform);
4620+
// check cache
4621+
let toolPath = tc.find('Swift', version, 'osx');
46094622
if (toolPath) {
46104623
core.debug(`Tool found in cache ${toolPath}`);
46114624
}
@@ -4622,6 +4635,7 @@ function getSwiftMacOS(version, platform) {
46224635
const swiftDirectory = yield tc.extractTar(swiftPayload, toolchain);
46234636
toolPath = yield tc.cacheDir(swiftDirectory, 'Swift', version, 'osx');
46244637
}
4638+
// install xcode toolchain
46254639
let stdOut = '';
46264640
const options = {
46274641
listeners: {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-swift-action",
3-
"version": "0.0.3",
3+
"version": "1.0.0",
44
"private": true,
55
"description": "Setup a Swift environment",
66
"main": "lib/main.js",

src/installer.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,35 @@ import * as exec from '@actions/exec'
44
import * as io from '@actions/io'
55
import * as path from 'path'
66

7-
export async function getSwift(
8-
version: string,
9-
platform: string
10-
): Promise<void> {
7+
export async function getSwift(version: string): Promise<void> {
8+
// determine os
119
if (process.platform === 'darwin') {
12-
return getSwiftMacOS(version, platform)
10+
return getSwiftMacOS(version)
1311
} else if (process.platform === 'linux') {
14-
return getSwiftLinux(version, platform)
12+
return getSwiftLinux(version)
1513
} else {
1614
core.setFailed('Platform not supported')
1715
}
1816
}
1917

20-
async function getSwiftLinux(version: string, platform: string): Promise<void> {
18+
async function getSwiftLinux(version: string): Promise<void> {
2119
const swiftBranch = `swift-${version}-release`
2220
const swiftVersion = `swift-${version}-RELEASE`
21+
22+
// determine os release
23+
let lsbReleaseStdOut = ''
24+
25+
const options = {
26+
listeners: {
27+
stdout: (data: Buffer) => {
28+
lsbReleaseStdOut += data.toString()
29+
}
30+
}
31+
}
32+
33+
await exec.exec('lsb_release', ['-rs'], options)
34+
const platform = `ubuntu${lsbReleaseStdOut.trim()}`
35+
// check cache
2336
let toolPath = tc.find('Swift', version, platform)
2437

2538
if (toolPath) {
@@ -44,11 +57,11 @@ async function getSwiftLinux(version: string, platform: string): Promise<void> {
4457
core.addPath(swiftBin)
4558
}
4659

47-
async function getSwiftMacOS(version: string, platform: string): Promise<void> {
60+
async function getSwiftMacOS(version: string): Promise<void> {
4861
const swiftBranch = `swift-${version}-release`
4962
const swiftVersion = `swift-${version}-RELEASE`
50-
51-
let toolPath = tc.find('Swift', version, platform)
63+
// check cache
64+
let toolPath = tc.find('Swift', version, 'osx')
5265

5366
if (toolPath) {
5467
core.debug(`Tool found in cache ${toolPath}`)
@@ -76,6 +89,7 @@ async function getSwiftMacOS(version: string, platform: string): Promise<void> {
7689
toolPath = await tc.cacheDir(swiftDirectory, 'Swift', version, 'osx')
7790
}
7891

92+
// install xcode toolchain
7993
let stdOut = ''
8094

8195
const options = {

src/main.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import * as installer from './installer'
44
async function run(): Promise<void> {
55
try {
66
const version = core.getInput('version')
7-
const platform = core.getInput('platform')
87

9-
await installer.getSwift(version, platform)
8+
await installer.getSwift(version)
109
} catch (error) {
1110
core.setFailed(error.message)
1211
}

0 commit comments

Comments
 (0)