Skip to content

Commit

Permalink
add deployment secret
Browse files Browse the repository at this point in the history
  • Loading branch information
HoloPanio committed Jun 21, 2021
1 parent edddb0f commit 08e1d4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
deployment-url:
description: "The URL that the payload is deployed to."
required: true
deployment-secret:
description: "The the secret used to authenticate the deployment."
required: true

runs:
using: "node12"
Expand Down
15 changes: 10 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ var github = __importStar(__nccwpck_require__(5438));
var axios_1 = __importDefault(__nccwpck_require__(6545));
function run() {
return __awaiter(this, void 0, void 0, function () {
var token, configPath, deploymentUrl, client, config, envName, branch, containers, payload, err_1;
var token, configPath, deploymentUrl, deploymentSecret, client, config, envName, branch, containers, payload, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
token = core.getInput('repo-token', { required: true });
configPath = core.getInput('config', { required: true });
deploymentUrl = core.getInput('deployment-url', { required: true });
deploymentSecret = core.getInput('deployment-secret', { required: true });
client = github.getOctokit(token);
return [4 /*yield*/, getConfig(client, configPath)];
case 1:
Expand All @@ -100,14 +101,14 @@ function run() {
key: ev.name,
value: secret
};
})
}) // NO SEMICOLON EVEN IF YOU WANT TO, ITS NOT A CALLBACK, ITS AN OBJECT
};
});
console.log("Compiling Payload...");
payload = createPayload(client, branch, envName, containers);
console.log("Payload Compiled!");
console.log("Deploying...");
sendPayload(client, deploymentUrl, payload).then(function (res) {
sendPayload(client, deploymentUrl, deploymentSecret, payload).then(function (res) {
console.log("Deployed");
}).catch(function (err) { throw err; });
return [3 /*break*/, 3];
Expand Down Expand Up @@ -142,10 +143,14 @@ function getConfig(client, path) {
});
});
}
function sendPayload(github, url, payload) {
function sendPayload(github, url, secret, payload) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, axios_1.default.post(url, payload)
return [2 /*return*/, axios_1.default.post(url, payload, {
headers: {
"Authorization": secret
}
})
.then(function (res) { return res.data; })];
});
});
Expand Down
12 changes: 9 additions & 3 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function run() {
const token = core.getInput('repo-token', { required: true });
const configPath = core.getInput('config', { required: true });
const deploymentUrl = core.getInput('deployment-url', { required: true });
const deploymentSecret = core.getInput('deployment-secret', { required: true });

const client = github.getOctokit(token);
const config = await getConfig(client, configPath);
Expand All @@ -31,7 +32,7 @@ export async function run() {
key: ev.name,
value: secret
}
})
}) // NO SEMICOLON EVEN IF YOU WANT TO, ITS NOT A CALLBACK, ITS AN OBJECT
};
});

Expand All @@ -40,7 +41,7 @@ export async function run() {
console.log("Payload Compiled!");

console.log("Deploying...");
sendPayload(client, deploymentUrl, payload).then(res => {
sendPayload(client, deploymentUrl, deploymentSecret, payload).then(res => {
console.log("Deployed");
}).catch(err => {throw err})

Expand Down Expand Up @@ -74,9 +75,14 @@ function getConfig(client: InstanceType<typeof GitHub>, path: string): Promise<C
async function sendPayload(
github: InstanceType<typeof GitHub>,
url: string,
secret: string,
payload: DeploymentPayload
): Promise<any> {
return axios.post(url, payload)
return axios.post(url, payload, {
headers: {
"Authorization": secret
}
})
.then(res => res.data)
}

Expand Down

0 comments on commit 08e1d4f

Please sign in to comment.