@@ -3542,7 +3542,7 @@ function getInput(name, options) {
3542
3542
return result;
3543
3543
}
3544
3544
function run() {
3545
- var _a, _b, _c, _d, _e, _f, _g;
3545
+ var _a, _b, _c, _d, _e, _f, _g, _h ;
3546
3546
return __awaiter(this, void 0, void 0, function* () {
3547
3547
let token;
3548
3548
let type;
@@ -3552,6 +3552,7 @@ function run() {
3552
3552
let environment;
3553
3553
let environmentUrl;
3554
3554
let deploymentId;
3555
+ let mainBranch;
3555
3556
const { actor, ref } = github.context;
3556
3557
console.log('### context ###');
3557
3558
console.log(`actor: ${actor}`);
@@ -3573,8 +3574,10 @@ function run() {
3573
3574
console.log(`environment: ${environment}`);
3574
3575
environmentUrl = (_f = getInput('environment_url')) !== null && _f !== void 0 ? _f : '';
3575
3576
console.log(`environmentUrl: ${environmentUrl}`);
3577
+ mainBranch = (_g = getInput('main_branch')) !== null && _g !== void 0 ? _g : 'master';
3578
+ console.log(`main branch: ${mainBranch}`);
3576
3579
const shouldRequireDeploymentId = type === 'finish' || type === 'delete';
3577
- deploymentId = (_g = getInput('deployment_id', { required: shouldRequireDeploymentId })) !== null && _g !== void 0 ? _g : '0';
3580
+ deploymentId = (_h = getInput('deployment_id', { required: shouldRequireDeploymentId })) !== null && _h !== void 0 ? _h : '0';
3578
3581
console.log(`deploymentId: ${deploymentId}`);
3579
3582
}
3580
3583
catch (error) {
@@ -3588,7 +3591,7 @@ function run() {
3588
3591
switch (type) {
3589
3592
case 'create':
3590
3593
try {
3591
- deploymentId = yield create_1.create(client, logsUrl, description, status, environment, environmentUrl);
3594
+ deploymentId = yield create_1.create(client, logsUrl, description, status, environment, environmentUrl, mainBranch );
3592
3595
console.log(`setOutput::deployment_id: ${deploymentId}`);
3593
3596
core.setOutput('deployment_id', deploymentId);
3594
3597
}
@@ -8670,10 +8673,28 @@ function invalidatePreviousDeployments(client, environment) {
8670
8673
})));
8671
8674
});
8672
8675
}
8673
- function create(client, logUrl, description, initialStatus, environment, environmentUrl) {
8676
+ function getMainSha(client, branch) {
8677
+ return __awaiter(this, void 0, void 0, function* () {
8678
+ try {
8679
+ const response = yield client.repos.getBranch(Object.assign(Object.assign({}, github_1.context.repo), { branch }));
8680
+ const sha = response.data.commit.sha;
8681
+ console.log(`${branch} branch sha: ${sha}`);
8682
+ return sha;
8683
+ }
8684
+ catch (error) {
8685
+ console.error(error.message);
8686
+ return `no_${branch}`;
8687
+ }
8688
+ });
8689
+ }
8690
+ function create(client, logUrl, description, initialStatus, environment, environmentUrl, mainBranch) {
8674
8691
return __awaiter(this, void 0, void 0, function* () {
8675
8692
yield invalidatePreviousDeployments(client, environment);
8676
- const deployment = yield client.repos.createDeployment(Object.assign(Object.assign({}, github_1.context.repo), { ref: github_1.context.ref, required_contexts: [], environment, transient_environment: true, auto_merge: false, description, payload: JSON.stringify({ actor: github_1.context.actor }) }));
8693
+ // get main branch sha to store in payload
8694
+ const mainBranchSha = yield getMainSha(client, mainBranch);
8695
+ const payload = JSON.stringify({ actor: github_1.context.actor, main_sha: mainBranchSha });
8696
+ const deployment = yield client.repos.createDeployment(Object.assign(Object.assign({}, github_1.context.repo), { ref: github_1.context.ref, required_contexts: [], environment, transient_environment: true, auto_merge: false, description,
8697
+ payload }));
8677
8698
console.log(`created deployment: ${JSON.stringify(deployment.data, null, 2)}`);
8678
8699
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 }));
8679
8700
console.log(`created deployment status: ${JSON.stringify(status.data, null, 2)}`);
0 commit comments