Compare commits

...

108 Commits
1.1.0 ... v3.x

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
rlespinasse
046be07299 build: fix npm vulnerabilities 2021-12-04 22:00:29 +01:00
rlespinasse
38b80287e3 ci: use matrix for os testing 2021-12-04 21:26:47 +01:00
Romain Lespinasse
c559dac9da docs(example): use dedictated domain exemple name 2021-10-30 09:25:40 +02:00
Romain Lespinasse
2f05f8b5cb docs(readme): add Michael Heap article 2021-09-29 16:29:38 +02:00
dependabot[bot]
9f53b89c13 build(deps): bump semver-regex from 3.1.2 to 3.1.3 2021-09-21 17:12:59 +02:00
semantic-release-bot
172fe43594 chore(release): 3.6.0 [skip ci]
# [3.6.0](http://github.com/rlespinasse/github-slug-action/compare/3.5.1...3.6.0) (2021-09-15)

### Features

* add GITHUB_REF_NAME env var ([12a7510](12a7510630))
2021-09-15 15:01:24 +00:00
Antoine Méausoone
12a7510630 feat: add GITHUB_REF_NAME env var
GITHUB_REF_NAME will contain the reference name (branch or tag)
  - based on GITHUB_HEAD_REF in a pull-request event context,
  - based on GITHUB_REF in others event contexts.
2021-09-15 17:00:11 +02:00
rlespinasse
b71a8a1cbc build: fix potential security vulnerabilities 2021-09-02 21:56:17 +02:00
Joshua Chaitin-Pollak
54910e921d docs: minor grammatical fixes for clarity 2021-08-04 23:07:16 +02:00
rlespinasse
35d90c4a71 build: update transitive dependencies 2021-06-14 22:44:11 +02:00
rlespinasse
ada34a0888 docs: fix link to use by badge 2021-04-17 23:19:39 +02:00
rlespinasse
6370faccb7 docs: improve links 2021-04-17 23:16:44 +02:00
rlespinasse
81beb28f90 ci: improve release process 2021-04-17 22:16:49 +02:00
Romain Lespinasse
08cd74e0fa docs: improve overview section 2021-04-17 22:16:49 +02:00
Romain Lespinasse
8c0a3268b6 docs: improve overview section 2021-04-02 16:14:40 +02:00
semantic-release-bot
016823880d chore(release): 3.5.1 [skip ci]
## [3.5.1](http://github.com/rlespinasse/github-slug-action/compare/3.5.0...3.5.1) (2021-03-31)

### Bug Fixes

* update dist files ([e6c550f](e6c550f88c))
2021-03-31 06:58:56 +00:00
Mark Allen
e6c550f88c fix: update dist files 2021-03-31 08:57:45 +02:00
semantic-release-bot
4060fda269 chore(release): 3.5.0 [skip ci]
# [3.5.0](http://github.com/rlespinasse/github-slug-action/compare/3.4.0...3.5.0) (2021-03-30)

### Features

* allow underscore in slug values ([475d293](475d293680))
2021-03-30 20:05:12 +00:00
Mark Allen
475d293680 feat: allow underscore in slug values 2021-03-30 22:04:00 +02:00
semantic-release-bot
0c099abd97 chore(release): 3.4.0 [skip ci]
# [3.4.0](http://github.com/rlespinasse/github-slug-action/compare/3.3.0...3.4.0) (2021-03-02)

### Features

* add _CS suffix to keep value case-sensitive ([6c93fcb](6c93fcbf53))
2021-03-02 23:30:23 +00:00
rlespinasse
6c93fcbf53 feat: add _CS suffix to keep value case-sensitive 2021-03-03 00:29:09 +01:00
rlespinasse
38c43d3f60 build(node): use non-vulnerable version of marked 2021-02-27 22:37:18 +01:00
rlespinasse
275eb0d01d docs(slug): document pull_request slug issue 2021-01-27 19:31:46 +01:00
semantic-release-bot
d1880ea5b3 chore(release): 3.3.0 [skip ci]
# [3.3.0](http://github.com/rlespinasse/github-slug-action/compare/3.2.0...3.3.0) (2021-01-25)

### Bug Fixes

* support pull-request for slug and slug url ([78985f8](78985f84ec))

### Features

* support partial GITHUB_REPOSITORY ([75ce03b](75ce03b6a0))
2021-01-25 22:20:39 +00:00
rlespinasse
66299f72e4 docs: improve readability on tables 2021-01-25 23:16:23 +01:00
rlespinasse
78985f84ec fix: support pull-request for slug and slug url 2021-01-25 22:12:27 +01:00
rlespinasse
75ce03b6a0 feat: support partial GITHUB_REPOSITORY 2021-01-25 22:12:27 +01:00
rlespinasse
49e1056c70 docs(troubleshooting): add naming convention issue 2021-01-25 20:01:05 +01:00
rlespinasse
81bff0391a docs(README): expose documentation and examples 2021-01-25 20:01:05 +01:00
rlespinasse
b956e16ac2 ci: print better testing output 2021-01-25 20:01:05 +01:00
rlespinasse
fad587c035 build: update dependencies 2021-01-25 20:01:05 +01:00
Romain Lespinasse
5f4806451f ci: disable linter about standard js
Since we use Prettier instead
2021-01-12 10:24:06 +01:00
semantic-release-bot
c8d8ee50d0 chore(release): 3.2.0 [skip ci]
# [3.2.0](http://github.com/rlespinasse/github-slug-action/compare/3.1.0...3.2.0) (2021-01-12)

### Features

* expose GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT ([5b9fe60](5b9fe6015d))
2021-01-12 09:23:14 +00:00
Julien Klaer
5b9fe6015d feat: expose GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT 2021-01-12 10:22:14 +01:00
rlespinasse
5629d21ee9 ci(linter): use repo eslint configuration 2021-01-09 09:44:25 +01:00
dependabot[bot]
b6938fb2bd build(deps): bump node-notifier from 8.0.0 to 8.0.1
Bumps [node-notifier](https://github.com/mikaelbr/node-notifier) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/mikaelbr/node-notifier/releases)
- [Changelog](https://github.com/mikaelbr/node-notifier/blob/v8.0.1/CHANGELOG.md)
- [Commits](https://github.com/mikaelbr/node-notifier/compare/v8.0.0...v8.0.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-01-01 18:42:36 +01:00
Romain Lespinasse
d6257a36a9 docs(contributing): fix typo 2020-12-18 17:39:27 +01:00
dependabot[bot]
7ad978282a build(deps): bump ini from 1.3.5 to 1.3.8
Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-14 08:32:50 +01:00
Romain Lespinasse
9f5fafb8ad docs: add talks/articles section 2020-12-12 18:13:01 +01:00
Romain Lespinasse
750d2f7f48 ci: setup CodeQL GitHub workflow 2020-12-05 19:37:21 +01:00
Alain Hélaïli
2b1034b1fb docs: fix typo in sample 2020-12-05 15:27:19 +01:00
dependabot[bot]
1b1913be6c build(deps-dev): bump semantic-release from 17.0.7 to 17.2.3
Bumps [semantic-release](https://github.com/semantic-release/semantic-release) from 17.0.7 to 17.2.3.
- [Release notes](https://github.com/semantic-release/semantic-release/releases)
- [Commits](https://github.com/semantic-release/semantic-release/compare/v17.0.7...v17.2.3)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-19 12:59:57 +01:00
Romain Lespinasse
cc560ad7b4 ci: run linter on default branch 2020-11-01 21:31:23 +01:00
rlespinasse
549c11b4e2 ci: improve build workflow 2020-11-01 21:29:52 +01:00
rlespinasse
68eb43656c ci: add dependabot for github-actions 2020-11-01 21:29:52 +01:00
rlespinasse
2aba10a826 ci: add linter workflow 2020-11-01 21:29:52 +01:00
Romain Lespinasse
afcda09378 docs(readme): add license badge 2020-11-01 21:01:37 +01:00
Romain Lespinasse
15f6edebdd docs(readme): improve action scope 2020-11-01 20:52:34 +01:00
semantic-release-bot
e4699e49fc chore(release): 3.1.0 [skip ci]
# [3.1.0](http://github.com/rlespinasse/github-slug-action/compare/3.0.0...3.1.0) (2020-11-01)

### Features

* **action:** improve marketplace information ([3cddc4f](3cddc4f12d))
2020-11-01 19:40:26 +00:00
Romain Lespinasse
3cddc4f12d feat(action): improve marketplace information 2020-11-01 20:39:24 +01:00
rlespinasse
d7817bf204 docs(contributing): improve issue links 2020-10-31 16:12:03 +01:00
Romain Lespinasse
4e3f956c5e docs: add contributing guide 2020-10-31 09:36:05 +01:00
Romain Lespinasse
f79727b5cc docs: improve master EOL section 2020-10-31 08:24:38 +01:00
Romain Lespinasse
a3c7c5c7a1 docs: use v3.x branch in example 2020-10-31 08:22:11 +01:00
rlespinasse
008aa6260d build: bump dev dependencies versions 2020-10-27 09:28:24 +01:00
rlespinasse
3c7ae42a01 ci: activate release on v3.x branch 2020-10-26 21:42:08 +01:00
Romain Lespinasse
ae2430ad57 docs(security): remove v1.1.x from supported versions 2020-10-26 21:29:58 +01:00
semantic-release-bot
6a873bec5a chore(release): 3.0.0 [skip ci]
# [3.0.0](http://github.com/rlespinasse/github-slug-action/compare/2.1.0...3.0.0) (2020-10-26)

### Bug Fixes

* upgrade actions core due to CVE fix ([d0549c1](d0549c1f85))

### Features

* add support for windows and macos jobs ([13c2f38](13c2f38dad))

### BREAKING CHANGES

* The action implementation move from container action to node.js action

Co-authored-by: Romain Lespinasse <romain.lespinasse@gmail.com>
2020-10-26 20:27:51 +00:00
Romain Lespinasse
749009dfe1 ci: activate release on v3.x branch 2020-10-26 21:26:45 +01:00
rlespinasse
ec03dc4d9c build: add dist files after actions core upgrades 2020-10-18 20:09:34 +02:00
rlespinasse
d0549c1f85 fix: upgrade actions core due to CVE fix 2020-10-07 22:53:33 +02:00
Antoine Méausoone
13c2f38dad feat: add support for windows and macos jobs
BREAKING CHANGE: The action implementation move from container action to node.js action

Co-authored-by: Romain Lespinasse <romain.lespinasse@gmail.com>
2020-09-26 09:07:49 +02:00
dependabot[bot]
6efa53ebca build(deps): bump node-fetch from 2.6.0 to 2.6.1
Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-09-12 17:41:09 +02:00
Romain Lespinasse
c0eae81222 style: use markdown syntax on link with image 2020-08-28 15:21:44 +02:00
Antoine Méausoone
7e9b2916a8 docs: add badge with number of public users 2020-08-26 19:20:17 +02:00
Romain Lespinasse
c34e0866d5 docs: improve troubleshooting section 2020-08-25 12:38:58 +02:00
rlespinasse
9ed3b31f8a ci: update release dependencies 2020-08-16 21:06:07 +02:00
semantic-release-bot
1172ed1802 chore(release): 2.1.0 [skip ci]
# [2.1.0](http://github.com/rlespinasse/github-slug-action/compare/2.0.0...2.1.0) (2020-07-28)

### Features

* expose slug variables for github.event.ref ([5a334a8](5a334a8573))
2020-07-28 16:50:05 +00:00
rlespinasse
5a334a8573 feat: expose slug variables for github.event.ref 2020-07-28 18:49:15 +02:00
Romain Lespinasse
4268cc0475 docs: add funding file 2020-07-20 20:26:41 +02:00
Romain Lespinasse
9225a8adaf docs: add troubleshooting section 2020-07-17 22:31:08 +02:00
rlespinasse
498f51bdf6 chore: update package json for security reason 2020-07-15 23:35:55 +02:00
rlespinasse
7c65a057e0 ci: improve release process 2020-05-01 17:18:08 +02:00
rlespinasse
e5b7d5b5fc docs: fix typo 2020-04-26 02:25:09 +02:00
rlespinasse
ca9a67fa1f feat(slug): expose GITHUB_REPOSITORY slugs 2020-04-26 02:12:41 +02:00
rlespinasse
e95fe45d8b feat(slug): keep period in slug variable
BREAKING CHANGE: The previous slug function is rename slug_url
to be able to still use itin the subdomain of an url.

Co-authored-by: Marc Schiller <m4rc.schiller@gmail.com>
2020-04-26 02:12:28 +02:00
rlespinasse
250b75dc58 ci: introduce version 2.x serie 2020-04-25 23:17:37 +02:00
rlespinasse
8799f16714 docs(security): add vulenerability report guide 2020-04-25 22:23:43 +02:00
rlespinasse
f55abd0ed8 docs: improve usage guide 2020-04-25 22:04:15 +02:00
rlespinasse
78b4cbe021 style: add editorconfig file 2020-04-25 22:04:15 +02:00
rlespinasse
74fe20250f ci: move to branch-based releases 2020-04-25 19:56:36 +02:00
rlespinasse
30ff8f2cb0 build: fix dependencies vulnerabilities 2020-04-25 19:43:46 +02:00
Slava Semushin
73f6003cd2 style: fix typos 2019-12-16 17:18:57 +01:00
dependabot[bot]
fd2f7856b9 build(deps): bump npm from 6.13.0 to 6.13.4
Bumps [npm](https://github.com/npm/cli) from 6.13.0 to 6.13.4.
- [Release notes](https://github.com/npm/cli/releases)
- [Changelog](https://github.com/npm/cli/blob/latest/CHANGELOG.md)
- [Commits](https://github.com/npm/cli/compare/v6.13.0...v6.13.4)

Signed-off-by: dependabot[bot] <support@github.com>
2019-12-13 22:32:17 +01:00
Antoine Meausoone
0e25ff1b4e ci(pr): build on pull_request 2019-12-11 13:23:09 +01:00
Antoine Méausoone
97aa7af437 test(docker): fix bats docker image 2019-12-11 13:23:09 +01:00
52 changed files with 18607 additions and 5604 deletions

6
.dependabot/config.xml Normal file
View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

11
.editorconfig Normal file
View File

@@ -0,0 +1,11 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

3
.eslintignore Normal file
View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

54
.eslintrc.json Normal file
View File

@@ -0,0 +1,54 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}

3
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: rlespinasse

View File

@@ -1,5 +0,0 @@
FROM dduportal/bats:latest
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env sh
/sbin/bats ./tests

View File

@@ -1,16 +0,0 @@
name: ci
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./.github/actions/bats
- uses: cycjimmy/semantic-release-action@v2
if: github.ref == 'refs/heads/master'
with:
extra_plugins: |
@semantic-release/git
@semantic-release/changelog
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

31
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: '[v3] CodeQL'
on:
push:
branches:
- v3.x
pull_request:
branches:
- v3.x
schedule:
- cron: '0 6 * * 1'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
analyse:
name: analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: ['javascript']
steps:
- uses: actions/checkout@v3
- uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v2

74
.github/workflows/github-slug.yml vendored Normal file
View File

@@ -0,0 +1,74 @@
name: '[v3] Testing'
on: [push]
jobs:
github-slug-on-os:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- run: npm install
shell: bash
- run: npm run all
shell: bash
- uses: ./
- name: Partial variables
run: |
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART }}"
shell: bash
- name: Slug variables
run: |
echo "repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}"
echo "ref : ${{ env.GITHUB_REF_SLUG }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
- name: Slug variables (Case Sensitive)
run: |
echo "repository : ${{ env.GITHUB_REPOSITORY_SLUG_CS }}"
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_CS }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_CS }}"
echo "ref : ${{ env.GITHUB_REF_SLUG_CS }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG_CS }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG_CS }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG_CS }}"
shell: bash
- name: Slug URL variables
run: |
echo "repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}"
echo "ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
shell: bash
- name: Slug URL variables (Case Sensitive)
run: |
echo "repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL_CS }}"
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL_CS }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}"
echo "ref : ${{ env.GITHUB_REF_SLUG_URL_CS }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL_CS }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL_CS }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}"
shell: bash
- name: Ref Name
run: |
echo "raw : ${{ env.GITHUB_REF_NAME }}"
echo "slug : ${{ env.GITHUB_REF_NAME_SLUG }}"
echo "slug url : ${{ env.GITHUB_REF_NAME_SLUG_URL }}"
echo "slug (Case Sensitive) : ${{ env.GITHUB_REF_NAME_SLUG_CS }}"
echo "slug url (Case Sensitive) : ${{ env.GITHUB_REF_NAME_SLUG_URL_CS }}"
shell: bash
- name: Short SHA variables
run: |
echo "sha : ${{ env.GITHUB_SHA_SHORT }}"
echo "pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
shell: bash

29
.github/workflows/release-dryrun.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
name: '[v3] Release DryRun'
on:
push:
branches-ignore:
- v*.x
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
release-dryrun:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
shell: bash
- run: npm run all
shell: bash
- uses: ./
- uses: cycjimmy/semantic-release-action@v3
with:
branches: |
[
"${{ env.GITHUB_REF_NAME }}"
]
dry_run: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

22
.github/workflows/release.yml vendored Normal file
View File

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

100
.gitignore vendored
View File

@@ -1 +1,99 @@
node_modules/
# Dependency directory
node_modules
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# OS metadata
.DS_Store
Thumbs.db
# Ignore built ts files
__tests__/runner/*
lib/**/*

3
.prettierignore Normal file
View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

10
.prettierrc.json Normal file
View File

@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}

View File

@@ -1,13 +1,114 @@
# [1.1.0](http://github.com/rlespinasse/github-slug-action/compare/1.0.2...1.1.0) (2019-11-11)
# [3.9.0](https://github.com/rlespinasse/github-slug-action/compare/v3.8.0...v3.9.0) (2024-01-28)
### Features
* **short_sha:** add a shortened sha commit id ([d77acd4](http://github.com/rlespinasse/github-slug-action/commit/d77acd4f478b6971e0f7b2c9d1d4e721032bc5ab))
* 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))
## [1.0.2](http://github.com/rlespinasse/github-slug-action/compare/1.0.1...1.0.2) (2019-11-06)
# [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
* manage branch with slash properly ([c35fd20](http://github.com/rlespinasse/github-slug-action/commit/c35fd2094f6f0cb6c4858cf6db020eedd535671d))
* 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)
### Features
* add GITHUB_REF_NAME env var ([12a7510](http://github.com/rlespinasse/github-slug-action/commit/12a75106304d45442301df66d3ba38e1ac002649))
## [3.5.1](http://github.com/rlespinasse/github-slug-action/compare/3.5.0...3.5.1) (2021-03-31)
### Bug Fixes
* update dist files ([e6c550f](http://github.com/rlespinasse/github-slug-action/commit/e6c550f88ccca52a82675b89186b6b72864f087c))
# [3.5.0](http://github.com/rlespinasse/github-slug-action/compare/3.4.0...3.5.0) (2021-03-30)
### Features
* allow underscore in slug values ([475d293](http://github.com/rlespinasse/github-slug-action/commit/475d293680b998a3315846828329f05bfff4ac9c))
# [3.4.0](http://github.com/rlespinasse/github-slug-action/compare/3.3.0...3.4.0) (2021-03-02)
### Features
* add _CS suffix to keep value case-sensitive ([6c93fcb](http://github.com/rlespinasse/github-slug-action/commit/6c93fcbf53da9c6415bd7f5e37579b488f34339e))
# [3.3.0](http://github.com/rlespinasse/github-slug-action/compare/3.2.0...3.3.0) (2021-01-25)
### Bug Fixes
* support pull-request for slug and slug url ([78985f8](http://github.com/rlespinasse/github-slug-action/commit/78985f84eca97ef1c5262e85e8a73a277494c4ed))
### Features
* support partial GITHUB_REPOSITORY ([75ce03b](http://github.com/rlespinasse/github-slug-action/commit/75ce03b6a055a3be9d936a3a99c51038bd72298c))
# [3.2.0](http://github.com/rlespinasse/github-slug-action/compare/3.1.0...3.2.0) (2021-01-12)
### Features
* expose GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT ([5b9fe60](http://github.com/rlespinasse/github-slug-action/commit/5b9fe6015d2facc71c81d53bf3b08f04e0f3f743))
# [3.1.0](http://github.com/rlespinasse/github-slug-action/compare/3.0.0...3.1.0) (2020-11-01)
### Features
* **action:** improve marketplace information ([3cddc4f](http://github.com/rlespinasse/github-slug-action/commit/3cddc4f12d7a6fdbb8b1221dc02a2c64670e54bf))
# [3.0.0](http://github.com/rlespinasse/github-slug-action/compare/2.1.0...3.0.0) (2020-10-26)
### Bug Fixes
* upgrade actions core due to CVE fix ([d0549c1](http://github.com/rlespinasse/github-slug-action/commit/d0549c1f85ab9567b439f9d660b01ce1142b9fbe))
### Features
* add support for windows and macos jobs ([13c2f38](http://github.com/rlespinasse/github-slug-action/commit/13c2f38dad5f32529f37c25736412b1e4cf687fe))
### BREAKING CHANGES
* The action implementation move from container action to node.js action
Co-authored-by: Romain Lespinasse <romain.lespinasse@gmail.com>
# [2.1.0](http://github.com/rlespinasse/github-slug-action/compare/2.0.0...2.1.0) (2020-07-28)
### Features
* expose slug variables for github.event.ref ([5a334a8](http://github.com/rlespinasse/github-slug-action/commit/5a334a8573fc27451af5b2a6ee175d8e11579e10))

33
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,33 @@
# How to contribute to GitHub Slug Action
## Did you find a bug
* **Do not open up a GitHub issue if the bug is a security vulnerability**, and instead to refer to our [security policy][1].
* **Ensure the bug was not already reported** by searching on GitHub under [Issues][2].
* If you're unable to find an open issue addressing the problem, [open a 'Bug' issue][4].
Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
## Did you write a patch that fixes a bug
* Open a new GitHub pull request with the patch.
* Ensure the PR description clearly describes the problem and solution.
Include the relevant issue number if applicable.
## Do you intend to add a new feature or change an existing one
* Suggest your change by [opening a 'Feature request' issue][5] and start writing code (following the [developers guide](DEVELOPERS.md))
## Do you have questions about the source code
* [open an issue][3] with your question.
Thanks!
[1]: https://github.com/rlespinasse/github-slug-action/security/policy
[2]: https://github.com/rlespinasse/github-slug-action/issues
[3]: https://github.com/rlespinasse/github-slug-action/issues/new
[4]: https://github.com/rlespinasse/github-slug-action/issues/new?assignees=&labels=bug&template=bug_report.md&title=
[5]: https://github.com/rlespinasse/github-slug-action/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=

38
DEVELOPERS.md Normal file
View File

@@ -0,0 +1,38 @@
# Developers guide
## Prepare
Install the dependencies
```bash
npm install
```
## Develop
Build the typescript and package it for distribution
```bash
npm run build && npm run package
```
Run the tests
```bash
$ npm test
PASS ./index.test.js
✓ throws invalid number (3ms)
wait 500 ms (504ms)
test runs (95ms)
...
```
## Contribute
Before creating a commit, validate your changes and build the associated distribution files
```bash
npm run all
```

View File

@@ -1,8 +0,0 @@
# Container image that runs your code
FROM alpine:3.10
# Copies your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh
# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 Romain Lespinasse
Copyright (c) 2019-2020 Romain Lespinasse
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

215
README.md
View File

@@ -1,37 +1,202 @@
# GitHub Slug action
This action slug and expose some github variables.
This GitHub Action will expose the slug/short values of [some GitHub environment variables][default-environment-variables] inside your GitHub workflow.
`Slug` a variable will
## Table of Contents
- put the variable content in lower case,
- replace any caracter by `-` except `0-9` and `a-z`,
- remove leading and trailing `-` caracter,
- limit the string size to 63 caracters.
- [GitHub Slug action](#github-slug-action)
- [Table of Contents](#table-of-contents)
- [Overview](#overview)
- [Use this action](#use-this-action)
- [Available Environment variables](#available-environment-variables)
- [Enhanced variables](#enhanced-variables)
- [Partial variables](#partial-variables)
- [Slug variables](#slug-variables)
- [Slug URL variables](#slug-url-variables)
- [Short variables](#short-variables)
- [Contribute](#contribute)
- [Troubleshooting](#troubleshooting)
- [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)
- [Thanks for talking about us](#thanks-for-talking-about-us)
Others `Slug`-ish commands are available:
- `Short SHA` a variable will limit the string size to 8 caracters.
## Overview
## Environment Variables
`SLUG` on a variable will
| GitHub environment variable | Slug variable |
| - | - |
| GITHUB_REF | GITHUB_REF_SLUG |
| GITHUB_HEAD_REF | GITHUB_HEAD_REF_SLUG |
| GITHUB_BASE_REF | GITHUB_BASE_REF_SLUG |
- put the variable content in lower case
- replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
- remove leading `-` characters
- limit the string size to 63 characters
- remove trailing `-` characters
| GitHub environment variable | Short variable |
| - | - |
| GITHUB_SHA | GITHUB_SHA_SHORT |
<details>
<summary>Others <b>Slug-ish</b> commands are available</summary>
<p>
## Example usage
- `SLUG_URL` on a variable to have a `slug` variable compliant to be used in an URL
- Like `SLUG` but `.` is also replaced by `-`
- `SHORT` on a variable will limit the string size to 8 characters
- Useful for _sha_ value
- `<KEY>_PART` on a variable will give a part of a variable defined by a key
- Like `GITHUB_REPOSITORY_OWNER_PART` for the owner part of `GITHUB_REPOSITORY`
- `<VAR>_CS` on others variables to keep the value case-sensitive
- Like `GITHUB_REF_SLUG_CS`
</p>
</details>
Additional enhanced environment variables can be compute to help you around GitHub environment variables.
## Use this action
Add this in your workflow
```yaml
- uses: rlespinasse/github-slug-action@master
- name: Print slug variables
run: |
echo ${{ env.GITHUB_REF_SLUG }}
echo ${{ env.GITHUB_HEAD_REF_SLUG }}
echo ${{ env.GITHUB_BASE_REF_SLUG }}
echo ${{ env.GITHUB_SHA_SHORT }}
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
```
Check for more [examples][examples] (OS usage, URL use, ...)
**Tip:** Use [Dependabot][dependabot] to maintain your `github-slug-action` version updated in your GitHub workflows.
## Available Environment variables
**Note**: If you don't find what you search for, read more about [available `GitHub` variables](docs/github-variables.md), and propose a [new custom variable][custom-variable].
### Enhanced variables
- `GITHUB_REF_NAME` will contains the reference name (branch or tag)
- based on `GITHUB_HEAD_REF` in a [`pull-request*`][webhooks-and-events] event context,
- based on `GITHUB_REF` in others event context.
**NOTE:** All enhanced variables are available in all **slug** formats.
### Partial variables
| Variable | Partial version of | Description |
| -------------------------------------------------------------------------------------- | ------------------ | ------------------------------------------------------ |
| [GITHUB_REPOSITORY_OWNER_PART](docs/partial-variables.md#github_repository_owner_part) | GITHUB_REPOSITORY | The Owner part of GITHUB_REPOSITORY variable |
| [GITHUB_REPOSITORY_NAME_PART](docs/partial-variables.md#github_repository_name_part) | GITHUB_REPOSITORY | The Repository name part of GITHUB_REPOSITORY variable |
### Slug variables
**NOTE:** `_CS` suffix available
| Variable | Slug version of | Description |
| ------------------------------------------------------------------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [GITHUB_REPOSITORY_SLUG](docs/slug-variables.md#github_repository_slug) | GITHUB_REPOSITORY | The owner and repository name. |
| [GITHUB_REPOSITORY<br>_OWNER_PART_SLUG](docs/slug-variables.md#github_repository_owner_part_slug) | GITHUB_REPOSITORY_OWNER_PART | The owner name. |
| [GITHUB_REPOSITORY<br>_NAME_PART_SLUG](docs/slug-variables.md#github_repository_name_part_slug) | GITHUB_REPOSITORY_NAME_PART | The repository name. |
| [GITHUB_REF_SLUG](docs/slug-variables.md#github_ref_slug) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
| [GITHUB_HEAD_REF_SLUG](docs/slug-variables.md#github_head_ref_slug) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][event-pull-request] event and forked repositories. |
| [GITHUB_BASE_REF_SLUG](docs/slug-variables.md#github_base_ref_slug) | GITHUB_BASE_REF | The branch of the base repository.<br>Only set for [pull-request][event-pull-request] event and forked repositories. |
| [GITHUB_EVENT_REF_SLUG](docs/slug-variables.md#github_event_ref_slug) | _github.event.ref_ | <br>Only set for [following webhook events][webhooks-and-events]<ul><li>`create`</li><li>`delete`</li></ul> |
### Slug URL variables
**NOTE:** `_CS` suffix available
| Variable | Slug URL version of | Description |
| --------------------------------------------------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [GITHUB_REPOSITORY_SLUG_URL](docs/slug-url-variables.md#github_repository_slug_url) | GITHUB_REPOSITORY | The owner and repository name. |
| [GITHUB_REPOSITORY<br>_OWNER_PART_SLUG_URL](docs/slug-variables.md#github_repository_owner_part_slug_url) | GITHUB_REPOSITORY_OWNER_PART | The owner name. |
| [GITHUB_REPOSITORY<br>_NAME_PART_SLUG_URL](docs/slug-variables.md#github_repository_name_part_slug_url) | GITHUB_REPOSITORY_NAME_PART | The repository name. |
| [GITHUB_REF_SLUG_URL](docs/slug-url-variables.md#github_ref_slug_url) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
| [GITHUB_HEAD_REF_SLUG_URL](docs/slug-url-variables.md#github_head_ref_slug_url) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][webhooks-and-events] event and forked repositories. |
| [GITHUB_BASE_REF_SLUG_URL](docs/slug-url-variables.md#github_base_ref_slug_url) | GITHUB_BASE_REF | The branch of the base repository.<br>Only set for [pull-request][webhooks-and-events] event and forked repositories. |
| [GITHUB_EVENT_REF_SLUG_URL](docs/slug-url-variables.md#github_event_ref_slug_url) | _github.event.ref_ | <br>Only set for [following webhook events][webhooks-and-events]<ul><li>`create`</li><li>`delete`</li></ul> |
### Short variables
| Variable | Short version of | Description |
| -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [GITHUB_SHA_SHORT](docs/short-variables.md#github_sha_short) | GITHUB_SHA | The commit SHA that triggered the workflow. |
| [GITHUB_EVENT<br>_PULL_REQUEST<br>_HEAD_SHA_SHORT](docs/short-variables.md#github_event_pull_request_head_sha_short) | _github.event<br>.pull_request<br>.head.sha_ | The commit SHA on pull request that trigger workflow.<br>Only set for [following webhook events][webhooks-and-events]<ul><li>`pull_request`</li><li>`pull_request_review`</li><li>`pull_request_review_comment`</li><li>`pull_request_target`</li></ul> |
## Contribute
Follow [Developers guide](DEVELOPERS.md)
## Troubleshooting
### One of the environment variables doesn't work as intended
[**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.**
If a variable start to be used as default environment variable, the environment variable may have a different behavior than the expected one.
If this append, the `${{ env.GITHUB_AWESOME_VARIABLE }}` and `$GITHUB_AWESOME_VARIABLE` expression will not works in the same way.
- `${{ 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
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
prefix: CI_
```
Then `${{ env.CI_GITHUB_REF_NAME }}`, and `$CI_GITHUB_REF_NAME` will serve the behavior of this action.
And `$GITHUB_REF_NAME` will serve the behavior of GitHub Action.
### An action could not be found at the URI
If your workflow fail on the `Set up job` task with this kind of log :
```text
Download action repository 'rlespinasse/github-slug-action@master'
##[error]An action could not be found at the URI 'https://api.github.com/repos/rlespinasse/github-slug-action/tarball/master'
```
> The master branch doesn't exists anymore.
>
> The master branch EOL has been set to **2020-10-25** after a 6-month deprecation period (more information on the [EOL issue][issue-15])
Please, use the current branch `v3.x` or a version tag (see [releases pages][releases]) in order to fix your workflow.
## Thanks for talking about us
- [Mettre en place une CI/CD Angular avec GitHub Actions & Netlify][article-1] (in french :fr:)
- [Github Actions : enfin des pipelines accessibles aux développeurs][talk-1] (in french :fr:)
- [Action spotlight by Michael Heap][article-2]
- The next one is you. _Don't hesitate to add youself to this list._
[actions]: https://github.com/rlespinasse/github-slug-action/actions
[license]: https://github.com/rlespinasse/github-slug-action/blob/v3.x/LICENSE
[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=
[releases]: https://github.com/rlespinasse/github-slug-action/releases
[issue-15]: https://github.com/rlespinasse/github-slug-action/issues/15
[issue-104]: https://github.com/rlespinasse/github-slug-action/issues/104
[default-environment-variables]: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
[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
[naming-conventions]: https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables
[article-1]: https://esensconsulting.medium.com/mettre-en-place-une-ci-cd-angular-avec-github-actions-netlify-ca0b59b99ed8
[article-2]: https://michaelheap.com/github-slug-action/
[talk-1]: https://www.youtube.com/watch?v=RHnTJBwcE98

24
SECURITY.md Normal file
View File

@@ -0,0 +1,24 @@
# Security Policy
## Supported Versions and Branches
| Version | Branch | Supported |
|---------|--------|--------------------|
| 3.x | v3.x | :white_check_mark: |
| 2.x | v2.x | :white_check_mark: |
| 1.1.x | v1.1.x | :x: |
| < 1.x | | :x: |
A GitHub repository can used one of the available branches as action inside its workflows.
## Reporting a Vulnerability
You can report a Vulnerability by [my email](mailto:romain.lespinasse@gmail.com).
_Vulnerability stages :_
- Reported,
- Confirmed (or declined),
- Fixed on maintained version series.
After a vulnerability fix, an GitHub issue will be created as document this vulnerability.

28
__tests__/partial.test.ts Normal file
View File

@@ -0,0 +1,28 @@
import {sep} from 'path'
import {get_first_part, get_second_part} from '../src/partial'
function test_get_first_part(
input: string,
separator: string,
expected: string
) {
let actual = get_first_part(input, separator)
expect(actual).toEqual(expected)
}
function test_get_second_part(
input: string,
separator: string,
expected: string
) {
let actual = get_second_part(input, separator)
expect(actual).toEqual(expected)
}
test('get_first_part', () => {
test_get_first_part('first/second', '/', 'first')
})
test('get_second_part', () => {
test_get_second_part('first/second', '/', 'second')
})

View File

@@ -0,0 +1,10 @@
import {shortsha} from '../src/short'
function test_short_sha(input: string, expected: string) {
let actual = shortsha(input)
expect(actual).toEqual(expected)
}
test('short_sha: long hash', () => {
test_short_sha('a35a1a486a260cfd99c5b6f8c6034a2929ba9b3f', 'a35a1a48')
})

73
__tests__/slug.test.ts Normal file
View File

@@ -0,0 +1,73 @@
import {slug, slug_cs} from '../src/slug'
function test_slug(input: string, expected: string) {
let actual = slug(input)
expect(actual).toEqual(expected)
}
function test_slug_cs(input: string, expected: string) {
let actual = slug_cs(input)
expect(actual).toEqual(expected)
}
test('slug: a word', () => {
test_slug('word', 'word')
test_slug_cs('word', 'word')
})
test('slug: a string', () => {
test_slug('basic-string', 'basic-string')
test_slug_cs('basic-string', 'basic-string')
})
test('slug: a string in camel case', () => {
test_slug('camelCase', 'camelcase')
test_slug_cs('camelCase', 'camelCase')
})
test('slug: a path', () => {
test_slug('path/to/something', 'path-to-something')
test_slug_cs('path/to/something', 'path-to-something')
})
test('slug: a number', () => {
test_slug('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('feat-(!è§-character', 'feat------character')
test_slug_cs('feat-(!è§-character', 'feat------character')
})
test('slug: trailing', () => {
test_slug('-feat-trailing-', 'feat-trailing')
test_slug_cs('-feat-trailing-', 'feat-trailing')
})
test('slug: a very long string', () => {
test_slug(
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-feature-very-very-very-very-very-very-very-long'
)
test_slug_cs(
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
)
})
test('slug: short string after trailing', () => {
test_slug(
'-has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-',
'has-an-awesome-feature-very-very-very-very-very-very-very-long'
)
test_slug_cs(
'-has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-',
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
)
})

72
__tests__/slugref.test.ts Normal file
View File

@@ -0,0 +1,72 @@
import {slugref, slugref_cs} from '../src/slug'
function test_slugref(input: string, expected: string) {
let actual = slugref(input)
expect(actual).toEqual(expected)
}
function test_slugref_cs(input: string, expected: string) {
let actual = slugref_cs(input)
expect(actual).toEqual(expected)
}
test('slug_ref:: master branch', () => {
test_slugref('refs/heads/master', 'master')
test_slugref_cs('refs/heads/master', 'master')
})
test('slug_ref: a feature branch', () => {
test_slugref('refs/heads/feat/new_feature', 'feat-new_feature')
test_slugref_cs('refs/heads/feat/new_feature', 'feat-new_feature')
})
test('slug_ref: a fix branch', () => {
test_slugref('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_slugref('refs/tags/v1.0.0', 'v1.0.0')
test_slugref_cs('refs/tags/v1.0.0', 'v1.0.0')
})
test('slug_ref: a complex tag', () => {
test_slugref('refs/tags/product@1.0.0-rc.2', 'product-1.0.0-rc.2')
test_slugref_cs('refs/tags/product@1.0.0-rc.2', 'product-1.0.0-rc.2')
})
test('slug_ref: a reference with upper case letters', () => {
test_slugref('refs/heads/New_Awesome_Product', 'new_awesome_product')
test_slugref_cs('refs/heads/New_Awesome_Product', 'New_Awesome_Product')
})
test('slug_ref: test trailing', () => {
test_slugref('refs/heads/-trailing-feat-', 'trailing-feat')
test_slugref_cs('refs/heads/-trailing-feat-', 'trailing-feat')
})
test('slug_ref: test refs inside string', () => {
test_slugref('refs/heads/-refs/tags/feature/-', 'refs-tags-feature')
test_slugref_cs('refs/heads/-refs/tags/feature/-', 'refs-tags-feature')
})
test('slug_ref: a very long name', () => {
test_slugref(
'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-feature-very-very-very-very-very-very-very-long'
)
test_slugref_cs(
'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
)
})
test('slug_ref: on pull-request ref', () => {
test_slugref('refs/pull/branch', 'branch')
test_slugref_cs('refs/pull/branch', 'branch')
})

57
__tests__/slugurl.test.ts Normal file
View File

@@ -0,0 +1,57 @@
import {slugurl, slugurl_cs} from '../src/slug'
function test_slugurl(input: string, expected: string) {
let actual = slugurl(input)
expect(actual).toEqual(expected)
}
function test_slugurl_cs(input: string, expected: string) {
let actual = slugurl_cs(input)
expect(actual).toEqual(expected)
}
test('slug_url: a word', () => {
test_slugurl('word', 'word')
test_slugurl_cs('word', 'word')
})
test('slug_url: a string', () => {
test_slugurl('basic-string', 'basic-string')
test_slugurl_cs('basic-string', 'basic-string')
})
test('slug_url: a string in camel case', () => {
test_slugurl('camelCase', 'camelcase')
test_slugurl_cs('camelCase', 'camelCase')
})
test('slug_url: a path', () => {
test_slugurl('path/to/something', 'path-to-something')
test_slugurl_cs('path/to/something', 'path-to-something')
})
test('slug_url: a number', () => {
test_slugurl('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_slugurl('.path.to.', 'path-to')
test_slugurl_cs('.path.to.', 'path-to')
})
test('slug_url: a very long string', () => {
test_slugurl(
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-feature-very-very-very-very-very-very-very-long'
)
test_slugurl_cs(
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
)
})

View File

@@ -0,0 +1,72 @@
import {slugurlref, slugurlref_cs} from '../src/slug'
function test_slugurlref(input: string, expected: string) {
let actual = slugurlref(input)
expect(actual).toEqual(expected)
}
function test_slugurlref_cs(input: string, expected: string) {
let actual = slugurlref_cs(input)
expect(actual).toEqual(expected)
}
test('slug_url_ref: master branch', () => {
test_slugurlref('refs/heads/master', 'master')
test_slugurlref_cs('refs/heads/master', 'master')
})
test('slug_url_ref: a feature branch', () => {
test_slugurlref('refs/heads/feat/new_feature', 'feat-new-feature')
test_slugurlref_cs('refs/heads/feat/new_feature', 'feat-new-feature')
})
test('slug_url_ref: a fix branch', () => {
test_slugurlref('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_slugurlref('refs/tags/v1.0.0', 'v1-0-0')
test_slugurlref_cs('refs/tags/v1.0.0', 'v1-0-0')
})
test('slug_url_ref: a complex tag', () => {
test_slugurlref('refs/tags/product@1.0.0-rc.2', 'product-1-0-0-rc-2')
test_slugurlref_cs('refs/tags/product@1.0.0-rc.2', 'product-1-0-0-rc-2')
})
test('slug_url_ref: a reference with upper case letters', () => {
test_slugurlref('refs/heads/New_Awesome_Product', 'new-awesome-product')
test_slugurlref_cs('refs/heads/New_Awesome_Product', 'New-Awesome-Product')
})
test('slug_url_ref: a very long name', () => {
test_slugurlref(
'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-feature-very-very-very-very-very-very-very-long'
)
test_slugurlref_cs(
'refs/heads/has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
'has-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long'
)
})
test('slug_url_ref: test trailing', () => {
test_slugurlref('refs/heads/-an-awesome-Feature-', 'an-awesome-feature')
test_slugurlref_cs('refs/heads/-an-awesome-Feature-', 'an-awesome-Feature')
})
test('slug_url_ref: test trailing with dot', () => {
test_slugurlref('refs/heads/.an-awesome-Feature.', 'an-awesome-feature')
test_slugurlref_cs('refs/heads/.an-awesome-Feature.', 'an-awesome-Feature')
})
test('slug_url_ref: on pull-request ref', () => {
test_slugurlref('refs/pull/branch', 'branch')
test_slugurlref_cs('refs/pull/branch', 'branch')
})

View File

@@ -1,9 +1,9 @@
# action.yml
name: 'GitHub Slug'
description: 'Action to slug and expose some github variables'
name: 'GitHub Slug Action'
description: 'GitHub Action to expose slug value of environment variables inside your GitHub workflow'
author: 'rlespinasse'
runs:
using: 'docker'
image: 'Dockerfile'
using: 'node20'
main: 'dist/index.js'
branding:
icon: 'crop'
color: 'orange'
icon: 'minimize'
color: 'blue'

3337
dist/index.js vendored Normal file

File diff suppressed because it is too large Load Diff

1
dist/index.js.map vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/sourcemap-register.js vendored Normal file

File diff suppressed because one or more lines are too long

96
docs/github-variables.md Normal file
View File

@@ -0,0 +1,96 @@
# Available GitHub Variables
All `GitHub` variables availables in your workflow in addition of ones exposed by this Action
## Table of Contents
- [Available GitHub Variables](#available-github-variables)
- [Table of Contents](#table-of-contents)
- [Default environment variables](#default-environment-variables)
- [Action-managed Environment Variables](#action-managed-environment-variables)
- [Variables from events](#variables-from-events)
- [Action-managed Event Variables](#action-managed-event-variables)
- [create](#create)
- [delete](#delete)
- [pull_request](#pull_request)
- [pull_request_review](#pull_request_review)
- [pull_request_review_comment](#pull_request_review_comment)
- [pull_request_target](#pull_request_target)
## Default environment variables
Read the official documentation about [Default environment variables][1].
### Action-managed Environment Variables
| Action-managed Variables | Can be suffix by |
| ------------------------ | -------------------- |
| GITHUB_REPOSITORY | `_SLUG`, `_SLUG_URL` |
| GITHUB_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_HEAD_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_BASE_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_SHA | `_SHORT` |
## Variables from events
Read the official documentation about [Events that trigger workflows][2].
### Action-managed Event Variables
#### create
Checkout [create][3] webhook payload content
| Action-managed Variables | Available as |
| ------------------------ | ------------------------- |
| github.event.ref | GITHUB_EVENT_REF_SLUG |
| github.event.ref | GITHUB_EVENT_REF_SLUG_URL |
#### delete
Checkout [delete][4] webhook payload content
| Action-managed Variables | Available as |
| ------------------------ | ------------------------- |
| github.event.ref | GITHUB_EVENT_REF_SLUG |
| github.event.ref | GITHUB_EVENT_REF_SLUG_URL |
#### pull_request
Checkout [pull_request][5] webhook payload content
| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
#### pull_request_review
Checkout [pull_request_review][6] webhook payload content
| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
#### pull_request_review_comment
Checkout [pull_request_review_comment][7] webhook payload content
| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
#### pull_request_target
Checkout [pull_request][5] webhook payload content
| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
[1]: https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
[2]: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
[3]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#create
[4]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#delete
[5]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request
[6]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request_review
[7]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request_review_comment

28
docs/partial-variables.md Normal file
View File

@@ -0,0 +1,28 @@
# Partial Variables
## Table of Contents
- [Partial Variables](#partial-variables)
- [Table of Contents](#table-of-contents)
- [GITHUB_REPOSITORY_OWNER_PART](#github_repository_owner_part)
- [GITHUB_REPOSITORY_NAME_PART](#github_repository_name_part)
## GITHUB_REPOSITORY_OWNER_PART
Owner part of the environment variable **GITHUB_REPOSITORY**
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_OWNER_PART |
| ---------------------------- | ---------------------------- |
| octocat/Hello-World | octocat |
| rlespinasse/Hello-World.go | rlespinasse |
| AnotherPerson/SomeRepository | AnotherPerson |
## GITHUB_REPOSITORY_NAME_PART
Repository name part of the environment variable **GITHUB_REPOSITORY**
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_NAME_PART |
| ---------------------------- | --------------------------- |
| octocat/Hello-World | Hello-World |
| rlespinasse/Hello-World.go | Hello-World.go |
| AnotherPerson/SomeRepository | SomeRepository |

27
docs/short-variables.md Normal file
View File

@@ -0,0 +1,27 @@
# Short Variables
## Table of Contents
- [Short Variables](#short-variables)
- [Table of Contents](#table-of-contents)
- [GITHUB_SHA_SHORT](#github_sha_short)
- [GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT](#github_event_pull_request_head_sha_short)
## GITHUB_SHA_SHORT
Short the environment variable **GITHUB_SHA**
The commit SHA that triggered the workflow
| GITHUB_SHA | GITHUB_SHA_SHORT |
| ---------------------------------------- | ---------------- |
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |
## GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT
Short the value of `github.event.pull_request.head.sha` that represents the last commit
used for triggering an action for a pull request.
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
| ---------------------------------------- | ---------------------------------------- |
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |

109
docs/slug-url-variables.md Normal file
View File

@@ -0,0 +1,109 @@
# Slug URL Variables
## Table of Contents
- [Slug URL Variables](#slug-url-variables)
- [Table of Contents](#table-of-contents)
- [GITHUB_REPOSITORY_SLUG_URL](#github_repository_slug_url)
- [GITHUB_REPOSITORY_OWNER_PART_SLUG_URL](#github_repository_owner_part_slug_url)
- [GITHUB_REPOSITORY_NAME_PART_SLUG_URL](#github_repository_name_part_slug_url)
- [GITHUB_REF_SLUG_URL](#github_ref_slug_url)
- [GITHUB_HEAD_REF_SLUG_URL](#github_head_ref_slug_url)
- [GITHUB_BASE_REF_SLUG_URL](#github_base_ref_slug_url)
- [GITHUB_EVENT_REF_SLUG_URL](#github_event_ref_slug_url)
## GITHUB_REPOSITORY_SLUG_URL
Slug URL the environment variable **GITHUB_REPOSITORY**
The owner and repository name.
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG_URL |
| ---------------------------- | ---------------------------- |
| octocat/Hello-World | octocat-hello-world |
| rlespinasse/Hello-World.go | rlespinasse-hello-world-go |
| AnotherPerson/SomeRepository | anotherperson-somerepository |
## GITHUB_REPOSITORY_OWNER_PART_SLUG_URL
Slug URL the environment variable [GITHUB_REPOSITORY_OWNER_PART](partial-variables.md#github_repository_owner_part)
The Owner part of **GITHUB_REPOSITORY** variable.
| GITHUB_REPOSITORY_OWNER_PART | GITHUB_REPOSITORY_OWNER_PART_SLUG_URL |
| ---------------------------- | ------------------------------------- |
| octocat | octocat |
| rlespinasse | rlespinasse |
| AnotherPerson | anotherperson |
## GITHUB_REPOSITORY_NAME_PART_SLUG_URL
Slug URL the environment variable [GITHUB_REPOSITORY_NAME_PART](partial-variables.md#github_repository_name_part)
The Repository name part of **GITHUB_REPOSITORY** variable.
| GITHUB_REPOSITORY_NAME_PART | GITHUB_REPOSITORY_NAME_PART_SLUG_URL |
| --------------------------- | ------------------------------------ |
| Hello-World | hello-world |
| Hello-World.go | hello-world-go |
| SomeRepository | somerepository |
## GITHUB_REF_SLUG_URL
Slug URL the environment variable **GITHUB_REF**
The branch or tag ref that triggered the workflow.
_If neither a branch or tag is available for the event type, the variable will not exist._
| GITHUB_REF | GITHUB_REF_SLUG_URL |
| ------------------------------ | ------------------- |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/tags/v1.0.0 | v1-0-0 |
| refs/pull/42-merge | 42-merge |
| refs/tags/product@1.0.0-rc.2 | product-1-0-0-rc-2 |
| refs/heads/New_Awesome_Product | new-awesome-product |
**Caution**: From v3.0.0 to v3.2.0 included, `GITHUB_REF_SLUG` have the wrong value on `pull_request` event.
`refs/pull/42-merge` become `refs-pull-42-merge` instead of `42-merge`. The bug have been fixed in v3.3.0
## GITHUB_HEAD_REF_SLUG_URL
Slug URL the environment variable **GITHUB_HEAD_REF**
The branch of the head repository.
_Only set for forked repositories._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG_URL |
| ------------------------------ | ------------------------ |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/heads/New_Awesome_Product | new-awesome-product |
## GITHUB_BASE_REF_SLUG_URL
Slug URL the environment variable **GITHUB_BASE_REF**
The branch of the base repository.
_Only set for forked repositories._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG_URL |
| ------------------------------ | ------------------------ |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/heads/New_Awesome_Product | new-awesome-product |
## GITHUB_EVENT_REF_SLUG_URL
Slug URL the variable **github.event.ref**
The git reference resource associated to triggered webhook.
_Only set for [`create`, and `delete`][1] events._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG_URL |
| ------------------------------ | ------------------------ |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/heads/New_Awesome_Product | new-awesome-product |
[1]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads

105
docs/slug-variables.md Normal file
View File

@@ -0,0 +1,105 @@
# Slug Variables
## Table of Contents
- [Slug Variables](#slug-variables)
- [Table of Contents](#table-of-contents)
- [GITHUB_REPOSITORY_SLUG](#github_repository_slug)
- [GITHUB_REPOSITORY_OWNER_PART_SLUG](#github_repository_owner_part_slug)
- [GITHUB_REPOSITORY_NAME_PART_SLUG](#github_repository_name_part_slug)
- [GITHUB_REF_SLUG](#github_ref_slug)
- [GITHUB_HEAD_REF_SLUG](#github_head_ref_slug)
- [GITHUB_BASE_REF_SLUG](#github_base_ref_slug)
- [GITHUB_EVENT_REF_SLUG](#github_event_ref_slug)
## GITHUB_REPOSITORY_SLUG
Slug the environment variable **GITHUB_REPOSITORY**
The owner and repository name.
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG |
| ---------------------------- | ---------------------------- |
| octocat/Hello-World | octocat-hello-world |
| rlespinasse/Hello-World.go | rlespinasse-hello-world.go |
| AnotherPerson/SomeRepository | anotherperson-somerepository |
## GITHUB_REPOSITORY_OWNER_PART_SLUG
Slug the environment variable [GITHUB_REPOSITORY_OWNER_PART](partial-variables.md#github_repository_owner_part)
The Owner part of **GITHUB_REPOSITORY** variable.
| GITHUB_REPOSITORY_OWNER_PART | GITHUB_REPOSITORY_OWNER_PART_SLUG |
| ---------------------------- | --------------------------------- |
| octocat | octocat |
| rlespinasse | rlespinasse |
| AnotherPerson | anotherperson |
## GITHUB_REPOSITORY_NAME_PART_SLUG
Slug the environment variable [GITHUB_REPOSITORY_NAME_PART](partial-variables.md#github_repository_name_part)
The Repository name part of **GITHUB_REPOSITORY** variable.
| GITHUB_REPOSITORY_NAME_PART | GITHUB_REPOSITORY_NAME_PART_SLUG |
| --------------------------- | -------------------------------- |
| Hello-World | hello-world |
| Hello-World.go | hello-world.go |
| SomeRepository | somerepository |
## GITHUB_REF_SLUG
Slug the environment variable **GITHUB_REF**
The branch or tag ref that triggered the workflow.
_If neither a branch or tag is available for the event type, the variable will not exist._
| GITHUB_REF | GITHUB_REF_SLUG |
| ------------------------------ | ------------------- |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/tags/v1.0.0 | v1.0.0 |
| refs/tags/product@1.0.0-rc.2 | product-1.0.0-rc.2 |
| refs/heads/New_Awesome_Product | new-awesome-product |
## GITHUB_HEAD_REF_SLUG
Slug the environment variable **GITHUB_HEAD_REF**
The branch of the head repository.
_Only set for [`pull-request`][1] event and forked repositories._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG |
| ------------------------------ | -------------------- |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/heads/New_Awesome_Product | new-awesome-product |
## GITHUB_BASE_REF_SLUG
Slug the environment variable **GITHUB_BASE_REF**
The branch of the base repository.
_Only set for [`pull-request`][1] event and forked repositories._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG |
| ------------------------------ | -------------------- |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/heads/New_Awesome_Product | new-awesome-product |
## GITHUB_EVENT_REF_SLUG
Slug the variable **github.event.ref**
The git reference resource associated to triggered webhook.
_Only set for [`create`, and `delete`][1] events._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG |
| ------------------------------ | -------------------- |
| refs/heads/main | main |
| refs/heads/feat/new_feature | feat-new-feature |
| refs/heads/New_Awesome_Product | new-awesome-product |
[1]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads

View File

@@ -1,18 +0,0 @@
#!/bin/sh -l
slug_ref() {
echo "$1" \
| tr "[:upper:]" "[:lower:]" \
| sed -r 's#refs/[^\/]*/##;s/[~\^]+//g;s/[^a-zA-Z0-9]+/-/g;s/^-+\|-+$//g;s/^-*//;s/-*$//' \
| cut -c1-63
}
short_sha(){
echo "$1" \
| cut -c1-8
}
echo ::set-env name=GITHUB_REF_SLUG::"$(slug_ref "$GITHUB_REF")"
echo ::set-env name=GITHUB_HEAD_REF_SLUG::"$(slug_ref "$GITHUB_HEAD_REF")"
echo ::set-env name=GITHUB_BASE_REF_SLUG::"$(slug_ref "$GITHUB_BASE_REF")"
echo ::set-env name=GITHUB_SHA_SHORT::"$(short_sha "$GITHUB_SHA")"

34
examples/linux-usage.yml Normal file
View File

@@ -0,0 +1,34 @@
name: Linux usage
on: push
jobs:
usage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/github-slug-action@v3.x
- name: Output
run: |
echo "Partial variables"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART }}"
echo "Slug variables"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}"
echo " ref : ${{ env.GITHUB_REF_SLUG }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
echo "Slug URL variables"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}"
echo " ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
echo "Short SHA variables"
echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"

34
examples/macos-usage.yml Normal file
View File

@@ -0,0 +1,34 @@
name: MacOS usage
on: push
jobs:
usage:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/github-slug-action@v3.x
- name: Output
run: |
echo "Partial variables"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART }}"
echo "Slug variables"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}"
echo " ref : ${{ env.GITHUB_REF_SLUG }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
echo "Slug URL variables"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}"
echo " ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
echo "Short SHA variables"
echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"

20
examples/url-use.yml Normal file
View File

@@ -0,0 +1,20 @@
name: URL use
on: push
jobs:
as_subdomain:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/github-slug-action@v3.x
- run: |
./deploy-application.sh --url "https://${{ env.GITHUB_REF_SLUG_URL }}.staging.app.example.com"
as_resource_path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/github-slug-action@v3.x
- run: |
./deploy-application.sh --url "https://staging.app.example.com/${{ env.GITHUB_REF_SLUG_URL }}"

View File

@@ -0,0 +1,34 @@
name: Windows usage
on: push
jobs:
usage:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: rlespinasse/github-slug-action@v3.x
- name: Output
run: |
echo "Partial variables"
echo " repository owner : $env:GITHUB_REPOSITORY_OWNER_PART"
echo " repository name : $env:GITHUB_REPOSITORY_NAME_PART"
echo "Slug variables"
echo " repository : $env:GITHUB_REPOSITORY_SLUG"
echo " repository owner : $env:GITHUB_REPOSITORY_OWNER_PART_SLUG"
echo " repository name : $env:GITHUB_REPOSITORY_NAME_PART_SLUG"
echo " ref : $env:GITHUB_REF_SLUG"
echo " head ref : $env:GITHUB_HEAD_REF_SLUG"
echo " base ref : $env:GITHUB_BASE_REF_SLUG"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG"
echo "Slug URL variables"
echo " repository : $env:GITHUB_REPOSITORY_SLUG_URL"
echo " repository owner : $env:GITHUB_REPOSITORY_OWNER_PART_SLUG_URL"
echo " repository name : $env:GITHUB_REPOSITORY_NAME_PART_SLUG_URL"
echo " ref : $env:GITHUB_REF_SLUG_URL"
echo " head ref : $env:GITHUB_HEAD_REF_SLUG_URL"
echo " base ref : $env:GITHUB_BASE_REF_SLUG_URL"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL"
echo "Short SHA variables"
echo " sha : $env:GITHUB_SHA_SHORT"
echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT"

11
jest.config.js Normal file
View File

@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

18526
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,28 +1,72 @@
{
"name": "github-slug-action",
"version": "1.0.1",
"version": "0.0.0",
"license": "MIT",
"private": true,
"description": "Github slug action",
"main": "lib/main.js",
"scripts": {
"test": "docker run -w /workdir -v $(pwd):/workdir dduportal/bats:latest ./tests",
"release": "semantic-release"
"release": "semantic-release",
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map",
"test": "jest",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
},
"repository": {
"type": "git",
"url": "http://github.com/rlespinasse/github-slug-action.git"
"url": "https://github.com/rlespinasse/github-slug-action.git"
},
"keywords": [
"actions",
"node",
"setup"
],
"author": "rlespinasse",
"dependencies": {
"@actions/core": "^1.10.0"
},
"devDependencies": {
"@semantic-release/changelog": "^3.0.5",
"@semantic-release/git": "^7.0.18",
"semantic-release": "^15.13.30"
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/exec": "^6.0.0",
"@semantic-release/git": "^10.0.1",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.25",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.0.1",
"eslint-plugin-github": "^4.3.7",
"eslint-plugin-jest": "^23.20.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"js-yaml": "^3.14.1",
"prettier": "^2.7.1",
"semantic-release": "^19.0.3",
"ts-jest": "^26.5.6",
"typescript": "^4.2.0"
},
"files": [
"/dist"
],
"release": {
"tagFormat": "${version}",
"tagFormat": "v${version}",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/exec",
{
"prepareCmd": "git add dist"
}
],
"@semantic-release/git",
"@semantic-release/github"
],
"branches": [
"v3.x"
]
}
}

401
src/main.ts Normal file
View File

@@ -0,0 +1,401 @@
import * as core from '@actions/core'
import {
removeRef,
slug,
slug_cs,
slugref,
slugref_cs,
slugurl,
slugurl_cs,
slugurlref,
slugurlref_cs
} from './slug'
import {shortsha} from './short'
import {get_first_part, get_second_part} from './partial'
const SEPARATOR = '/'
/**
* Inputs environments variables keys from Github actions job
* see https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
*/
const GITHUB_REPOSITORY = 'GITHUB_REPOSITORY'
const GITHUB_REF = 'GITHUB_REF'
const GITHUB_HEAD_REF = 'GITHUB_HEAD_REF'
const GITHUB_BASE_REF = 'GITHUB_BASE_REF'
const GITHUB_SHA = 'GITHUB_SHA'
const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH'
/**
* Partial outputs environments variables keys
*/
const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART'
const GITHUB_REPOSITORY_NAME_PART = 'GITHUB_REPOSITORY_NAME_PART'
/**
* New environments variables keys
*/
const GITHUB_REF_NAME = 'GITHUB_REF_NAME'
/**
* Slugged outputs environments variables keys
*/
const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG'
const GITHUB_REPOSITORY_SLUG_CS = 'GITHUB_REPOSITORY_SLUG_CS'
const GITHUB_REPOSITORY_OWNER_PART_SLUG = 'GITHUB_REPOSITORY_OWNER_PART_SLUG'
const GITHUB_REPOSITORY_OWNER_PART_SLUG_CS =
'GITHUB_REPOSITORY_OWNER_PART_SLUG_CS'
const GITHUB_REPOSITORY_NAME_PART_SLUG = 'GITHUB_REPOSITORY_NAME_PART_SLUG'
const GITHUB_REPOSITORY_NAME_PART_SLUG_CS =
'GITHUB_REPOSITORY_NAME_PART_SLUG_CS'
const GITHUB_REF_SLUG = 'GITHUB_REF_SLUG'
const GITHUB_REF_SLUG_CS = 'GITHUB_REF_SLUG_CS'
const GITHUB_HEAD_REF_SLUG = 'GITHUB_HEAD_REF_SLUG'
const GITHUB_HEAD_REF_SLUG_CS = 'GITHUB_HEAD_REF_SLUG_CS'
const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG'
const GITHUB_BASE_REF_SLUG_CS = 'GITHUB_BASE_REF_SLUG_CS'
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG'
const GITHUB_EVENT_REF_SLUG_CS = 'GITHUB_EVENT_REF_SLUG_CS'
const GITHUB_REF_NAME_SLUG = 'GITHUB_REF_NAME_SLUG'
const GITHUB_REF_NAME_SLUG_CS = 'GITHUB_REF_NAME_SLUG_CS'
/**
* URL-Slugged outputs environments variables keys
*/
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL'
const GITHUB_REPOSITORY_SLUG_URL_CS = 'GITHUB_REPOSITORY_SLUG_URL_CS'
const GITHUB_REPOSITORY_OWNER_PART_SLUG_URL =
'GITHUB_REPOSITORY_OWNER_PART_SLUG_URL'
const GITHUB_REPOSITORY_OWNER_PART_SLUG_URL_CS =
'GITHUB_REPOSITORY_OWNER_PART_SLUG_URL_CS'
const GITHUB_REPOSITORY_NAME_PART_SLUG_URL =
'GITHUB_REPOSITORY_NAME_PART_SLUG_URL'
const GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS =
'GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS'
const GITHUB_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL'
const GITHUB_REF_SLUG_URL_CS = 'GITHUB_REF_SLUG_URL_CS'
const GITHUB_HEAD_REF_SLUG_URL = 'GITHUB_HEAD_REF_SLUG_URL'
const GITHUB_HEAD_REF_SLUG_URL_CS = 'GITHUB_HEAD_REF_SLUG_URL_CS'
const GITHUB_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL'
const GITHUB_BASE_REF_SLUG_URL_CS = 'GITHUB_BASE_REF_SLUG_URL_CS'
const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL'
const GITHUB_EVENT_REF_SLUG_URL_CS = 'GITHUB_EVENT_REF_SLUG_URL_CS'
const GITHUB_REF_NAME_SLUG_URL = 'GITHUB_REF_NAME_SLUG_URL'
const GITHUB_REF_NAME_SLUG_URL_CS = 'GITHUB_REF_NAME_SLUG_URL_CS'
/**
* Shorted outputs environments variables keys
*/
const GITHUB_SHA_SHORT = 'GITHUB_SHA_SHORT'
const GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT =
'GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT'
async function run(): Promise<void> {
try {
const eventPath = process.env[GITHUB_EVENT_PATH]
if (eventPath) {
const eventData = await import(eventPath)
if (eventData.hasOwnProperty('ref')) {
core.exportVariable(GITHUB_EVENT_REF_SLUG, slugref(eventData.ref))
core.exportVariable(GITHUB_EVENT_REF_SLUG_CS, slugref_cs(eventData.ref))
core.exportVariable(
GITHUB_EVENT_REF_SLUG_URL,
slugurlref(eventData.ref)
)
core.exportVariable(
GITHUB_EVENT_REF_SLUG_URL_CS,
slugurlref_cs(eventData.ref)
)
} else if (eventData.hasOwnProperty('pull_request')) {
core.exportVariable(
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT,
shortsha(eventData.pull_request.head.sha)
)
}
}
exportFirstPart(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_OWNER_PART)
exportSecondPart(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_NAME_PART)
exportSlug(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG)
exportSlugCS(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_CS)
exportFirstPartSlug(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_OWNER_PART_SLUG
)
exportFirstPartSlugCS(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_OWNER_PART_SLUG_CS
)
exportSecondPartSlug(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_NAME_PART_SLUG
)
exportSecondPartSlugCS(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_NAME_PART_SLUG_CS
)
exportSlugUrl(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_URL)
exportSlugUrlCS(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_URL_CS)
exportFirstPartSlugUrl(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_OWNER_PART_SLUG_URL
)
exportFirstPartSlugUrlCS(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_OWNER_PART_SLUG_URL_CS
)
exportSecondPartSlugUrl(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_NAME_PART_SLUG_URL
)
exportSecondPartSlugUrlCS(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS
)
exportSlugRef(GITHUB_REF, GITHUB_REF_SLUG)
exportSlugRefCS(GITHUB_REF, GITHUB_REF_SLUG_CS)
exportSlugRef(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG)
exportSlugRefCS(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG_CS)
exportSlugRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG)
exportSlugRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_CS)
exportSlugUrlRef(GITHUB_REF, GITHUB_REF_SLUG_URL)
exportSlugUrlRefCS(GITHUB_REF, GITHUB_REF_SLUG_URL_CS)
exportSlugUrlRef(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG_URL)
exportSlugUrlRefCS(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG_URL_CS)
exportSlugUrlRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL)
exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS)
exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT)
exportBranchName()
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
}
function exportFirstPart(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, get_first_part(envVar, separator))
}
}
function exportSecondPart(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, get_second_part(envVar, separator))
}
}
function exportSlugCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, slug_cs(envVar))
}
}
function exportSlug(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, slug(envVar))
}
}
function exportFirstPartSlugCS(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_first_part(envVar, separator)
core.exportVariable(outputKey, slug_cs(value))
}
}
function exportFirstPartSlug(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_first_part(envVar, separator)
core.exportVariable(outputKey, slug(value))
}
}
function exportSecondPartSlugCS(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_second_part(envVar, separator)
core.exportVariable(outputKey, slug_cs(value))
}
}
function exportSecondPartSlug(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_second_part(envVar, separator)
core.exportVariable(outputKey, slug(value))
}
}
function exportSlugRefCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
exportSlugRefCSValue(envVar, outputKey)
}
}
function exportSlugRefCSValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugref_cs(envVar))
}
function exportSlugRef(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
exportSlugRefValue(envVar, outputKey)
}
}
function exportSlugRefValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugref(envVar))
}
function exportSlugUrlCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, slugurl_cs(envVar))
}
}
function exportSlugUrl(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, slugurl(envVar))
}
}
function exportFirstPartSlugUrlCS(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_first_part(envVar, separator)
core.exportVariable(outputKey, slugurl_cs(value))
}
}
function exportFirstPartSlugUrl(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_first_part(envVar, separator)
core.exportVariable(outputKey, slugurl(value))
}
}
function exportSecondPartSlugUrlCS(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_second_part(envVar, separator)
core.exportVariable(outputKey, slugurl_cs(value))
}
}
function exportSecondPartSlugUrl(
inputKey: string,
separator: string,
outputKey: string
): void {
const envVar = process.env[inputKey]
if (envVar) {
const value = get_second_part(envVar, separator)
core.exportVariable(outputKey, slugurl(value))
}
}
function exportSlugUrlRefCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
exportSlugUrlRefCSValue(envVar, outputKey)
}
}
function exportSlugUrlRefCSValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugurlref_cs(envVar))
}
function exportSlugUrlRef(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
exportSlugUrlRefValue(envVar, outputKey)
}
}
function exportSlugUrlRefValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugurlref(envVar))
}
function exportShortSha(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey]
if (envVar) {
core.exportVariable(outputKey, shortsha(envVar))
}
}
function exportBranchName(): void {
//GITHUB_HEAD_REF is only set for pull request events https://docs.github.com/en/actions/reference/environment-variables
const isPullRequest = !!process.env.GITHUB_HEAD_REF
let refName
if (isPullRequest) {
refName = process.env.GITHUB_HEAD_REF
} else {
refName = process.env.GITHUB_REF
}
if (refName) {
core.exportVariable(GITHUB_REF_NAME, removeRef(refName))
exportSlugRefValue(refName, GITHUB_REF_NAME_SLUG)
exportSlugRefCSValue(refName, GITHUB_REF_NAME_SLUG_CS)
exportSlugUrlRefValue(refName, GITHUB_REF_NAME_SLUG_URL)
exportSlugUrlRefCSValue(refName, GITHUB_REF_NAME_SLUG_URL_CS)
}
}
run()

17
src/partial.ts Normal file
View File

@@ -0,0 +1,17 @@
/**
* Get the first part of envVar
* @param envVar to be split
* @param separator of the split
*/
export function get_first_part(envVar: string, separator: string): string {
return envVar.replace(RegExp(`${separator}.*$`), '')
}
/**
* Get the second part of envVar
* @param envVar to be split
* @param separator of the split
*/
export function get_second_part(envVar: string, separator: string): string {
return envVar.replace(RegExp(`^.*${separator}`), '')
}

10
src/short.ts Normal file
View File

@@ -0,0 +1,10 @@
const SHORT_SHA_SIZE = 8
/**
* slug will take envVar and then :
* - limit the string size to 8 characters
* @param envVar to be slugged
*/
export function shortsha(envVar: string): string {
return envVar.substring(0, SHORT_SHA_SIZE)
}

129
src/slug.ts Normal file
View File

@@ -0,0 +1,129 @@
const MAX_SLUG_STRING_SIZE = 63
/**
* slug_cs will take envVar and then :
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slug_cs(envVar: string): string {
return removeTrailingHyphens(
removeLeadingHyphens(replaceAnyNonAlphanumericCharacter(envVar)).substring(
0,
MAX_SLUG_STRING_SIZE
)
)
}
/**
* slug will take envVar and then :
* - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slug(envVar: string): string {
return slug_cs(envVar.toLowerCase())
}
/**
* slugref_cs will take envVar and then :
* - remove refs/(heads|tags|pull)/
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slugref_cs(envVar: string): string {
return slug_cs(removeRef(envVar))
}
/**
* slugref will take envVar and then :
* - remove refs/(heads|tags|pull)/
* - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slugref(envVar: string): string {
return slugref_cs(envVar.toLowerCase())
}
/**
* slugurl_cs will take envVar and then :
* - replace any character by `-` except `0-9`, `a-z`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slugurl_cs(envVar: string): string {
return slug_cs(replaceAnyNonUrlCharactersWithHyphen(envVar))
}
/**
* slugurl will take envVar and then :
* - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slugurl(envVar: string): string {
return slugurl_cs(envVar.toLowerCase())
}
/**
* slugurlref_cs will take envVar and then :
* - remove refs/(heads|tags|pull)/
* - replace any character by `-` except `0-9`, `a-z`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slugurlref_cs(envVar: string): string {
return slugurl_cs(removeRef(envVar))
}
/**
* slugurlref will take envVar and then :
* - remove refs/(heads|tags|pull)/
* - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`
* - remove leading `-` characters
* - limit the string size to 63 characters
* - remove trailing `-` characters
* @param envVar to be slugged
*/
export function slugurlref(envVar: string): string {
return slugurlref_cs(envVar.toLowerCase())
}
function removeLeadingHyphens(envVar: string): string {
return envVar.replace(RegExp('^-*', 'g'), '')
}
function removeTrailingHyphens(envVar: string): string {
return envVar.replace(RegExp('-*$', 'g'), '')
}
function replaceAnyNonAlphanumericCharacter(envVar: string): string {
return envVar.replace(RegExp('[^a-zA-Z0-9._]', 'g'), '-')
}
function replaceAnyNonUrlCharactersWithHyphen(envVar: string): string {
return envVar.replace(RegExp('[._]', 'g'), '-')
}
export function removeRef(envVar: string): string {
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '')
}

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env bats
@test "Short long hash" {
test_short_sha \
"a35a1a486a260cfd99c5b6f8c6034a2929ba9b3f" \
"a35a1a48"
}
# Load sluf_ref function
source entrypoint.sh > /dev/null 2>&1
test_short_sha(){
given="${1}"
expected="${2}"
actual="$(short_sha ${given})"
echo "expected : [${expected}], actual : [${actual}]"
[ "${actual}" == "${expected}" ]
}

View File

@@ -1,55 +0,0 @@
#!/usr/bin/env bats
@test "Slug master branch" {
test_sluf_ref \
"refs/heads/master" \
"master"
}
@test "Slug a feature branch" {
test_sluf_ref \
"refs/heads/feat/new_feature" \
"feat-new-feature"
}
@test "Slug a fix branch" {
test_sluf_ref \
"refs/heads/fix/issue_number" \
"fix-issue-number"
}
@test "Slug a simple tag" {
test_sluf_ref \
"refs/tags/v1.0.0" \
"v1-0-0"
}
@test "Slug a complex tag" {
test_sluf_ref \
"refs/tags/product@1.0.0-rc.2" \
"product-1-0-0-rc-2"
}
@test "Slug a reference with upper case letters" {
test_sluf_ref \
"refs/heads/New_Awesome_Product" \
"new-awesome-product"
}
@test "Slug a very long name" {
test_sluf_ref \
"refs/heads/an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters" \
"an-awesome-feature-very-very-very-very-very-very-very-long-more"
}
# Load sluf_ref function
source entrypoint.sh > /dev/null 2>&1
test_sluf_ref() {
given="${1}"
expected="${2}"
actual="$(slug_ref \"${given}\")"
echo "expected : [${expected}], actual : [${actual}]"
[ "${actual}" == "${expected}" ]
}

12
tsconfig.json Normal file
View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}