Skip to content

Commit bf52fe1

Browse files
committed
Added deployment handler prototype
Refs #3
1 parent b55d028 commit bf52fe1

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/index.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Application } from 'probot' // eslint-disable-line no-unused-vars
22
import { CommentParser, LinkEntry } from './CommentParser'
33
import { SnippetResolver } from './SnippetResolver'
4-
import express from 'express'
4+
import { execSync } from 'child_process'
55

66
export = (app: Application) => {
77
const parser = new CommentParser;
@@ -111,11 +111,32 @@ ${snippet.results.results.length ? snippet.results.results.map(issue => `${issue
111111
}
112112
});
113113

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;
116123

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+
}
121142
}

0 commit comments

Comments
 (0)