Skip to content

Commit

Permalink
Merge pull request #65 from vdice/ci/gh-release
Browse files Browse the repository at this point in the history
ci(brigade.js): add githubRelease handler
  • Loading branch information
carolynvs-msft authored Jul 22, 2019
2 parents 4f62b69 + 59bddae commit d0e47f4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions brigade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const goImg = "golang:1.11";
const gopath = "/go";
const localPath = gopath + `/src/github.com/${projectOrg}/${projectName}`;

const releaseTagRegex = /^refs\/tags\/(v[0-9]+(?:\.[0-9]+)*(?:\-.+)?)$/;

// **********************************************
// Event Handlers
// **********************************************
Expand All @@ -15,6 +17,20 @@ events.on("exec", (e, p) => {
return test(e, p).run();
})

events.on("push", (e, p) => {
let matchStr = e.revision.ref.match(releaseTagRegex);

if (matchStr) {
// This is an official release with a semantically versioned tag
let matchTokens = Array.from(matchStr);
let version = matchTokens[1];
return test(e, p).run()
.then(() => {
githubRelease(p, version).run();
});
}
})

events.on("check_suite:requested", runSuite);
events.on("check_suite:rerequested", runSuite);
events.on("check_run:rerequested", checkRequested);
Expand Down Expand Up @@ -112,6 +128,40 @@ function checkRequested(e, p) {
}
}

// githubRelease creates a new release on GitHub, named by the provided tag
function githubRelease(p, tag) {
if (!p.secrets.ghToken) {
throw new Error("Project must have 'secrets.ghToken' set");
}

var job = new Job("release", goImg);
job.mountPath = localPath;
parts = p.repo.name.split("/", 2);

job.env = {
"GITHUB_USER": parts[0],
"GITHUB_REPO": parts[1],
"GITHUB_TOKEN": p.secrets.ghToken,
};

job.tasks = [
"go get github.com/aktau/github-release",
`cd ${localPath}`,
`last_tag=$(git describe --tags ${tag}^ --abbrev=0 --always)`,
`github-release release \
-t ${tag} \
-n "${parts[1]} ${tag}" \
-d "$(git log --no-merges --pretty=format:'- %s %H (%aN)' HEAD ^$last_tag)" \
|| echo "release ${tag} exists"`
];

console.log(job.tasks);
console.log(`release at https://github.com/${p.repo.name}/releases/tag/${tag}`);

return job;
}


// **********************************************
// Classes/Helpers
// **********************************************
Expand Down

0 comments on commit d0e47f4

Please sign in to comment.