mirror of
https://github.com/FranzDiebold/github-env-vars-action.git
synced 2024-11-09 18:43:32 -05:00
Add slug values.
This commit is contained in:
parent
19929f6cd1
commit
789d3f0d81
1 changed files with 54 additions and 4 deletions
58
dist/index.js
vendored
58
dist/index.js
vendored
|
@ -163,6 +163,20 @@ module.exports = require("path");
|
||||||
|
|
||||||
const core = __webpack_require__(827);
|
const core = __webpack_require__(827);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slugify a given string.
|
||||||
|
* @param {string} inputString
|
||||||
|
* @return {string} The slugified string.
|
||||||
|
*/
|
||||||
|
function slugify(inputString) {
|
||||||
|
return inputString
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9 -]/g, ' ') // remove invalid chars
|
||||||
|
.replace(/^\s+|\s+$/g, '') // trim
|
||||||
|
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
||||||
|
.replace(/-+/g, '-'); // collapse dashes
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the repository owner from the repository string.
|
* Get the repository owner from the repository string.
|
||||||
* @param {string} repository
|
* @param {string} repository
|
||||||
|
@ -204,14 +218,29 @@ try {
|
||||||
// i.e. FranzDiebold/github-env-vars-action
|
// i.e. FranzDiebold/github-env-vars-action
|
||||||
repository = process.env.GITHUB_REPOSITORY;
|
repository = process.env.GITHUB_REPOSITORY;
|
||||||
|
|
||||||
|
if (repository) {
|
||||||
|
core.exportVariable('GITHUB_REPOSITORY_SLUG', slugify(repository));
|
||||||
|
core.info(`Set GITHUB_REPOSITORY_SLUG=` +
|
||||||
|
`${process.env.GITHUB_REPOSITORY_SLUG}`);
|
||||||
|
} else {
|
||||||
|
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||||
|
'Cannot set "GITHUB_REPOSITORY_SLUG".');
|
||||||
|
}
|
||||||
|
|
||||||
repositoryOwner = getRepositoryOwner(repository);
|
repositoryOwner = getRepositoryOwner(repository);
|
||||||
if (repositoryOwner) {
|
if (repositoryOwner) {
|
||||||
core.exportVariable('GITHUB_REPOSITORY_OWNER', repositoryOwner);
|
core.exportVariable('GITHUB_REPOSITORY_OWNER', repositoryOwner);
|
||||||
core.info(`Set GITHUB_REPOSITORY_OWNER=` +
|
core.info(`Set GITHUB_REPOSITORY_OWNER=` +
|
||||||
`${process.env.GITHUB_REPOSITORY_OWNER}`);
|
`${process.env.GITHUB_REPOSITORY_OWNER}`);
|
||||||
|
|
||||||
|
core.exportVariable('GITHUB_REPOSITORY_OWNER_SLUG',
|
||||||
|
slugify(repositoryOwner));
|
||||||
|
core.info(`Set GITHUB_REPOSITORY_OWNER_SLUG=` +
|
||||||
|
`${process.env.GITHUB_REPOSITORY_OWNER_SLUG}`);
|
||||||
} else {
|
} else {
|
||||||
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||||
'Cannot set "GITHUB_REPOSITORY_OWNER".');
|
'Cannot set "GITHUB_REPOSITORY_OWNER" and ' +
|
||||||
|
'"GITHUB_REPOSITORY_OWNER_SLUG".');
|
||||||
}
|
}
|
||||||
|
|
||||||
repositoryName = getRepositoryName(repository);
|
repositoryName = getRepositoryName(repository);
|
||||||
|
@ -219,19 +248,39 @@ try {
|
||||||
core.exportVariable('GITHUB_REPOSITORY_NAME', repositoryName);
|
core.exportVariable('GITHUB_REPOSITORY_NAME', repositoryName);
|
||||||
core.info(`Set GITHUB_REPOSITORY_NAME=` +
|
core.info(`Set GITHUB_REPOSITORY_NAME=` +
|
||||||
`${process.env.GITHUB_REPOSITORY_NAME}`);
|
`${process.env.GITHUB_REPOSITORY_NAME}`);
|
||||||
|
|
||||||
|
core.exportVariable('GITHUB_REPOSITORY_NAME_SLUG',
|
||||||
|
slugify(repositoryName));
|
||||||
|
core.info(`Set GITHUB_REPOSITORY_NAME_SLUG=` +
|
||||||
|
`${process.env.GITHUB_REPOSITORY_NAME_SLUG}`);
|
||||||
} else {
|
} else {
|
||||||
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||||
'Cannot set "GITHUB_REPOSITORY_NAME".');
|
'Cannot set "GITHUB_REPOSITORY_NAME" and ' +
|
||||||
|
'"GITHUB_REPOSITORY_NAME_SLUG".');
|
||||||
}
|
}
|
||||||
|
|
||||||
// i.e. refs/heads/feat/feature-branch-1
|
// i.e. refs/heads/feat/feature-branch-1
|
||||||
refName = getRefName(process.env.GITHUB_REF);
|
ref = process.env.GITHUB_REF;
|
||||||
|
|
||||||
|
if (ref) {
|
||||||
|
core.exportVariable('GITHUB_REF_SLUG', slufigy(ref));
|
||||||
|
core.info(`Set GITHUB_REF_SLUG=${process.env.GITHUB_REF_SLUG}`);
|
||||||
|
} else {
|
||||||
|
core.warning('Environment variable "GITHUB_REF" not set. ' +
|
||||||
|
'Cannot set "GITHUB_REF_SLUG".');
|
||||||
|
}
|
||||||
|
|
||||||
|
refName = getRefName(ref);
|
||||||
if (refName) {
|
if (refName) {
|
||||||
core.exportVariable('GITHUB_REF_NAME', refName);
|
core.exportVariable('GITHUB_REF_NAME', refName);
|
||||||
core.info(`Set GITHUB_REF_NAME=${process.env.GITHUB_REF_NAME}`);
|
core.info(`Set GITHUB_REF_NAME=${process.env.GITHUB_REF_NAME}`);
|
||||||
|
|
||||||
|
core.exportVariable('GITHUB_REF_NAME_SLUG', slufigy(refName));
|
||||||
|
core.info(`Set GITHUB_REF_NAME_SLUG=${process.env.GITHUB_REF_NAME_SLUG}`);
|
||||||
} else {
|
} else {
|
||||||
core.warning('Environment variable "GITHUB_REF" not set. ' +
|
core.warning('Environment variable "GITHUB_REF" not set. ' +
|
||||||
'Cannot set "GITHUB_REF_NAME".');
|
'Cannot set "GITHUB_REF_NAME" and ' +
|
||||||
|
'"GITHUB_REF_NAME_SLUG".');
|
||||||
}
|
}
|
||||||
|
|
||||||
// i.e. ffac537e6cbbf934b08745a378932722df287a53
|
// i.e. ffac537e6cbbf934b08745a378932722df287a53
|
||||||
|
@ -248,6 +297,7 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
slugify,
|
||||||
getRepositoryOwner,
|
getRepositoryOwner,
|
||||||
getRepositoryName,
|
getRepositoryName,
|
||||||
getRefName,
|
getRefName,
|
||||||
|
|
Loading…
Reference in a new issue