-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_repo.js
51 lines (43 loc) · 1.48 KB
/
release_repo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const git = require('simple-git/promise');
const path = require('path');
const fs = require('fs');
exports.clone = async function(repoPath, repo, token) {
const repoURL = `https://${token}@github.com/${repo}.git`;
console.log(`Cloning ${repoURL} to ${repoPath}`);
await git('.').clone(repoURL, repoPath, ['--depth=1'])
}
exports.clean = function(repoPath, keep) {
// keep is a colon seperated list files to keep
var keepFiles = [];
if (keep) {
keepFiles = keep.split(":").map((item) => item.trim());
}
let nonKeepers = (file) => !keepFiles.includes(file);
let nonDotFiles = (file) => (file[0] != ".");
let existingFiles = fs.readdirSync(repoPath)
.filter(nonDotFiles)
.filter(nonKeepers);
for (let file of existingFiles) {
fs.rmSync(path.join(repoPath, file), { recursive: true })
}
}
exports.prep = async function(repoPath, actor) {
const repo = git(repoPath);
await repo.addConfig("user.email", `${actor}@users.noreply.github.com`);
await repo.addConfig("user.name", "Release Repo Bot");
}
exports.commitAndPush = async function(repoPath, tag, branch) {
const repo = git(repoPath);
const message = `Release ${tag}`;
console.log(`Commit, tag, and push to release repo: ${message}`);
if (branch) {
await repo.checkout(["-b", branch]);
}
await repo.add(['.']);
await repo.commit(message);
await repo.push("origin", "HEAD");
if (tag) {
await repo.addTag(tag);
await repo.pushTags("origin");
}
}