mirror of
https://github.com/FranzDiebold/github-env-vars-action.git
synced 2024-11-22 08:40:59 -05:00
Merge pull request #53 from FranzDiebold/52-_slug-envs-are-not-truncated
slug envs are not truncated
This commit is contained in:
commit
9e73536a61
5 changed files with 1674 additions and 1056 deletions
18
README.md
18
README.md
|
@ -2,7 +2,7 @@
|
|||
|
||||
[![GitHub Action: View on Marketplace](https://img.shields.io/badge/GitHub%20Action-View_on_Marketplace-28a745?logo=github)](https://github.com/marketplace/actions/github-environment-variables-action)
|
||||
[![Demo: available](https://img.shields.io/badge/Demo-available-orange)](.github/workflows/demo.yml)
|
||||
[![Version: v2.5.0](https://img.shields.io/badge/Version-v2.5.0-brightgreen)](https://github.com/FranzDiebold/github-env-vars-action/releases/tag/v2.5.0)
|
||||
[![Version: v2.6.0](https://img.shields.io/badge/Version-v2.6.0-brightgreen)](https://github.com/FranzDiebold/github-env-vars-action/releases/tag/v2.6.0)
|
||||
[![Lint and Test](https://github.com/FranzDiebold/github-env-vars-action/workflows/Lint%20and%20Test/badge.svg)](https://github.com/FranzDiebold/github-env-vars-action/actions?query=workflow%3A%22Lint+and+Test%22)
|
||||
[![license: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](./LICENSE)
|
||||
|
||||
|
@ -12,21 +12,21 @@ A [GitHub Action](https://github.com/features/actions) to expose useful environm
|
|||
|
||||
| Environment Variable Name | Description | Example value |
|
||||
|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|
|
||||
| `CI_REPOSITORY_SLUG` | The slug of the owner and repository name (i.e. slug of `FranzDiebold/github-env-vars-action`). | `franzdiebold-github-env-vars-action` |
|
||||
| `CI_REPOSITORY_SLUG` | The slug of the owner and repository name (i.e. slug of `FranzDiebold/github-env-vars-action`). The slug is truncated to 63 characters. | `franzdiebold-github-env-vars-action` |
|
||||
| `CI_REPOSITORY_OWNER` | The owner of the repository. | `FranzDiebold` |
|
||||
| `CI_REPOSITORY_OWNER_SLUG` | The slug of the owner of the repository. | `franzdiebold` |
|
||||
| `CI_REPOSITORY_OWNER_SLUG` | The slug of the owner of the repository. The slug is truncated to 63 characters. | `franzdiebold` |
|
||||
| `CI_REPOSITORY_NAME` | The name of the repository. | `github-env-vars-action` |
|
||||
| `CI_REPOSITORY_NAME_SLUG` | The slug of the name of the repository. | `github-env-vars-action` |
|
||||
| `CI_REPOSITORY_NAME_SLUG` | The slug of the name of the repository. The slug is truncated to 63 characters. | `github-env-vars-action` |
|
||||
| `CI_REPOSITORY` | The owner and repository name. Copy of `GITHUB_REPOSITORY` - for reasons of completeness. | `FranzDiebold/github-env-vars-action` |
|
||||
| `CI_REF_SLUG` | The slug of the branch, tag or PR number *ref* that triggered the workflow (i.e. slug of `refs/heads/feat/feature-branch-1`). <br>If neither a branch, tag or PR number is available for the event type, the variable will not exist. | `refs-heads-feat-feature-branch-1` or<br> `refs-tags-v1-3-7` or<br> `refs-pull-42-merge` |
|
||||
| `CI_REF_SLUG` | The slug of the branch, tag or PR number *ref* that triggered the workflow (i.e. slug of `refs/heads/feat/feature-branch-1`). <br>If neither a branch, tag or PR number is available for the event type, the variable will not exist. The slug is truncated to 63 characters. | `refs-heads-feat-feature-branch-1` or<br> `refs-tags-v1-3-7` or<br> `refs-pull-42-merge` |
|
||||
| `CI_ACTION_REF_NAME` | The branch or tag *name* that triggered the workflow. For pull requests it is the *head* branch name. | `feat/feature-branch-1` or<br> `v1.3.7` |
|
||||
| `CI_ACTION_REF_NAME_SLUG` | The slug of the branch or tag *name* that triggered the workflow. For pull requests it is the slug of the *head* branch name. | `feat-feature-branch-1` or<br> `v1-3-7` |
|
||||
| `CI_ACTION_REF_NAME_SLUG` | The slug of the branch or tag *name* that triggered the workflow. For pull requests it is the slug of the *head* branch name. The slug is truncated to 63 characters. | `feat-feature-branch-1` or<br> `v1-3-7` |
|
||||
| `CI_REF_NAME` | The branch *name*, tag *name* or PR number that triggered the workflow. <br>If neither a branch, tag or PR number is available for the event type, the variable will not exist. | `feat/feature-branch-1` or<br> `v1.3.7` or<br> `42/merge` |
|
||||
| `CI_REF_NAME_SLUG` | The slug of the branch *name*, tag *name* or PR number that triggered the workflow. <br>If neither a branch, tag or PR number is available for the event type, the variable will not exist. | `feat-feature-branch-1` or<br> `v1-3-7` or<br> `42-merge` |
|
||||
| `CI_REF_NAME_SLUG` | The slug of the branch *name*, tag *name* or PR number that triggered the workflow. <br>If neither a branch, tag or PR number is available for the event type, the variable will not exist. The slug is truncated to 63 characters. | `feat-feature-branch-1` or<br> `v1-3-7` or<br> `42-merge` |
|
||||
| `CI_REF` | The branch, tag or PR number *ref* that triggered the workflow. <br>If neither a branch, tag or PR number is available for the event type, the variable will not exist. Copy of `GITHUB_REF` - for reasons of completeness. | `refs/heads/feat/feature-branch-1` or<br> `refs/tags/v1.3.7` or<br> `refs/pull/42/merge` |
|
||||
| `CI_HEAD_REF_SLUG` | The slug of the head branch *name*. <br>Only set for event type *pull request* or forked repositories. | `feat-feature-branch-1` |
|
||||
| `CI_HEAD_REF_SLUG` | The slug of the head branch *name*. <br>Only set for event type *pull request* or forked repositories. The slug is truncated to 63 characters. | `feat-feature-branch-1` |
|
||||
| `CI_HEAD_REF` | Only set for forked repositories / pull request. The branch of the head repository / the head branch name. Copy of `GITHUB_HEAD_REF` - for reasons of completeness. | `feat/feature-branch-1` |
|
||||
| `CI_BASE_REF_SLUG` | The slug of the base branch *name*. <br>Only set for event type *pull request* or forked repositories. | `main` |
|
||||
| `CI_BASE_REF_SLUG` | The slug of the base branch *name*. <br>Only set for event type *pull request* or forked repositories. The slug is truncated to 63 characters. | `main` |
|
||||
| `CI_BASE_REF` | Only set for forked repositories / pull request. The branch of the base repository / the base branch name. Copy of `GITHUB_BASE_REF` - for reasons of completeness. | `main` |
|
||||
| `CI_SHA_SHORT` | The shortened commit SHA (8 characters) that triggered the workflow. | `ffac537e` |
|
||||
| `CI_SHA` | The commit SHA that triggered the workflow. Copy of `GITHUB_SHA` - for reasons of completeness. | `ffac537e6cbbf934b08745a378932722df287a53` |
|
||||
|
|
9
index.js
9
index.js
|
@ -4,17 +4,20 @@ const core = require('@actions/core');
|
|||
const github = require('@actions/github');
|
||||
|
||||
/**
|
||||
* Slugify a given string.
|
||||
* Slugify a given string to a maximum length.
|
||||
* @param {string} inputString
|
||||
* @param {int} maxLength
|
||||
* @return {string} The slugified string.
|
||||
*/
|
||||
function slugify(inputString) {
|
||||
function slugify(inputString, maxLength = 63) {
|
||||
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
|
||||
.replace(/-+/g, '-') // collapse dashes
|
||||
.slice(0, maxLength) // truncate to maximum length
|
||||
.replace(/[-]+$/g, ''); // trim trailing -
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,16 @@ test('slugifies text', () => {
|
|||
expect(slugify(' /abc+efg*123/test§xyz ')).toEqual('abc-efg-123-test-xyz');
|
||||
});
|
||||
|
||||
test('slugifies a text to a maximum length', () => {
|
||||
expect(slugify(' /abc+efg*123/test§xyz 1234567 /(ö) ', 16))
|
||||
.toEqual('abc-efg-123-test');
|
||||
});
|
||||
|
||||
test('slugifies a text to a maximum length with trailing dash', () => {
|
||||
expect(slugify(' /abc+efg*123/test§xyz 1234567 /(ö) ', 17))
|
||||
.toEqual('abc-efg-123-test');
|
||||
});
|
||||
|
||||
test('slugifies ref name with dash', () => {
|
||||
expect(slugify('feat/feature-branch-1')).toEqual('feat-feature-branch-1');
|
||||
});
|
||||
|
|
2683
package-lock.json
generated
2683
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "github-env-vars-action",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"description": "A GitHub Action to expose useful environment variables.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -23,13 +23,13 @@
|
|||
},
|
||||
"homepage": "https://github.com/FranzDiebold/github-env-vars-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.0",
|
||||
"@actions/core": "^1.9.1",
|
||||
"@actions/github": "^5.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"eslint": "^8.19.0",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jest": "^28.1.2"
|
||||
"jest": "^29.0.2"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue