generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.mjs
119 lines (99 loc) · 3 KB
/
index.mjs
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
import fs from 'fs';
import os from 'os';
import path from 'path';
import core from '@actions/core';
import exec from '@actions/exec';
import * as swiftenv from './swiftenv.mjs';
async function installEssentials() {
core.startGroup('Install Essentials');
switch (process.platform) {
case 'linux':
const osRelease = new Map();
const osReleaseString = await fs.promises.readFile('/etc/os-release', 'utf8');
osReleaseString.split('\n').forEach(
(value) => {
const words = value.split('=');
if (words.length != 2) {
return;
}
osRelease.set(words[0].trim(), words[1].trim());
}
);
switch (osRelease.get("ID")) {
case 'ubuntu':
await exec.exec('sudo apt-get update');
switch (osRelease.get("VERSION_ID")) {
case '"18.04"':
await exec.exec('sudo apt-get install \
binutils \
git \
libc6-dev \
libcurl4 \
libedit2 \
libgcc-5-dev \
libpython2.7 \
libsqlite3-0 \
libstdc++-5-dev \
libxml2 \
pkg-config \
tzdata \
zlib1g-dev');
break;
case '"20.04"':
await exec.exec('sudo apt-get install \
binutils \
git \
gnupg2 \
libc6-dev \
libcurl4 \
libedit2 \
libgcc-9-dev \
libpython2.7 \
libsqlite3-0 \
libstdc++-9-dev \
libxml2 \
libz3-dev \
pkg-config \
tzdata \
uuid-dev \
zlib1g-dev');
break;
}
break;
}
}
core.endGroup();
}
async function installSwiftenv() {
core.startGroup('Install swiftenv');
const swiftenvRoot = process.env['SWIFTENV_ROOT'] || path.join(os.homedir(), '.swiftenv');
await exec.exec('git clone --depth 1 --no-tags --progress https://github.com/kylef/swiftenv.git ' + swiftenvRoot);
core.exportVariable('SWIFTENV_ROOT', swiftenvRoot);
core.addPath(path.join(swiftenvRoot, 'bin'));
core.addPath(path.join(swiftenvRoot, 'shims'));
core.endGroup();
}
async function installSwift(options = {}) {
core.startGroup('Install swift');
await swiftenv.install(options);
await swiftenv.rehash(options);
core.endGroup();
}
async function setupSwift() {
const swiftVersion = core.getInput('swift-version', { required: false });
if (swiftVersion) {
core.exportVariable('SWIFT_VERSION', swiftVersion)
}
await installEssentials();
await installSwiftenv();
await installSwift({'swiftVersion': swiftVersion, 'debug': core.isDebug()});
}
// most @actions toolkit packages have async methods
export async function run() {
try {
await setupSwift();
} catch (error) {
core.setFailed(error.message);
}
}
run();