-
Notifications
You must be signed in to change notification settings - Fork 12
/
action.js
146 lines (117 loc) · 5.55 KB
/
action.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const core = require('./.action/core')
const exec = require('./.action/exec')
const path = require('path')
const artifact = require('././.action/artifact')
const fs = require('fs')
const scxVersion = 'v2.3.0'
const outputPath = '.build/xcframework-zipfile.url'
core.setCommandEcho(true)
async function run() {
try {
let packagePath = core.getInput('path', { required: false })
let targets = core.getInput('target', { required: false })
let configuration = core.getInput('configuration', { required: false })
let platforms = core.getInput('platforms', { required: false })
let xcconfig = core.getInput('xcconfig', { required: false })
// install mint if its not installed
await installUsingBrewIfRequired("mint")
// install ourselves if not installed
await installUsingMintIfRequired('swift-create-xcframework', 'unsignedapps/swift-create-xcframework')
// put together our options
var options = ['--zip', '--github-action']
if (!!packagePath) {
options.push('--package-path')
options.push(packagePath)
}
if (!!configuration) {
options.push('--configuration')
options.push(configuration)
}
if (!!xcconfig) {
options.push('--xcconfig')
options.push(xcconfig)
}
if (!!platforms) {
platforms
.split(',')
.map((p) => p.trim())
.forEach((platform) => {
options.push('--platform')
options.push(platform)
})
}
if (!targets) {
targets
.split(',')
.map((t) => t.trim())
.filter((t) => t.length > 0)
.forEach((target) => {
options.push(target)
})
}
await runUsingMint('swift-create-xcframework', options)
let client = artifact.create()
let files = fs.readFileSync(outputPath, { encoding: 'utf8' })
.split('\n')
.map((file) => file.trim())
for (var i = 0, c = files.length; i < c; i++) {
let file = files[i]
let name = path.basename(file)
await client.uploadArtifact(name, [file], path.dirname(file))
}
} catch (error) {
core.setFailed(error)
}
}
async function installUsingBrewIfRequired(package) {
if (await isInstalled(package)) {
core.info(package + " is already installed.")
} else {
core.info("Installing " + package)
await exec.exec('brew', ['install', package])
}
}
async function installUsingMintIfRequired(command, package) {
if (await isInstalled(command)) {
core.info(command + " is already installed")
} else {
core.info("Installing " + package)
await exec.exec('mint', ['install', 'unsignedapps/swift-create-xcframework@' + scxVersion])
}
}
async function isInstalled(command) {
return await exec.exec('which', [command], { silent: true, failOnStdErr: false, ignoreReturnCode: true }) == 0
}
async function runUsingMint(command, options) {
await exec.exec('mint', ['run', command, ...options])
}
run()
// Kuroneko:swift-create-xcframework bok$ swift create-xcframework --help
// OVERVIEW: Creates an XCFramework out of a Swift Package using xcodebuild
// Note that Swift Binary Frameworks (XCFramework) support is only available in Swift 5.1
// or newer, and so it is only supported by recent versions of Xcode and the *OS SDKs. Likewise,
// only Apple pplatforms are supported.
// Supported platforms: ios, macos, tvos, watchos
// USAGE: command [--package-path <directory>] [--build-path <directory>] [--configuration <debug|release>] [--clean] [--no-clean] [--list-products] [--platform <ios|macos|tvos|watchos> ...] [--output <directory>] [--zip] [--zip-version <version>] [<products> ...]
// ARGUMENTS:
// <products> An optional list of products (or targets) to build. Defaults to building all `.library` products
// OPTIONS:
// --package-path <directory>
// The location of the Package (default: .)
// --build-path <directory>
// The location of the build/cache directory to use (default: .build)
// --configuration <debug|release>
// Build with a specific configuration (default: release)
// --clean/--no-clean Whether to clean before we build (default: true)
// --list-products Prints the available products and targets
// --platform <ios|macos|tvos|watchos>
// A list of platforms you want to build for. Can be specified multiple times. Default is to build for all platforms supported in your
// Package.swift, or all Apple platforms if omitted
// --output <directory> Where to place the compiled .xcframework(s) (default: .)
// --zip Whether to wrap the .xcframework(s) up in a versioned zip file ready for deployment
// --zip-version <version> The version number to append to the name of the zip file
// If the target you are packaging is a dependency, swift-create-xcframework will look into the package graph and locate the version
// number the dependency resolved to. As there is no standard way to specify the version inside your Swift Package, --zip-version lets
// you specify it manually.
// --version Show the version.
// -h, --help Show help information.