Skip to content

Commit d0e47f4

Browse files
Merge pull request #65 from vdice/ci/gh-release
ci(brigade.js): add githubRelease handler
2 parents 4f62b69 + 59bddae commit d0e47f4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

brigade.js

+50
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const goImg = "golang:1.11";
77
const gopath = "/go";
88
const localPath = gopath + `/src/github.com/${projectOrg}/${projectName}`;
99

10+
const releaseTagRegex = /^refs\/tags\/(v[0-9]+(?:\.[0-9]+)*(?:\-.+)?)$/;
11+
1012
// **********************************************
1113
// Event Handlers
1214
// **********************************************
@@ -15,6 +17,20 @@ events.on("exec", (e, p) => {
1517
return test(e, p).run();
1618
})
1719

20+
events.on("push", (e, p) => {
21+
let matchStr = e.revision.ref.match(releaseTagRegex);
22+
23+
if (matchStr) {
24+
// This is an official release with a semantically versioned tag
25+
let matchTokens = Array.from(matchStr);
26+
let version = matchTokens[1];
27+
return test(e, p).run()
28+
.then(() => {
29+
githubRelease(p, version).run();
30+
});
31+
}
32+
})
33+
1834
events.on("check_suite:requested", runSuite);
1935
events.on("check_suite:rerequested", runSuite);
2036
events.on("check_run:rerequested", checkRequested);
@@ -112,6 +128,40 @@ function checkRequested(e, p) {
112128
}
113129
}
114130

131+
// githubRelease creates a new release on GitHub, named by the provided tag
132+
function githubRelease(p, tag) {
133+
if (!p.secrets.ghToken) {
134+
throw new Error("Project must have 'secrets.ghToken' set");
135+
}
136+
137+
var job = new Job("release", goImg);
138+
job.mountPath = localPath;
139+
parts = p.repo.name.split("/", 2);
140+
141+
job.env = {
142+
"GITHUB_USER": parts[0],
143+
"GITHUB_REPO": parts[1],
144+
"GITHUB_TOKEN": p.secrets.ghToken,
145+
};
146+
147+
job.tasks = [
148+
"go get github.com/aktau/github-release",
149+
`cd ${localPath}`,
150+
`last_tag=$(git describe --tags ${tag}^ --abbrev=0 --always)`,
151+
`github-release release \
152+
-t ${tag} \
153+
-n "${parts[1]} ${tag}" \
154+
-d "$(git log --no-merges --pretty=format:'- %s %H (%aN)' HEAD ^$last_tag)" \
155+
|| echo "release ${tag} exists"`
156+
];
157+
158+
console.log(job.tasks);
159+
console.log(`release at https://github.com/${p.repo.name}/releases/tag/${tag}`);
160+
161+
return job;
162+
}
163+
164+
115165
// **********************************************
116166
// Classes/Helpers
117167
// **********************************************

0 commit comments

Comments
 (0)