mirror of
https://github.com/FranzDiebold/github-env-vars-action.git
synced 2025-02-20 19:52:49 -05:00
27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
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
|
|
core.exportVariable('GITHUB_REPO_OWNER', slugify(splitted_github_repository[0]));
|
|
core.info(`Set GITHUB_REPO_OWNER=${process.env.GITHUB_REPO_OWNER}`);
|
|
core.exportVariable('GITHUB_REPO_NAME', slugify(splitted_github_repository[1]));
|
|
core.info(`Set GITHUB_REPO_NAME=${process.env.GITHUB_REPO_NAME}`);
|
|
|
|
splitted_github_ref = process.env.GITHUB_REF.split('/'); // refs/heads/feature-branch-1
|
|
core.exportVariable('GITHUB_BRANCH_NAME', slugify(splitted_github_ref[2]));
|
|
core.info(`Set GITHUB_BRANCH_NAME=${process.env.GITHUB_BRANCH_NAME}`);
|
|
} catch (error) {
|
|
core.setFailed(error.message);
|
|
}
|