Compare commits

...

22 Commits
v4 ... v3

Author SHA1 Message Date
semantic-release-bot
2daab132aa chore(release): 3.9.0 [skip ci]
# [3.9.0](https://github.com/rlespinasse/github-slug-action/compare/v3.8.0...v3.9.0) (2024-01-28)

### Features

* use node20 as action run mode ([#138](https://github.com/rlespinasse/github-slug-action/issues/138)) ([26c5c6b](26c5c6b51c))
2024-01-28 19:30:34 +00:00
Romain Lespinasse
26c5c6b51c feat: use node20 as action run mode (#138) 2024-01-28 20:25:18 +01:00
semantic-release-bot
4a00c29bc1 chore(release): 3.8.0 [skip ci]
# [3.8.0](https://github.com/rlespinasse/github-slug-action/compare/v3.7.1...v3.8.0) (2023-10-20)

### Features

* use node16 as action run mode ([7bf92d8](7bf92d88ff))
2023-10-20 10:59:54 +00:00
Romain Lespinasse
c0fb0bc1a5 build: update dependencies to fix vulnerabilities 2023-10-20 12:50:55 +02:00
Romain Lespinasse
60beba5b25 build: update dependencies to fix vulnerabilities (#133) 2023-07-19 21:30:03 +02:00
Romain Lespinasse
7bf92d88ff feat: use node16 as action run mode 2023-03-29 08:31:58 +02:00
Romain Lespinasse
ae2f6b069b docs(readme): remove badges
Signed-off-by: Romain Lespinasse <romain.lespinasse@gmail.com>
2023-03-28 20:05:30 +02:00
Romain Lespinasse
7c02e68015 build: fix security vulnerabilities 2023-02-03 16:43:05 +01:00
semantic-release-bot
5150a26d43 chore(release): 3.7.1 [skip ci]
## [3.7.1](https://github.com/rlespinasse/github-slug-action/compare/v3.7.0...v3.7.1) (2022-10-15)

### Bug Fixes

* use environment file to manage outputs ([dedf4ac](dedf4ac5bb))
2022-10-15 18:55:42 +00:00
Romain Lespinasse
dedf4ac5bb fix: use environment file to manage outputs
use @actions/core v1.10.0
so setOutput uses the new GITHUB_OUTPUT environment file
2022-10-15 20:54:46 +02:00
semantic-release-bot
ebfc49c0e9 chore(release): 3.7.0 [skip ci]
# [3.7.0](https://github.com/rlespinasse/github-slug-action/compare/v3.6.1...v3.7.0) (2022-10-02)

### Features

* generate proper git tag ([68babf6](68babf69b3))
2022-10-02 19:53:01 +00:00
Romain Lespinasse
68babf69b3 feat: generate proper git tag 2022-10-02 21:52:10 +02:00
semantic-release-bot
1bf76b7bc6 chore(release): 3.6.1 [skip ci]
## [3.6.1](https://github.com/rlespinasse/github-slug-action/compare/3.6.0...3.6.1) (2022-08-22)

### Bug Fixes

* remove trailing hyphens if any after cut ([19f9c84](19f9c84ac6))
2022-08-22 21:11:18 +00:00
rlespinasse
46a738e36b ci: use checkout v3 2022-08-22 23:07:07 +02:00
Romain Lespinasse
82da1fd43c ci(release): use github token 2022-08-22 23:02:40 +02:00
rlespinasse
99afdf4551 ci: use semantic release action v3 2022-08-22 22:58:21 +02:00
rlespinasse
944fee4603 ci: remove release dry-run 2022-06-16 22:26:11 +02:00
rlespinasse
19f9c84ac6 fix: remove trailing hyphens if any after cut 2022-06-16 22:26:11 +02:00
rlespinasse
596b602d8a docs(README): improve the overwrite troubleshooting section 2022-04-16 19:25:35 +02:00
Romain Lespinasse
b98d94bda3 ci: remove unused workflow 2022-04-07 20:50:05 +02:00
Romain Lespinasse
e8c1f6060b ci: rename workflows used on v3 only 2022-04-07 20:49:21 +02:00
Romain Lespinasse
f80aa0fae4 tests: add more test cases on v3 around underscore 2022-04-07 20:35:46 +02:00
19 changed files with 13390 additions and 11026 deletions

View File

@@ -1,4 +1,4 @@
name: CodeQL name: '[v3] CodeQL'
on: on:
push: push:
@@ -8,7 +8,11 @@ on:
branches: branches:
- v3.x - v3.x
schedule: schedule:
- cron: "0 6 * * 1" - cron: '0 6 * * 1'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
analyse: analyse:
@@ -17,12 +21,11 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
language: ["javascript"] language: ['javascript']
steps: steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1 - uses: actions/checkout@v3
- uses: actions/checkout@v2 - uses: github/codeql-action/init@v2
- uses: github/codeql-action/init@v1
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
- uses: github/codeql-action/autobuild@v1 - uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v1 - uses: github/codeql-action/analyze@v2

View File

@@ -1,4 +1,4 @@
name: Github Slug testing name: '[v3] Testing'
on: [push] on: [push]
jobs: jobs:
github-slug-on-os: github-slug-on-os:
@@ -9,9 +9,11 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- run: npm install - run: npm install
shell: bash
- run: npm run all - run: npm run all
shell: bash
- uses: ./ - uses: ./
- name: Partial variables - name: Partial variables
run: | run: |

View File

@@ -1,31 +0,0 @@
name: Lint
on:
push:
branches:
- v3.x
pull_request:
branches:
- v3.x
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: github/super-linter@v3
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_TYPESCRIPT_STANDARD: false
LINTER_RULES_PATH: .
JAVASCRIPT_ES_CONFIG_FILE: .eslintrc.json
JAVASCRIPT_DEFAULT_STYLE: prettier
DEFAULT_BRANCH: v3.x
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER_REGEX_INCLUDE: .*src/.*

View File

@@ -1,20 +1,24 @@
name: Release DryRun name: '[v3] Release DryRun'
on: on:
push: push:
branches-ignore: branches-ignore:
- v*.x - v*.x
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs: jobs:
release-dryrun: release-dryrun:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1 - uses: actions/checkout@v3
- uses: actions/checkout@v2
- run: npm install - run: npm install
shell: bash
- run: npm run all - run: npm run all
shell: bash
- uses: ./ - uses: ./
- uses: cycjimmy/semantic-release-action@v2 - uses: cycjimmy/semantic-release-action@v3
with: with:
branches: | branches: |
[ [

View File

@@ -1,18 +1,22 @@
name: Release name: '[v3] Release'
on: on:
push: push:
branches: branches:
- v*.x - v*.x
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs: jobs:
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1 - uses: actions/checkout@v3
- uses: actions/checkout@v2
- run: npm install - run: npm install
shell: bash
- run: npm run all - run: npm run all
- uses: cycjimmy/semantic-release-action@v2 shell: bash
- uses: cycjimmy/semantic-release-action@v3
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,3 +1,38 @@
# [3.9.0](https://github.com/rlespinasse/github-slug-action/compare/v3.8.0...v3.9.0) (2024-01-28)
### Features
* use node20 as action run mode ([#138](https://github.com/rlespinasse/github-slug-action/issues/138)) ([26c5c6b](https://github.com/rlespinasse/github-slug-action/commit/26c5c6b51cfc01c811f8a14ddd9d9bcb43948328))
# [3.8.0](https://github.com/rlespinasse/github-slug-action/compare/v3.7.1...v3.8.0) (2023-10-20)
### Features
* use node16 as action run mode ([7bf92d8](https://github.com/rlespinasse/github-slug-action/commit/7bf92d88ffb302024ab1f11ced51360f041f1b5e))
## [3.7.1](https://github.com/rlespinasse/github-slug-action/compare/v3.7.0...v3.7.1) (2022-10-15)
### Bug Fixes
* use environment file to manage outputs ([dedf4ac](https://github.com/rlespinasse/github-slug-action/commit/dedf4ac5bbb50aeb6992c8323d2862843079f1b4))
# [3.7.0](https://github.com/rlespinasse/github-slug-action/compare/v3.6.1...v3.7.0) (2022-10-02)
### Features
* generate proper git tag ([68babf6](https://github.com/rlespinasse/github-slug-action/commit/68babf69b34f4c4b556ea350616c5408d627937e))
## [3.6.1](https://github.com/rlespinasse/github-slug-action/compare/3.6.0...3.6.1) (2022-08-22)
### Bug Fixes
* remove trailing hyphens if any after cut ([19f9c84](https://github.com/rlespinasse/github-slug-action/commit/19f9c84ac61b17071a3cfc4ae984ac0e2ba1cdae))
# [3.6.0](http://github.com/rlespinasse/github-slug-action/compare/3.5.1...3.6.0) (2021-09-15) # [3.6.0](http://github.com/rlespinasse/github-slug-action/compare/3.5.1...3.6.0) (2021-09-15)

View File

@@ -1,10 +1,6 @@
# GitHub Slug action # GitHub Slug action
[![Release][release-badge]][releases] This GitHub Action will expose the slug/short values of [some GitHub environment variables][default-environment-variables] inside your GitHub workflow.
![Lint][lint-badge]
[![Licence][license-badge]][license]
This GitHub Action will expose the slug/short values of [some GitHub environment variables][github-env-vars] inside your GitHub workflow.
## Table of Contents ## Table of Contents
@@ -21,6 +17,8 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
- [Contribute](#contribute) - [Contribute](#contribute)
- [Troubleshooting](#troubleshooting) - [Troubleshooting](#troubleshooting)
- [One of the environment variables doesn't work as intended](#one-of-the-environment-variables-doesnt-work-as-intended) - [One of the environment variables doesn't work as intended](#one-of-the-environment-variables-doesnt-work-as-intended)
- [Known environment variable conflicts](#known-environment-variable-conflicts)
- [GITHUB_REF_NAME](#github_ref_name)
- [An action could not be found at the URI](#an-action-could-not-be-found-at-the-uri) - [An action could not be found at the URI](#an-action-could-not-be-found-at-the-uri)
- [Thanks for talking about us](#thanks-for-talking-about-us) - [Thanks for talking about us](#thanks-for-talking-about-us)
@@ -30,8 +28,9 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
- put the variable content in lower case - put the variable content in lower case
- replace any character by `-` except `0-9`, `a-z`, `.`, and `_` - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
- remove leading and trailing `-` character - remove leading `-` characters
- limit the string size to 63 characters - limit the string size to 63 characters
- remove trailing `-` characters
<details> <details>
<summary>Others <b>Slug-ish</b> commands are available</summary> <summary>Others <b>Slug-ish</b> commands are available</summary>
@@ -126,34 +125,42 @@ Follow [Developers guide](DEVELOPERS.md)
### One of the environment variables doesn't work as intended ### One of the environment variables doesn't work as intended
[**Note**][naming-conventions]: GitHub reserves the `GITHUB_` environment variable prefix for internal use by GitHub. Setting an environment variable or secret with the `GITHUB_` prefix will result in an error. [**Note**][naming-conventions]: When you set a custom environment variable, you cannot use any of the default environment variable names. For a complete list of these, see [Default environment variables][default-environment-variables]. **If you attempt to override the value of one of these default environment variables, the assignment is ignored.**
Currently, a GitHub workflow setting a `GITHUB_` variable will not cause an error, it will just fail silently. If a variable start to be used as default environment variable, the environment variable may have a different behavior than the expected one.
And if a custom `GITHUB_` variable is in conflict with an official `GITHUB_` variable, the offical `GITHUB_` variable will override custom one.
<details> If this append, the `${{ env.GITHUB_AWESOME_VARIABLE }}` and `$GITHUB_AWESOME_VARIABLE` expression will not works in the same way.
<summary>Test workflow</summary>
<p> - `${{ env.GITHUB_AWESOME_VARIABLE }}` will serve the behavior of this action,
- `$GITHUB_AWESOME_VARIABLE` will serve the behavior of GitHub Action.
Otherwise the two expression will serve the behavior of this action.
This will not occurs if you use the `prefix` input to avoid the issue.
**NOTE:** If detected, the maintainers of this action will choose the best course of action depending of the impact.
#### Known environment variable conflicts
##### GITHUB_REF_NAME
The behavior is the same as the GitHub one except on `pull_request*` workflows ([Ready the full story][issue-104]).
- `${{ env.GITHUB_REF_NAME }}` will serve the behavior of this action,
- `$GITHUB_REF_NAME` will serve the behavior of GitHub Action.
On `pull_request*` workflows, the content will be `<PR-number>/merge` instead of the branch name.
A possible workaround is to use `prefix` input available in `v4` version
```yaml ```yaml
name: Test - name: Inject slug/short variables
on: push uses: rlespinasse/github-slug-action@v4
jobs: with:
build: prefix: CI_
runs-on: ubuntu-latest
steps:
- run: echo ${GITHUB_REF}
# print "refs/heads/v3.x"
- run: echo "GITHUB_REF=one_value" >> "$GITHUB_ENV"
- run: echo ${GITHUB_REF}
# print "refs/heads/v3.x"
- run: echo "GITHUB_REF_SLUG=another_value" >> "$GITHUB_ENV"
- run: echo ${GITHUB_REF_SLUG}
# print "another_value"
``` ```
</p> Then `${{ env.CI_GITHUB_REF_NAME }}`, and `$CI_GITHUB_REF_NAME` will serve the behavior of this action.
</details> And `$GITHUB_REF_NAME` will serve the behavior of GitHub Action.
### An action could not be found at the URI ### An action could not be found at the URI
@@ -177,19 +184,16 @@ Please, use the current branch `v3.x` or a version tag (see [releases pages][rel
- [Action spotlight by Michael Heap][article-2] - [Action spotlight by Michael Heap][article-2]
- The next one is you. _Don't hesitate to add youself to this list._ - The next one is you. _Don't hesitate to add youself to this list._
[release-badge]: https://img.shields.io/github/workflow/status/rlespinasse/github-slug-action/Release?label=Build&logo=github&style=flat-square
[lint-badge]: https://img.shields.io/github/workflow/status/rlespinasse/github-slug-action/Lint?label=Lint&logo=github&style=flat-square
[license-badge]: https://img.shields.io/github/license/rlespinasse/github-slug-action?style=flat-square
[actions]: https://github.com/rlespinasse/github-slug-action/actions [actions]: https://github.com/rlespinasse/github-slug-action/actions
[license]: https://github.com/rlespinasse/github-slug-action/blob/v3.x/LICENSE [license]: https://github.com/rlespinasse/github-slug-action/blob/v3.x/LICENSE
[examples]: https://github.com/rlespinasse/github-slug-action/tree/v3.x/examples [examples]: https://github.com/rlespinasse/github-slug-action/tree/v3.x/examples
[custom-variable]: https://github.com/rlespinasse/github-slug-action/issues/new?assignees=&labels=enhancement&template=feature_request.md&title= [custom-variable]: https://github.com/rlespinasse/github-slug-action/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
[releases]: https://github.com/rlespinasse/github-slug-action/releases [releases]: https://github.com/rlespinasse/github-slug-action/releases
[issue-15]: https://github.com/rlespinasse/github-slug-action/issues/15 [issue-15]: https://github.com/rlespinasse/github-slug-action/issues/15
[issue-104]: https://github.com/rlespinasse/github-slug-action/issues/104
[github-env-vars]: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables [default-environment-variables]: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
[dependabot]: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot [dependabot]: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
[webhooks-and-events]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads [webhooks-and-events]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads
[naming-conventions]: https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables [naming-conventions]: https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables

View File

@@ -35,6 +35,11 @@ test('slug: a number', () => {
test_slug_cs('4.2', '4.2') test_slug_cs('4.2', '4.2')
}) })
test('slug: an underscore', () => {
test_slug('An_Underscore', 'an_underscore')
test_slug_cs('An_Underscore', 'An_Underscore')
})
test('slug: special character', () => { test('slug: special character', () => {
test_slug('feat-(!è§-character', 'feat------character') test_slug('feat-(!è§-character', 'feat------character')
test_slug_cs('feat-(!è§-character', 'feat------character') test_slug_cs('feat-(!è§-character', 'feat------character')
@@ -47,22 +52,22 @@ test('slug: trailing', () => {
test('slug: a very long string', () => { test('slug: a very long string', () => {
test_slug( test_slug(
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-feature-very-very-very-very-very-very-very-long-more' 'has-an-awesome-feature-very-very-very-very-very-very-very-long'
) )
test_slug_cs( test_slug_cs(
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more' 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
) )
}) })
test('slug: short string after trailing', () => { test('slug: short string after trailing', () => {
test_slug( test_slug(
'-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-', '-has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-',
'an-awesome-feature-very-very-very-very-very-very-very-long-more' 'has-an-awesome-feature-very-very-very-very-very-very-very-long'
) )
test_slug_cs( test_slug_cs(
'-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-', '-has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-',
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more' 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
) )
}) })

View File

@@ -25,6 +25,11 @@ test('slug_ref: a fix branch', () => {
test_slugref_cs('refs/heads/fix/issue_number', 'fix-issue_number') test_slugref_cs('refs/heads/fix/issue_number', 'fix-issue_number')
}) })
test('slug_ref: an underscore', () => {
test_slugref('refs/heads/An_Underscore', 'an_underscore')
test_slugref_cs('refs/heads/An_Underscore', 'An_Underscore')
})
test('slug_ref: a simple tag', () => { test('slug_ref: a simple tag', () => {
test_slugref('refs/tags/v1.0.0', 'v1.0.0') test_slugref('refs/tags/v1.0.0', 'v1.0.0')
test_slugref_cs('refs/tags/v1.0.0', 'v1.0.0') test_slugref_cs('refs/tags/v1.0.0', 'v1.0.0')
@@ -52,12 +57,12 @@ test('slug_ref: test refs inside string', () => {
test('slug_ref: a very long name', () => { test('slug_ref: a very long name', () => {
test_slugref( test_slugref(
'refs/heads/an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-feature-very-very-very-very-very-very-very-long-more' 'has-an-awesome-feature-very-very-very-very-very-very-very-long'
) )
test_slugref_cs( test_slugref_cs(
'refs/heads/an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more' 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
) )
}) })

View File

@@ -35,6 +35,11 @@ test('slug_url: a number', () => {
test_slugurl_cs('4.2', '4-2') test_slugurl_cs('4.2', '4-2')
}) })
test('slug_url: an underscore', () => {
test_slugurl('An_Underscore', 'an-underscore')
test_slugurl_cs('An_Underscore', 'An-Underscore')
})
test('slug_url: trailing', () => { test('slug_url: trailing', () => {
test_slugurl('.path.to.', 'path-to') test_slugurl('.path.to.', 'path-to')
test_slugurl_cs('.path.to.', 'path-to') test_slugurl_cs('.path.to.', 'path-to')
@@ -42,11 +47,11 @@ test('slug_url: trailing', () => {
test('slug_url: a very long string', () => { test('slug_url: a very long string', () => {
test_slugurl( test_slugurl(
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-feature-very-very-very-very-very-very-very-long-more' 'has-an-awesome-feature-very-very-very-very-very-very-very-long'
) )
test_slugurl_cs( test_slugurl_cs(
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more' 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
) )
}) })

View File

@@ -25,6 +25,11 @@ test('slug_url_ref: a fix branch', () => {
test_slugurlref_cs('refs/heads/fix/issue_number', 'fix-issue-number') test_slugurlref_cs('refs/heads/fix/issue_number', 'fix-issue-number')
}) })
test('slug_url_ref: an underscore', () => {
test_slugurlref('refs/heads/An_Underscore', 'an-underscore')
test_slugurlref_cs('refs/heads/An_Underscore', 'An-Underscore')
})
test('slug_url_ref: a simple tag', () => { test('slug_url_ref: a simple tag', () => {
test_slugurlref('refs/tags/v1.0.0', 'v1-0-0') test_slugurlref('refs/tags/v1.0.0', 'v1-0-0')
test_slugurlref_cs('refs/tags/v1.0.0', 'v1-0-0') test_slugurlref_cs('refs/tags/v1.0.0', 'v1-0-0')
@@ -42,12 +47,12 @@ test('slug_url_ref: a reference with upper case letters', () => {
test('slug_url_ref: a very long name', () => { test('slug_url_ref: a very long name', () => {
test_slugurlref( test_slugurlref(
'refs/heads/an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-feature-very-very-very-very-very-very-very-long-more' 'has-an-awesome-feature-very-very-very-very-very-very-very-long'
) )
test_slugurlref_cs( test_slugurlref_cs(
'refs/heads/an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters', 'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more' 'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
) )
}) })

View File

@@ -1,9 +1,9 @@
name: "GitHub Slug Action" name: 'GitHub Slug Action'
description: "GitHub Action to expose slug value of environment variables inside your GitHub workflow" description: 'GitHub Action to expose slug value of environment variables inside your GitHub workflow'
author: 'rlespinasse' author: 'rlespinasse'
runs: runs:
using: 'node12' using: 'node20'
main: 'dist/index.js' main: 'dist/index.js'
branding: branding:
icon: "minimize" icon: 'minimize'
color: "blue" color: 'blue'

3366
dist/index.js vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

14320
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "http://github.com/rlespinasse/github-slug-action.git" "url": "https://github.com/rlespinasse/github-slug-action.git"
}, },
"keywords": [ "keywords": [
"actions", "actions",
@@ -26,32 +26,32 @@
], ],
"author": "rlespinasse", "author": "rlespinasse",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6" "@actions/core": "^1.10.0"
}, },
"devDependencies": { "devDependencies": {
"@semantic-release/changelog": "^5.0.1", "@semantic-release/changelog": "^6.0.1",
"@semantic-release/exec": "^5.0.0", "@semantic-release/exec": "^6.0.0",
"@semantic-release/git": "^9.0.0", "@semantic-release/git": "^10.0.1",
"@types/jest": "^26.0.20", "@types/jest": "^26.0.24",
"@types/node": "^14.14.21", "@types/node": "^14.18.25",
"@typescript-eslint/eslint-plugin": "^4.22.0", "@typescript-eslint/eslint-plugin": "^5.38.1",
"@vercel/ncc": "^0.23.0", "@vercel/ncc": "^0.36.1",
"eslint": "^7.18.0", "eslint": "^8.0.1",
"eslint-plugin-github": "^4.1.1", "eslint-plugin-github": "^4.3.7",
"eslint-plugin-jest": "^23.20.0", "eslint-plugin-jest": "^23.20.0",
"jest": "^26.6.3", "jest": "^26.6.3",
"jest-circus": "^26.6.3", "jest-circus": "^26.6.3",
"js-yaml": "^3.14.1", "js-yaml": "^3.14.1",
"prettier": "^2.2.1", "prettier": "^2.7.1",
"semantic-release": "^17.4.0", "semantic-release": "^19.0.3",
"ts-jest": "^26.4.4", "ts-jest": "^26.5.6",
"typescript": "^3.9.7" "typescript": "^4.2.0"
}, },
"files": [ "files": [
"/dist" "/dist"
], ],
"release": { "release": {
"tagFormat": "${version}", "tagFormat": "v${version}",
"plugins": [ "plugins": [
"@semantic-release/commit-analyzer", "@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator", "@semantic-release/release-notes-generator",
@@ -66,7 +66,6 @@
"@semantic-release/github" "@semantic-release/github"
], ],
"branches": [ "branches": [
"v2.x",
"v3.x" "v3.x"
] ]
} }

View File

@@ -181,7 +181,7 @@ async function run(): Promise<void> {
exportBranchName() exportBranchName()
} catch (error) { } catch (error) {
core.setFailed(error.message) if (error instanceof Error) core.setFailed(error.message)
} }
} }

View File

@@ -3,23 +3,27 @@ const MAX_SLUG_STRING_SIZE = 63
/** /**
* slug_cs will take envVar and then : * slug_cs will take envVar and then :
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slug_cs(envVar: string): string { export function slug_cs(envVar: string): string {
return trailHyphen(replaceAnyNonAlphanumericCharacter(envVar)).substring( return removeTrailingHyphens(
removeLeadingHyphens(replaceAnyNonAlphanumericCharacter(envVar)).substring(
0, 0,
MAX_SLUG_STRING_SIZE MAX_SLUG_STRING_SIZE
) )
)
} }
/** /**
* slug will take envVar and then : * slug will take envVar and then :
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slug(envVar: string): string { export function slug(envVar: string): string {
@@ -30,8 +34,9 @@ export function slug(envVar: string): string {
* slugref_cs will take envVar and then : * slugref_cs will take envVar and then :
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugref_cs(envVar: string): string { export function slugref_cs(envVar: string): string {
@@ -43,8 +48,9 @@ export function slugref_cs(envVar: string): string {
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugref(envVar: string): string { export function slugref(envVar: string): string {
@@ -54,8 +60,9 @@ export function slugref(envVar: string): string {
/** /**
* slugurl_cs will take envVar and then : * slugurl_cs will take envVar and then :
* - replace any character by `-` except `0-9`, `a-z` * - replace any character by `-` except `0-9`, `a-z`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugurl_cs(envVar: string): string { export function slugurl_cs(envVar: string): string {
@@ -66,24 +73,26 @@ export function slugurl_cs(envVar: string): string {
* slugurl will take envVar and then : * slugurl will take envVar and then :
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z` * - replace any character by `-` except `0-9`, `a-z`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugurl(envVar: string): string { export function slugurl(envVar: string): string {
return slug(replaceAnyNonUrlCharactersWithHyphen(envVar)) return slugurl_cs(envVar.toLowerCase())
} }
/** /**
* slugurlref_cs will take envVar and then : * slugurlref_cs will take envVar and then :
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - replace any character by `-` except `0-9`, `a-z` * - replace any character by `-` except `0-9`, `a-z`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugurlref_cs(envVar: string): string { export function slugurlref_cs(envVar: string): string {
return slugurl_cs(slugref_cs(envVar)) return slugurl_cs(removeRef(envVar))
} }
/** /**
@@ -91,16 +100,20 @@ export function slugurlref_cs(envVar: string): string {
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z` * - replace any character by `-` except `0-9`, `a-z`
* - remove leading and trailing `-` character * - remove leading `-` characters
* - limit the string size to 63 characters * - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugurlref(envVar: string): string { export function slugurlref(envVar: string): string {
return slugurl(slugref(envVar)) return slugurlref_cs(envVar.toLowerCase())
} }
function trailHyphen(envVar: string): string { function removeLeadingHyphens(envVar: string): string {
return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '') return envVar.replace(RegExp('^-*', 'g'), '')
}
function removeTrailingHyphens(envVar: string): string {
return envVar.replace(RegExp('-*$', 'g'), '')
} }
function replaceAnyNonAlphanumericCharacter(envVar: string): string { function replaceAnyNonAlphanumericCharacter(envVar: string): string {