Skip to content

Commit 092b792

Browse files
committed
feat: implement finish and tests
1 parent 7d11768 commit 092b792

File tree

8 files changed

+392
-80
lines changed

8 files changed

+392
-80
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v1
2121
- uses: ./
22+
id: create
2223
with:
2324
token: ${{github.token}}
2425
type: create
26+
- uses: ./
27+
with:
28+
token: ${{github.token}}
29+
type: finish
30+
deployment_id: ${{steps.create.outputs.deployment_id}}

dist/index.js

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,9 +3525,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
35253525
});
35263526
};
35273527
Object.defineProperty(exports, "__esModule", { value: true });
3528+
exports.run = void 0;
35283529
const core = __importStar(__webpack_require__(470));
35293530
const github = __importStar(__webpack_require__(469));
35303531
const create_1 = __webpack_require__(646);
3532+
const finish_1 = __webpack_require__(209);
35313533
// nullify getInput empty results
35323534
// to allow coalescence ?? operator
35333535
function getInput(name, options) {
@@ -3544,7 +3546,7 @@ function run() {
35443546
let type;
35453547
let logsUrl;
35463548
let description;
3547-
let initialStatus;
3549+
let status;
35483550
let environment;
35493551
let environmentUrl;
35503552
let deploymentId;
@@ -3561,15 +3563,16 @@ function run() {
35613563
console.log(`logs: ${logsUrl}`);
35623564
description = (_c = getInput('description')) !== null && _c !== void 0 ? _c : `deployed by ${actor}`;
35633565
console.log(`description: ${description}`);
3564-
initialStatus = ((_d = getInput('initial_status')) !== null && _d !== void 0 ? _d : 'in_progress');
3565-
console.log(`initialStatus: ${initialStatus}`);
3566+
status = ((_d = getInput('status')) !== null && _d !== void 0 ? _d : 'in_progress');
3567+
console.log(`status: ${status}`);
35663568
// default to branch name w/o `deploy-` prefix
35673569
environment = (_e = getInput('environment')) !== null && _e !== void 0 ? _e : ref.replace('refs/heads/', '').replace(/^deploy-/, '');
35683570
console.log(`environment: ${environment}`);
35693571
environmentUrl = (_f = getInput('environment_url')) !== null && _f !== void 0 ? _f : '';
35703572
console.log(`environmentUrl: ${environmentUrl}`);
3571-
const shouldRequireDeploymentId = type === 'status' || type === 'delete';
3573+
const shouldRequireDeploymentId = type === 'finish' || type === 'delete';
35723574
deploymentId = (_g = getInput('deployment_id', { required: shouldRequireDeploymentId })) !== null && _g !== void 0 ? _g : '0';
3575+
console.log(`deploymentId: ${deploymentId}`);
35733576
}
35743577
catch (error) {
35753578
core.error(error);
@@ -3579,19 +3582,64 @@ function run() {
35793582
const client = new github.GitHub(token, { previews: ['ant-man', 'flash'] });
35803583
switch (type) {
35813584
case 'create':
3582-
deploymentId = yield create_1.create(client, logsUrl, description, initialStatus, environment, environmentUrl);
3583-
core.setOutput('deployment_id', deploymentId);
3585+
try {
3586+
deploymentId = yield create_1.create(client, logsUrl, description, status, environment, environmentUrl);
3587+
core.setOutput('deployment_id', deploymentId);
3588+
}
3589+
catch (error) {
3590+
core.error(error);
3591+
// core.setFailed(error)
3592+
throw error;
3593+
}
3594+
break;
3595+
case 'finish':
3596+
try {
3597+
yield finish_1.finish(client, deploymentId, status, logsUrl, environmentUrl);
3598+
}
3599+
catch (error) {
3600+
core.error(error);
3601+
// core.setFailed(`Could not finish a deployment: ${JSON.stringify(error, null, 2)}`)
3602+
throw error;
3603+
}
35843604
break;
35853605
case 'delete':
35863606
break;
35873607
case 'delete-all':
35883608
break;
3589-
case 'status':
3590-
break;
35913609
}
35923610
});
35933611
}
3594-
run(); // eslint-disable-line @typescript-eslint/no-floating-promises
3612+
exports.run = run;
3613+
if (process.env.NODE_ENV !== 'test')
3614+
run(); // eslint-disable-line @typescript-eslint/no-floating-promises
3615+
3616+
3617+
/***/ }),
3618+
3619+
/***/ 209:
3620+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
3621+
3622+
"use strict";
3623+
3624+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3625+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3626+
return new (P || (P = Promise))(function (resolve, reject) {
3627+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3628+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3629+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3630+
step((generator = generator.apply(thisArg, _arguments || [])).next());
3631+
});
3632+
};
3633+
Object.defineProperty(exports, "__esModule", { value: true });
3634+
exports.finish = void 0;
3635+
const github_1 = __webpack_require__(469);
3636+
function finish(client, deploymentId, status, logUrl, environmentUrl) {
3637+
return __awaiter(this, void 0, void 0, function* () {
3638+
const statusResult = yield client.repos.createDeploymentStatus(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: Number(deploymentId), state: status, log_url: logUrl, environment_url: environmentUrl }));
3639+
console.log(`created deployment status: ${JSON.stringify(statusResult.data, null, 2)}`);
3640+
});
3641+
}
3642+
exports.finish = finish;
35953643

35963644

35973645
/***/ }),
@@ -8539,25 +8587,6 @@ module.exports = require("net");
85398587

85408588
"use strict";
85418589

8542-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8543-
if (k2 === undefined) k2 = k;
8544-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8545-
}) : (function(o, m, k, k2) {
8546-
if (k2 === undefined) k2 = k;
8547-
o[k2] = m[k];
8548-
}));
8549-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
8550-
Object.defineProperty(o, "default", { enumerable: true, value: v });
8551-
}) : function(o, v) {
8552-
o["default"] = v;
8553-
});
8554-
var __importStar = (this && this.__importStar) || function (mod) {
8555-
if (mod && mod.__esModule) return mod;
8556-
var result = {};
8557-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
8558-
__setModuleDefault(result, mod);
8559-
return result;
8560-
};
85618590
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
85628591
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
85638592
return new (P || (P = Promise))(function (resolve, reject) {
@@ -8570,7 +8599,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
85708599
Object.defineProperty(exports, "__esModule", { value: true });
85718600
exports.create = void 0;
85728601
const github_1 = __webpack_require__(469);
8573-
const core = __importStar(__webpack_require__(470));
85748602
function invalidatePreviousDeployments(client, environment) {
85758603
return __awaiter(this, void 0, void 0, function* () {
85768604
const deployments = yield client.repos.listDeployments(Object.assign(Object.assign({}, github_1.context.repo), { ref: github_1.context.ref, environment }));
@@ -8593,7 +8621,6 @@ function create(client, logUrl, description, initialStatus, environment, environ
85938621
console.log(`created deployment: ${JSON.stringify(deployment.data, null, 2)}`);
85948622
const status = yield client.repos.createDeploymentStatus(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: deployment.data.id, state: initialStatus, log_url: logUrl, environment_url: environmentUrl }));
85958623
console.log(`created deployment status: ${JSON.stringify(status.data, null, 2)}`);
8596-
core.setOutput('deployment_id', deployment.data.id.toString());
85978624
return deployment.data.id.toString();
85988625
});
85998626
}

0 commit comments

Comments
 (0)