@@ -52,25 +52,21 @@ const github = __importStar(__webpack_require__(95438));
52
52
const netlify_1 = __importDefault(__webpack_require__(44666));
53
53
const path = __importStar(__webpack_require__(85622));
54
54
const util_1 = __webpack_require__(64024);
55
- const dryRunDeploy = {
56
- name: 'dry-run',
57
- deploy_ssl_url: 'http://example.com',
58
- ssl_url: 'http://example.com',
59
- };
60
55
function run() {
61
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l ;
56
+ var _a, _b, _c, _d, _e, _f, _g;
62
57
return __awaiter(this, void 0, void 0, function* () {
63
58
try {
64
59
const isCommit = Object.keys(github.context.payload).includes('head_commit');
65
60
const isPullRequest = Object.keys(github.context.payload).includes('pull_request');
66
61
const isRelease = Object.keys(github.context.payload).includes('release');
67
- const commitSha = github.context.sha;
68
- const commitShaShort = github.context.sha.slice(0, 7);
69
- const commitMessage = isCommit ? (_b = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.head_commit) === null || _b === void 0 ? void 0 : _b.message : undefined;
70
- const pullRequestNumber = (_c = github.context.payload.pull_request) === null || _c === void 0 ? void 0 : _c.number;
71
- const pullRequestTitle = isPullRequest ? (_e = (_d = github.context.payload) === null || _d === void 0 ? void 0 : _d.pull_request) === null || _e === void 0 ? void 0 : _e.title : undefined;
72
- const releaseTag = isRelease ? (_g = (_f = github.context.payload) === null || _f === void 0 ? void 0 : _f.release) === null || _g === void 0 ? void 0 : _g.tag_name : undefined;
73
- const releaseTitle = isRelease ? (_j = (_h = github.context.payload) === null || _h === void 0 ? void 0 : _h.release) === null || _j === void 0 ? void 0 : _j.name : undefined;
62
+ const { payload, sha, issue: { number }, repo: { owner, repo }, } = github.context;
63
+ const shaShort = sha.slice(0, 7);
64
+ const deploymentSha = (_b = (_a = payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.sha) !== null && _b !== void 0 ? _b : sha;
65
+ const commitMessage = isCommit ? (_c = payload.head_commit) === null || _c === void 0 ? void 0 : _c.message : undefined;
66
+ const pullRequestNumber = (_d = payload.pull_request) === null || _d === void 0 ? void 0 : _d.number;
67
+ const pullRequestTitle = isPullRequest ? (_e = payload.pull_request) === null || _e === void 0 ? void 0 : _e.title : undefined;
68
+ const releaseTag = isRelease ? (_f = payload.release) === null || _f === void 0 ? void 0 : _f.tag_name : undefined;
69
+ const releaseTitle = isRelease ? (_g = payload.release) === null || _g === void 0 ? void 0 : _g.name : undefined;
74
70
// Get required inputs
75
71
const githubToken = core.getInput('github-token', { required: true });
76
72
const netlifyAuthToken = core.getInput('netlify-auth-token', { required: true });
@@ -79,22 +75,28 @@ function run() {
79
75
// Get config inputs
80
76
const commentOnCommit = core.getInput('comment-on-commit') === 'true';
81
77
const commentOnPullRequest = core.getInput('comment-on-pull-request') === 'true';
82
- const githubEnv = core.getInput('github-env') || undefined;
83
- const githubEnvReportStatus = core.getInput('github-env-report-status') === 'true';
78
+ const githubDeployEnvironment = core.getInput('github-deployment-environment') || undefined;
79
+ const githubDeployDescription = core.getInput('github-deployment-description') || undefined;
80
+ const githubDeployIsTransient = core.getInput('github-deployment-is-transient') === 'true';
81
+ const githubDeployIsProduction = core.getInput('github-deployment-is-production') === 'true';
82
+ const githubDeployReportStatus = core.getInput('github-deployment-should-report-status') === 'true';
84
83
const dryRun = core.getInput('dry-run') === 'true';
85
84
// Get optional inputs
86
85
const configPath = core.getInput('config-path') || undefined;
87
86
const draft = core.getInput('draft') === 'true';
88
87
const functionsDir = core.getInput('functions-dir') || undefined;
89
88
let message = core.getInput('message');
89
+ // Create clients
90
+ const githubClient = github.getOctokit(githubToken);
91
+ const netlifyClient = new netlify_1.default(netlifyAuthToken);
90
92
// If there's no explict deploy message input, then make a deploy message from the action's context.
91
93
if (!message) {
92
- message = `Build [${commitShaShort }]`;
94
+ message = `Build [${shaShort }]`;
93
95
if (isCommit) {
94
- message = `Commit: ${commitMessage} [${commitShaShort }]`;
96
+ message = `Commit: ${commitMessage} [${shaShort }]`;
95
97
}
96
98
if (isPullRequest) {
97
- message = `PR: ${pullRequestTitle} [${commitShaShort }]`;
99
+ message = `PR: ${pullRequestTitle} [${shaShort }]`;
98
100
}
99
101
if (isRelease) {
100
102
message = `Release: ${releaseTitle} [${releaseTag}]`;
@@ -104,7 +106,6 @@ function run() {
104
106
process.stdout.write(`Action is running dry - there won't be any outputs from this run.\n`);
105
107
}
106
108
process.stdout.write(`Deploying ${draft ? 'draft ' : ''}to Netlify...\n`);
107
- const netlifyClient = new netlify_1.default(netlifyAuthToken);
108
109
let deploy;
109
110
if (!dryRun) {
110
111
try {
@@ -126,11 +127,15 @@ function run() {
126
127
else {
127
128
process.stdout.write(`[Dry run] Netlify deploy message: "${message}"\n`);
128
129
}
129
- const githubClient = github.getOctokit(githubToken);
130
- const body = util_1.createCommentMessage(draft, dryRun ? dryRunDeploy : deploy);
130
+ const body = dryRun
131
+ ? util_1.createCommentMessage(draft, {
132
+ name: 'dry-run',
133
+ deploy_ssl_url: 'http://example.com',
134
+ ssl_url: 'http://example.com',
135
+ })
136
+ : util_1.createCommentMessage(draft, deploy);
131
137
if (isCommit && commentOnCommit) {
132
- process.stdout.write(`Commenting on commit ${commitShaShort} (SHA: ${commitSha})\n`);
133
- const { repo: { owner, repo }, sha, } = github.context;
138
+ process.stdout.write(`Commenting on commit ${shaShort} (SHA: ${sha})\n`);
134
139
if (!dryRun) {
135
140
try {
136
141
yield githubClient.repos.createCommitComment({
@@ -147,12 +152,11 @@ function run() {
147
152
}
148
153
}
149
154
else {
150
- process.stdout.write(`[Dry run] Github commit comment: "${body}"\n`);
155
+ process.stdout.write(`[Dry run] GitHub commit comment: "${body}"\n`);
151
156
}
152
157
}
153
158
if (isPullRequest && commentOnPullRequest) {
154
159
process.stdout.write(`Commenting on pull request #${pullRequestNumber}\n`);
155
- const { repo: { owner, repo }, issue: { number }, } = github.context;
156
160
if (!dryRun) {
157
161
try {
158
162
yield githubClient.issues.createComment({
@@ -169,28 +173,29 @@ function run() {
169
173
}
170
174
}
171
175
else {
172
- process.stdout.write(`[Dry run] Github pull request comment: "${body}"\n`);
176
+ process.stdout.write(`[Dry run] GitHub pull request comment: "${body}"\n`);
173
177
}
174
178
}
175
- const envSha = (_l = (_k = github.context.payload.pull_request) === null || _k === void 0 ? void 0 : _k.head.sha) !== null && _l !== void 0 ? _l : commitSha;
176
- if (githubEnv) {
179
+ if (githubDeployEnvironment) {
177
180
if (!dryRun) {
178
- process.stdout.write(`Creating deployment for "${githubEnv}"\n`);
179
- const { repo: { owner, repo }, } = github.context;
181
+ process.stdout.write(`Creating deployment for "${githubDeployEnvironment}"\n`);
180
182
try {
181
183
const deployment = yield githubClient.repos.createDeployment({
182
- ref: envSha,
183
184
owner,
184
185
repo,
185
- environment: githubEnv ,
186
+ ref: deploymentSha ,
186
187
auto_merge: false,
187
188
required_contexts: [],
189
+ environment: githubDeployEnvironment,
190
+ description: githubDeployDescription,
191
+ transient_environment: githubDeployIsTransient,
192
+ production_environment: githubDeployIsProduction,
188
193
});
189
194
yield githubClient.repos.createDeploymentStatus({
190
195
owner,
191
196
repo,
192
- state: 'success',
193
197
deployment_id: deployment.data.id,
198
+ state: 'success',
194
199
environment_url: util_1.getDeployUrl(draft, deploy),
195
200
});
196
201
}
@@ -201,32 +206,31 @@ function run() {
201
206
}
202
207
}
203
208
else {
204
- process.stdout.write(`[Dry run] Github deployment env: "${githubEnv }"\n`);
209
+ process.stdout.write(`[Dry run] GitHub deployment env: "${githubDeployEnvironment }"\n`);
205
210
}
206
211
if (!dryRun) {
207
- if (githubEnvReportStatus) {
208
- process.stdout.write(`Creating commit status for SHA: "${envSha}"\n`);
209
- const { repo: { owner, repo }, } = github.context;
212
+ if (githubDeployReportStatus) {
213
+ process.stdout.write(`Creating commit status for SHA: "${deploymentSha}"\n`);
210
214
try {
211
215
yield githubClient.repos.createCommitStatus({
212
- sha: envSha ,
216
+ sha: deploymentSha ,
213
217
owner,
214
218
repo,
215
219
state: 'success',
216
220
context: 'action-netlify-deploy',
217
221
target_url: util_1.getDeployUrl(draft, deploy),
218
- description: 'Netlify deployment status',
222
+ description: 'action-netlify-deploy status',
219
223
});
220
224
}
221
225
catch (error) {
222
- process.stderr.write('creating deployment failed\n');
226
+ process.stderr.write('creating commit status failed\n');
223
227
process.stderr.write(`${JSON.stringify(error, null, 2)}\n`);
224
228
core.setFailed(error.message);
225
229
}
226
230
}
227
231
}
228
232
else {
229
- process.stdout.write(`[Dry run] Github status on commit: "${envSha }"\n`);
233
+ process.stdout.write(`[Dry run] GitHub commit status "success" on "${deploymentSha }"\n`);
230
234
}
231
235
}
232
236
}
0 commit comments