-
Notifications
You must be signed in to change notification settings - Fork 56
/
google-play-promote.ts
73 lines (61 loc) · 3.29 KB
/
google-play-promote.ts
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
import * as path from 'path';
import * as tl from 'azure-pipelines-task-lib/task';
import * as googleutil from './googleutil';
async function run() {
try {
tl.setResourcePath(path.join( __dirname, 'task.json'));
const authType: string = tl.getInput('authType', true);
let key: googleutil.ClientKey = {};
if (authType === 'JsonFile') {
const serviceAccountKeyFile: string = tl.getPathInput('serviceAccountKey', false);
if (!serviceAccountKeyFile) {
throw new Error(tl.loc('JsonKeyFileNotFound'));
}
const stats: tl.FsStats = tl.stats(serviceAccountKeyFile);
if (stats && stats.isFile()) {
key = require(serviceAccountKeyFile);
} else {
console.error(tl.loc('InvalidAuthFile'));
throw new Error(tl.loc('InvalidAuthFilewithName', serviceAccountKeyFile));
}
} else if (authType === 'ServiceEndpoint') {
const serviceEndpoint: tl.EndpointAuthorization = tl.getEndpointAuthorization(tl.getInput('serviceEndpoint', true), true);
if (!serviceEndpoint) {
throw new Error(tl.loc('EndpointNotFound'));
}
key.client_email = serviceEndpoint.parameters['username'];
key.private_key = serviceEndpoint.parameters['password'].replace(/\\n/g, '\n');
}
const packageName: string = tl.getPathInput('packageName', true);
const sourceTrack: string = tl.getInput('sourceTrack', true);
const destinationTrack: string = tl.getInput('destinationTrack', true);
const userFractionSupplied: boolean = tl.getBoolInput('rolloutToUserFraction');
const userFraction: number = Number(userFractionSupplied ? tl.getInput('userFraction', false) : 1.0);
// Constants
const globalParams: googleutil.GlobalParams = { auth: null, params: {} };
const jwtClient = googleutil.getJWT(key);
const edits: any = googleutil.publisher.edits;
globalParams.auth = jwtClient;
googleutil.updateGlobalParams(globalParams, 'packageName', packageName);
console.log(tl.loc('Authenticating'));
await jwtClient.authorize();
await googleutil.getNewEdit(edits, globalParams, packageName);
console.log(tl.loc('GetTrackInfo', sourceTrack));
let track = await googleutil.getTrack(edits, packageName, sourceTrack);
tl.debug(`Current track: ${JSON.stringify(track)}`);
console.log(tl.loc('PromoteTrack', destinationTrack));
track = await googleutil.updateTrack(edits, packageName, destinationTrack, track.releases[0].versionCodes, userFraction, track.releases[0].releaseNotes);
tl.debug(`Update track: ${JSON.stringify(track)}`);
console.log(tl.loc('CleanTrack', sourceTrack));
track = await googleutil.updateTrack(edits, packageName, sourceTrack, [], userFraction);
tl.debug(`Update clean track: ${JSON.stringify(track)}`);
await edits.commit();
console.log(tl.loc('PromoteSucceed'));
console.log(tl.loc('SourceTrack', sourceTrack));
console.log(tl.loc('DestTrack', destinationTrack));
tl.setResult(tl.TaskResult.Succeeded, tl.loc('Success'));
} catch (err) {
tl.setResult(tl.TaskResult.Failed, err);
}
}
run();