/
change_management
executable file
·83 lines (73 loc) · 2.15 KB
/
change_management
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
#!/usr/bin/env node
const isStableRelease = require('../utils/isStableRelease')
const {GITHUB_REF_TYPE, GITHUB_REF_NAME} = process.env
if (!isStableRelease(GITHUB_REF_TYPE, GITHUB_REF_NAME)) {
console.log('Not on stable release, skipping change management trigger')
process.exit(0)
}
const REQUEST_PROMISE = require('promise-request-retry')
// Set these in Github Actions in the heroku/cli project
//
const TPS_API_APP_ID = process.env.TPS_API_APP_ID
const TPS_API_RELEASE_ACTOR_EMAIL = process.env.TPS_API_RELEASE_ACTOR_EMAIL
const TPS_API_STAGE = process.env.TPS_API_STAGE || 'production'
const TPS_API_TOKEN_PARAM = process.env.TPS_API_TOKEN_PARAM
const TPS_API_URL_PARAM = process.env.TPS_API_URL_PARAM
// This is set by GitHub Actions automagically
// https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
const RELEASE_COMMIT_SHA = process.env.GITHUB_SHA
if (TPS_API_APP_ID &&
TPS_API_RELEASE_ACTOR_EMAIL &&
TPS_API_STAGE &&
TPS_API_TOKEN_PARAM &&
TPS_API_URL_PARAM &&
RELEASE_COMMIT_SHA
) {
// continue
} else {
throw(new Error('Unset env var(s). Check CI settings.'))
}
async function sendDeployNotification () {
const actorEmail = TPS_API_RELEASE_ACTOR_EMAIL
const appId = TPS_API_APP_ID
const sha = RELEASE_COMMIT_SHA
const stage = TPS_API_STAGE
const token = TPS_API_TOKEN_PARAM
const uri = TPS_API_URL_PARAM
const body = {
release: {
actor_email: actorEmail,
app_id: appId,
component_name: 'cli',
description: `Deploy ${sha} of heroku/cli in ${stage}`,
sha,
stage
}
}
try {
// Retry up to 6 (~2m) doubling the delay each time
//
const options = {
method: 'POST',
headers: {
Authorization: `Token ${token}`,
ACCEPT: 'application/json',
'Content-Type': 'application/json'
},
uri,
body,
accepted: [401, 403, 404],
retry: 6,
delay: 1000,
factor: 2,
json: true
}
const resp = await REQUEST_PROMISE(options)
console.log(resp)
} catch (error) {
console.log(error)
console.log(body)
process.exit(1)
}
}
sendDeployNotification()