Created
March 25, 2024 07:46
-
-
Save uurtech/62ebd60f88c2ee1c9aed0a3be782145c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const { spawn } = require('child_process'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
const port = 3000; | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/deploy', (req, res) => { | |
// Extract necessary information from Slack command request | |
const { text } = req.body; | |
// Trigger GitHub Actions workflow | |
const deployWorkflow = spawn('curl', [ | |
'-X', 'POST', | |
'-H', 'Authorization: token YOUR_GITHUB_TOKEN', | |
'-H', 'Accept: application/vnd.github.v3+json', | |
'https://api.github.com/repos/your_username/your_repo/actions/workflows/your_workflow_dispatch.yml/dispatches', | |
'-d', `{"ref":"${text}"}`, | |
]); | |
deployWorkflow.stdout.on('data', (data) => { | |
console.log(`GitHub Actions workflow trigger response: ${data}`); | |
// Respond to Slack indicating the deployment process has started | |
res.send('Deployment process has started...'); | |
}); | |
deployWorkflow.stderr.on('data', (data) => { | |
console.error(`Error triggering GitHub Actions workflow: ${data}`); | |
// Respond to Slack if there was an error | |
res.status(500).send('Error triggering deployment'); | |
}); | |
}); | |
app.listen(port, () => { | |
console.log(`Webhook receiver listening at http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment