-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (51 loc) · 2.25 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
const core = require('@actions/core');
const github = require('@actions/github');
const exec = require('@actions/exec');
const package = require('./package');
const update = require('./update');
const job = require('./job');
const utils = require('./utils');
async function run() {
try {
const dateTime = (new Date()).toLocaleString('pt-BR');
const {
ref,
eventName
} = github.context;
const {
repository
} = github.context.payload;
const environment = core.getInput('ENVIRONMENT');
const path = core.getInput('PATH');
const data = JSON.parse(process.env.CUSTOMERS)
if (environment !== 'production' && environment !== 'staging') {
throw new Error('Environment input must be provided (production or staging).');
}
await exec.exec(`echo 💡 Job started at ${dateTime} - Environment: ${environment}`);
await exec.exec(`echo 🖥️ Job was automatically triggered by ${eventName} event`);
await exec.exec(`echo 🔎 The name of your branch is ${ref} and your repository is ${repository.name}.`);
await exec.exec(`echo 🐧 Installing dependencies...`);
await exec.exec('yarn install');
await exec.exec(`echo 🐧 Packaging, Validating and Updating...`);
for (const customer of data) {
await exec.exec(`echo 🐧 Creating .env and Building...`);
utils.objectToEnv(customer.environment[environment])
await exec.exec(`yarn build`);
await exec.exec(`echo 🐧 Packaging, Validating and Updating...`);
const packagePath = await package.createPackage(path)
await package.validatePackage(packagePath)
const uploadId = await update.uploadPackage(packagePath)
const jobId = await update.installPackage(uploadId)
const { app_id } = await job.getJobStatuses(jobId)
await exec.exec(`echo 🐧 Package path: ${packagePath}`);
await exec.exec(`echo 🐧 Upload ID: ${uploadId}`);
await exec.exec(`echo 🐧 Job ID: ${jobId}`);
await exec.exec(`echo 🐧 Job Status: Completed for app_id: ${app_id}`);
await exec.exec(`echo 🐧 Customer: ${customer.name} has been updated.`);
}
await exec.exec(`echo 🚀 Job has been finished`);
} catch (error) {
core.setFailed(error.message);
}
}
run()