-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.js
150 lines (119 loc) · 4.7 KB
/
index.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
147
148
149
150
// MIT License - Copyright (c) 2020 Stefan Arentz <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
const fs = require('fs');
const core = require('@actions/core');
const execa = require('execa');
const parseConfiguration = () => {
const configuration = {
productPath: core.getInput("product-path", {required: true}),
username: core.getInput("appstore-connect-username", {required: true}),
teamid: core.getInput("appstore-connect-teamid", {required: true}),
password: core.getInput("appstore-connect-password", {required: true}),
verbose: core.getInput("verbose") === "true",
};
if (!fs.existsSync(configuration.productPath)) {
throw Error(`Product path ${configuration.productPath} does not exist.`);
}
return configuration
};
const archive = async ({productPath}) => {
const archivePath = "/tmp/archive.zip"; // TODO Temporary file
const args = [
"-c", // Create an archive at the destination path
"-k", // Create a PKZip archive
"--keepParent", // Embed the parent directory name src in dst_archive.
productPath, // Source
archivePath, // Destination
];
try {
await execa("ditto", args);
} catch (error) {
core.error(error);
return null;
}
return archivePath;
};
const submit = async ({archivePath, username, teamid, password, verbose}) => {
//
// Run notarytool to notarize this application. This only submits the
// application to the queue on Apple's server side. It does not
// actually tell us if the notarization was succesdful or not, for
// that we need to poll using the request UUID that is returned.
//
const args = [
"notarytool",
"submit",
"--wait",
"--apple-id", username,
"--team-id", teamid,
"--password", password,
archivePath
];
if (verbose === true) {
args.push("--verbose");
}
let xcrun = execa("xcrun", args, {reject: false});
xcrun.stdout.pipe(process.stdout);
xcrun.stderr.pipe(process.stderr);
const {exitCode, stdout, stderr} = await xcrun;
if (exitCode === undefined) {
// TODO Command did not run at all
throw Error("Unknown failure - notarytool did not run at all?");
}
if (exitCode !== 0) {
const response = JSON.parse(stdout);
if (verbose === true) {
console.log("STDERR", stderr);
console.log(response);
}
for (const productError of response["product-errors"]) {
core.error(`${productError.code} - ${productError.message}`);
}
return false;
}
return true;
};
const main = async () => {
try {
const configuration = parseConfiguration();
const archivePath = await core.group('Archiving Application', async () => {
const archivePath = await archive(configuration)
if (archivePath !== null) {
core.info(`Created application archive at ${archivePath}`);
}
return archivePath;
});
if (archivePath == null) {
core.setFailed("Notarization failed");
return;
}
const success = await core.group('Waiting for Notarization Status', async () => {
return await submit({archivePath: archivePath, ...configuration})
});
if (success == false) {
core.setFailed("Notarization failed");
return;
}
core.setOutput('product-path', configuration.productPath);
} catch (error) {
core.setFailed(`Notarization failed with an unexpected error: ${error.message}`);
}
};
main();