2020-02-10 22:41:27 +01:00
|
|
|
const core = require('@actions/core');
|
|
|
|
|
|
|
|
function slugify(str) {
|
|
|
|
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
|
|
|
str = str.toLowerCase();
|
|
|
|
|
|
|
|
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
|
|
|
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
|
|
|
.replace(/-+/g, '-'); // collapse dashes
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables
|
|
|
|
try {
|
|
|
|
splitted_github_repository = process.env.GITHUB_REPOSITORY.split('/'); // octocat/Hello-World
|
2020-02-11 08:56:10 +01:00
|
|
|
core.exportVariable('GITHUB_REPO_OWNER', slugify(splitted_github_repository[0]));
|
2020-02-10 23:14:54 +01:00
|
|
|
core.info(`Set GITHUB_REPO_OWNER=${process.env.GITHUB_REPO_OWNER}`);
|
2020-02-11 08:56:10 +01:00
|
|
|
core.exportVariable('GITHUB_REPO_NAME', slugify(splitted_github_repository[1]));
|
2020-02-10 23:14:54 +01:00
|
|
|
core.info(`Set GITHUB_REPO_NAME=${process.env.GITHUB_REPO_NAME}`);
|
|
|
|
|
2020-02-10 22:41:27 +01:00
|
|
|
splitted_github_ref = process.env.GITHUB_REF.split('/'); // refs/heads/feature-branch-1
|
2020-02-11 08:56:10 +01:00
|
|
|
core.exportVariable('GITHUB_BRANCH_NAME', slugify(splitted_github_ref[2]));
|
2020-02-10 23:14:54 +01:00
|
|
|
core.info(`Set GITHUB_BRANCH_NAME=${process.env.GITHUB_BRANCH_NAME}`);
|
2020-02-10 22:41:27 +01:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|