-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
71 lines (60 loc) · 1.87 KB
/
index.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
import * as core from '@actions/core';
import {Docker} from 'docker-cli-js';
import * as fs from 'fs';
import {map} from 'lodash-es';
import {AppJson} from './lib/heroku';
import Heroku = require('heroku-client');
export interface FormationDyno {
size?: string;
quantity?: number;
type: string;
docker_image: string;
}
async function getImageId(docker: Docker, tag: string) {
const data = await docker.command(`inspect ${tag}`);
return data.object[0].Id as string;
}
async function run() {
const herokuApiToken = core.getInput('heroku_api_token');
const appName = core.getInput('app');
const appJsonPath = core.getInput('app_json');
const imageRepository = core.getInput('image_repo');
const imageTag = core.getInput('image_tag');
const webOnly = core.getInput('web_only') === 'true';
const heroku = new Heroku({token: herokuApiToken});
const docker = new Docker({echo: false});
const appJson: AppJson = JSON.parse(fs.readFileSync(appJsonPath).toString());
const dynos: FormationDyno[] = await Promise.all(map(appJson.formation, async(dynoDef, type) => {
return {
type,
...dynoDef,
docker_image: await getImageId(docker, `${imageRepository}/${type}:${imageTag}`),
};
}));
if (!webOnly) {
dynos.push({
type: 'release',
quantity: undefined,
docker_image: await getImageId(docker, `${imageRepository}/release:${imageTag}`),
size: undefined,
});
}
console.log('Updating formation...', dynos);
const formation = {
updates: dynos,
};
const response = await heroku.patch(
`/apps/${appName}/formation`,
{body: formation, headers: {Accept: 'application/vnd.heroku+json; version=3.docker-releases'}},
);
console.log('Updated formation.');
}
try {
run().catch((e) => {
console.error(e);
core.setFailed(e.message);
});
} catch (e) {
console.error(e);
core.setFailed(e.message);
}