commit 73529570754a1fa4fdd5e679424d6758066a683f Author: Semih Kaiser Date: Sat Apr 25 00:28:34 2026 +0200 Init diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ec3e5ab --- /dev/null +++ b/action.yml @@ -0,0 +1,20 @@ +name: "Signed Webhook Sender" +description: "Send a JSON webhook signed with HMAC SHA-256" +author: "Oryfox" + +inputs: + url: + description: "Webhook endpoint URL" + required: true + + secret: + description: "HMAC secret" + required: true + + payload: + description: "JSON payload string" + required: true + +runs: + using: "node24" + main: "index.js" \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9272d38 --- /dev/null +++ b/index.js @@ -0,0 +1,61 @@ +const crypto = require("crypto"); +const https = require("https"); + +function createSignature(payload, secret) { + return crypto + .createHmac("sha256", secret) + .update(payload) + .digest("hex"); +} + +async function sendRequest(url, payload, signature) { + const parsedUrl = new URL(url); + + const options = { + hostname: parsedUrl.hostname, + path: parsedUrl.pathname + parsedUrl.search, + method: "POST", + headers: { + "Content-Type": "application/json", + "Content-Length": Buffer.byteLength(payload), + "X-Signature": signature + } + }; + + return new Promise((resolve, reject) => { + const req = https.request(options, (res) => { + let data = ""; + + res.on("data", (chunk) => (data += chunk)); + res.on("end", () => { + console.log("Status:", res.statusCode); + console.log("Response:", data); + resolve(); + }); + }); + + req.on("error", reject); + req.write(payload); + req.end(); + }); +} + +async function run() { + try { + const url = process.env.INPUT_URL; + const secret = process.env.INPUT_SECRET; + const payload = process.env.INPUT_PAYLOAD + + const signature = createSignature(payload, secret); + + console.log("Sending webhook..."); + await sendRequest(url, payload, signature); + + console.log("Done."); + } catch (err) { + console.error("Action failed:", err); + process.exit(1); + } +} + +run(); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d70ef09 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "name": "signed-webhook-action", + "version": "1.0.0", + "main": "index.js", + "dependencies": {} +} \ No newline at end of file