Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(brigade.js): add githubRelease handler #65

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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