|
1 | 1 | import { Application } from 'probot' // eslint-disable-line no-unused-vars |
2 | 2 | import { CommentParser, LinkEntry } from './CommentParser' |
3 | 3 | import { SnippetResolver } from './SnippetResolver' |
4 | | -import express from 'express' |
| 4 | +import { execSync } from 'child_process' |
5 | 5 |
|
6 | 6 | export = (app: Application) => { |
7 | 7 | const parser = new CommentParser; |
@@ -111,11 +111,32 @@ ${snippet.results.results.length ? snippet.results.results.map(issue => `${issue |
111 | 111 | } |
112 | 112 | }); |
113 | 113 |
|
114 | | - const router = app.route(); |
115 | | - router.use(express.json()); |
| 114 | + if (process.env.DEPLOYMENTS_ENABLED) { |
| 115 | + app.on('release.published', async(context) => { |
| 116 | + if (context.payload.repository.full_name !== process.env.DEPLOYMENTS_REPO) { |
| 117 | + return; |
| 118 | + } |
| 119 | + if (context.payload.release.prerelease && (process.env.DEPLOYMENTS_ENABLED !== 'all')) { |
| 120 | + return; |
| 121 | + } |
| 122 | + const release = context.payload.release; |
116 | 123 |
|
117 | | - app.route().post('/deploy', (req, res) => { |
118 | | - app.log(req.body); |
119 | | - res.sendStatus(200); |
120 | | - }); |
| 124 | + const commands = [ |
| 125 | + 'git fetch origin', |
| 126 | + `git checkout "${release.tag_name}"`, |
| 127 | + `git reset --hard "${release.tag_name}"`, |
| 128 | + 'npm install', |
| 129 | + 'npm run-script build', |
| 130 | + 'command -v refresh >/dev/null 2>&1 && refresh || true' |
| 131 | + ]; |
| 132 | + |
| 133 | + context.log.info(`Updating to release ${release.tag_name}`); |
| 134 | + |
| 135 | + for (const cmd of commands) { |
| 136 | + context.log.debug('Running command', execSync(cmd).toString()); |
| 137 | + } |
| 138 | + |
| 139 | + context.log.info(`Updated to release ${release.tag_name}`); |
| 140 | + }); |
| 141 | + } |
121 | 142 | } |
0 commit comments