Compare commits

...

14 Commits
3.4.0 ... 3.6.0

Author SHA1 Message Date
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
16 changed files with 2753 additions and 20865 deletions

View File

@@ -1,43 +1,21 @@
name: Build name: Build OS-Dependent
on: on:
push: push:
branches: branches:
- v3.x - v3.x
pull_request: pull_request:
branches:
- v3.x
jobs: jobs:
build: use-on-linux:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- run: | - run: npm install
npm ci - run: npm run all
- run: |
npm run all
- uses: cycjimmy/semantic-release-action@v2
with:
semantic_version: 17.3.4
branches: |
[
'v2.x',
'v3.x'
]
extra_plugins: |
@semantic-release/changelog@5.0.1
@semantic-release/git@9.0.0
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
os-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
steps:
- uses: actions/checkout@v2
- uses: ./ - uses: ./
- name: Output - name: Output
run: | run: |
@@ -63,6 +41,10 @@ jobs:
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : ${{ env.GITHUB_SHA_SHORT }}" echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}" echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
echo "Branch Name"
echo " raw : ${{ env.GITHUB_BRANCH_NAME }}"
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG }}"
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL }}"
- name: Case Sensitive Output - name: Case Sensitive Output
run: | run: |
echo "Slug variables" echo "Slug variables"
@@ -81,11 +63,75 @@ jobs:
echo " head ref : ${{ env.GITHUB_HEAD_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 " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL_CS }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}"
echo "Branch Name"
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG_CS }}"
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL_CS }}"
win-test: use-on-macos:
runs-on: macos-latest
steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2
- run: npm install
- run: npm run all
- uses: ./
- 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 }}"
echo "Branch Name"
echo " raw : ${{ env.GITHUB_BRANCH_NAME }}"
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG }}"
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL }}"
- name: Case Sensitive Output
run: |
echo "Slug variables"
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 }}"
echo "Slug URL variables"
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 }}"
echo "Branch Name"
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG_CS }}"
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL_CS }}"
use-on-windows:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- run: npm install
- run: npm run all
- uses: ./ - uses: ./
- name: Output - name: Output
run: | run: |
@@ -111,6 +157,10 @@ jobs:
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : $env:GITHUB_SHA_SHORT" echo " sha : $env:GITHUB_SHA_SHORT"
echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT" echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT"
echo "Branch Name"
echo " raw : $env:GITHUB_BRANCH_NAME"
echo " slug : $env:GITHUB_BRANCH_NAME_SLUG"
echo " slug url : $env:GITHUB_BRANCH_NAME_SLUG_URL"
- name: Case Sensitive Output - name: Case Sensitive Output
run: | run: |
echo "Slug variables" echo "Slug variables"
@@ -129,3 +179,6 @@ jobs:
echo " head ref : $env:GITHUB_HEAD_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 " base ref : $env:GITHUB_BASE_REF_SLUG_URL_CS"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL_CS" echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL_CS"
echo "Branch Name"
echo " slug : $env:GITHUB_BRANCH_NAME_SLUG_CS"
echo " slug url : $env:GITHUB_BRANCH_NAME_SLUG_URL_CS"

View File

@@ -1,34 +1,28 @@
name: "CodeQL" name: CodeQL
on: on:
push: push:
branches: [ v3.x, v*.x ] branches:
- v3.x
pull_request: pull_request:
branches: [ v3.x ] branches:
- v3.x
schedule: schedule:
- cron: '0 6 * * 1' - cron: "0 6 * * 1"
jobs: jobs:
analyze: analyse:
name: Analyze name: analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
language: [ 'javascript' ] language: ["javascript"]
steps: steps:
- name: Checkout repository - uses: technote-space/auto-cancel-redundant-workflow@v1
uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: github/codeql-action/init@v1
- name: Initialize CodeQL with:
uses: github/codeql-action/init@v1 languages: ${{ matrix.language }}
with: - uses: github/codeql-action/autobuild@v1
languages: ${{ matrix.language }} - uses: github/codeql-action/analyze@v1
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@@ -5,6 +5,8 @@ on:
branches: branches:
- v3.x - v3.x
pull_request: pull_request:
branches:
- v3.x
jobs: jobs:
lint: lint:
@@ -12,13 +14,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Code - uses: technote-space/auto-cancel-redundant-workflow@v1
uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: github/super-linter@v3
- name: Lint Code Base
uses: github/super-linter@v3
env: env:
VALIDATE_ALL_CODEBASE: false VALIDATE_ALL_CODEBASE: false
VALIDATE_JAVASCRIPT_STANDARD: false VALIDATE_JAVASCRIPT_STANDARD: false

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

@@ -0,0 +1,25 @@
name: Release DryRun
on:
push:
branches-ignore:
- v*.x
jobs:
release-dryrun:
runs-on: ubuntu-latest
steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2
- run: npm install
- run: npm run all
- uses: ./
- uses: cycjimmy/semantic-release-action@v2
with:
branches: |
[
"${{ env.GITHUB_REF_NAME }}"
]
dry_run: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

@@ -0,0 +1,18 @@
name: Release
on:
push:
branches:
- v*.x
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: technote-space/auto-cancel-redundant-workflow@v1
- uses: actions/checkout@v2
- run: npm install
- run: npm run all
- uses: cycjimmy/semantic-release-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,3 +1,24 @@
# [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) # [3.4.0](http://github.com/rlespinasse/github-slug-action/compare/3.3.0...3.4.0) (2021-03-02)

View File

@@ -18,7 +18,7 @@ Include the relevant issue number if applicable.
## Do you intend to add a new feature or change an existing one ## 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. * 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 ## Do you have questions about the source code

View File

@@ -1,11 +1,15 @@
# Developers guide # Developers guide
## Prepare
Install the dependencies Install the dependencies
```bash ```bash
npm install npm install
``` ```
## Develop
Build the typescript and package it for distribution Build the typescript and package it for distribution
```bash ```bash
@@ -24,3 +28,11 @@ $ npm test
... ...
``` ```
## Contribute
Before creating a commit, validate your changes and build the associated distribution files
```bash
npm run all
```

138
README.md
View File

@@ -1,11 +1,10 @@
# GitHub Slug action # GitHub Slug action
[![Actions Status][1]][2] [![Release][release-badge]][releases]
![GitHub Super-Linter][13] ![Lint][lint-badge]
[![Public workflows that use this action.][8]][9] [![Licence][license-badge]][license]
[![Licence][11]][12]
This GitHub Action will expose the slug/short values of [some GitHub environment variables][10] inside your GitHub workflow. This GitHub Action will expose the slug/short values of [some GitHub environment variables][github-env-vars] inside your GitHub workflow.
## Table of Contents ## Table of Contents
@@ -14,13 +13,14 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
- [Overview](#overview) - [Overview](#overview)
- [Use this action](#use-this-action) - [Use this action](#use-this-action)
- [Available Environment variables](#available-environment-variables) - [Available Environment variables](#available-environment-variables)
- [Enhanced variables](#enhanced-variables)
- [Partial variables](#partial-variables) - [Partial variables](#partial-variables)
- [Slug variables](#slug-variables) - [Slug variables](#slug-variables)
- [Slug URL variables](#slug-url-variables) - [Slug URL variables](#slug-url-variables)
- [Short variables](#short-variables) - [Short variables](#short-variables)
- [Contribute](#contribute) - [Contribute](#contribute)
- [Troubleshooting](#troubleshooting) - [Troubleshooting](#troubleshooting)
- [One of environement variable don't work as intended](#one-of-environement-variable-dont-work-as-intended) - [One of the environment variables doesn't work as intended](#one-of-the-environment-variables-doesnt-work-as-intended)
- [An action could not be found at the URI](#an-action-could-not-be-found-at-the-uri) - [An action could not be found at the URI](#an-action-could-not-be-found-at-the-uri)
- [Thanks for talking about us](#thanks-for-talking-about-us) - [Thanks for talking about us](#thanks-for-talking-about-us)
@@ -29,7 +29,7 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
`SLUG` on a variable will `SLUG` on a variable will
- put the variable content in lower case - put the variable content in lower case
- replace any character by `-` except `0-9`, `a-z`, and `.` - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
- remove leading and trailing `-` character - remove leading and trailing `-` character
- limit the string size to 63 characters - limit the string size to 63 characters
@@ -37,14 +37,20 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
<summary>Others <b>Slug-ish</b> commands are available</summary> <summary>Others <b>Slug-ish</b> commands are available</summary>
<p> <p>
- `SLUG_URL` on a variable to have a `slug` variable compliant to be used in an URL (Like `SLUG` but `.` is also replaced by `-`) - `SLUG_URL` on a variable to have a `slug` variable compliant to be used in an URL
- `SHORT` on a variable will limit the string size to 8 characters (useful for _sha_ value) - 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 - `<KEY>_PART` on a variable will give a part of a variable defined by a key
_ `<VAR>_CS` on others variables to keep the value case-sensitive - 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> </p>
</details> </details>
Additional enhanced environment variables can be compute to help you around GitHub environment variables.
## Use this action ## Use this action
Add this in your workflow Add this in your workflow
@@ -54,13 +60,21 @@ Add this in your workflow
uses: rlespinasse/github-slug-action@v3.x uses: rlespinasse/github-slug-action@v3.x
``` ```
Check for more [examples][3] (OS usage, URL use, ...) Check for more [examples][examples] (OS usage, URL use, ...)
**Tip:** Use [Dependabot][14] to maintain your `github-slug-action` version updated in your GitHub workflows. **Tip:** Use [Dependabot][dependabot] to maintain your `github-slug-action` version updated in your GitHub workflows.
## Available Environment variables ## 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][5]. **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 ### Partial variables
@@ -73,36 +87,36 @@ Check for more [examples][3] (OS usage, URL use, ...)
**NOTE:** `_CS` suffix available **NOTE:** `_CS` suffix available
| Variable | Slug version of | Description | | Variable | Slug version of | Description |
| ------------------------------------------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [GITHUB_REPOSITORY_SLUG](docs/slug-variables.md#github_repository_slug) | GITHUB_REPOSITORY | The owner and repository name. | | [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>_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_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_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][4] event and forked repositories. | | [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][4] 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][4]<ul><li>`create`</li><li>`delete`</li></ul> | | [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 ### Slug URL variables
**NOTE:** `_CS` suffix available **NOTE:** `_CS` suffix available
| Variable | Slug URL version of | Description | | 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_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>_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_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_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][4] event and forked repositories. | | [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][4] 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][4]<ul><li>`create`</li><li>`delete`</li></ul> | | [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 ### Short variables
| Variable | Short version of | Description | | 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_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][4]<ul><li>`pull_request`</li><li>`pull_request_review`</li><li>`pull_request_review_comment`</li><li>`pull_request_target`</li></ul> | | [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 ## Contribute
@@ -110,11 +124,11 @@ Follow [Developers guide](DEVELOPERS.md)
## Troubleshooting ## Troubleshooting
### One of environement variable don't work as intended ### One of the environment variables doesn't work as intended
[**Note**][17]: GitHub reserves the `GITHUB_` environment variable prefix for internal use by GitHub. Setting an environment variable or secret with the `GITHUB_` prefix will result in an error. [**Note**][naming-conventions]: GitHub reserves the `GITHUB_` environment variable prefix for internal use by GitHub. Setting an environment variable or secret with the `GITHUB_` prefix will result in an error.
Currently, a GitHub workflow setting a `GITHUB_` variable don't ended up in error. Currently, a GitHub workflow setting a `GITHUB_` variable will not cause an error, it will just fail silently.
And if a custom `GITHUB_` variable is in conflict with an official `GITHUB_` variable, the offical `GITHUB_` variable will override custom one. And if a custom `GITHUB_` variable is in conflict with an official `GITHUB_` variable, the offical `GITHUB_` variable will override custom one.
<details> <details>
@@ -150,33 +164,33 @@ 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' ##[error]An action could not be found at the URI 'https://api.github.com/repos/rlespinasse/github-slug-action/tarball/master'
``` ```
> The master branch don't exists anymore. > The master branch doesn't exists anymore.
> >
> The master branch EOL have been set to **2020-10-25** after a 6-month deprecation period (more information on the [EOL issue][7]) > 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][6]) in order to fix your workflow. 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 ## Thanks for talking about us
- [Mettre en place une CI/CD Angular avec GitHub Actions & Netlify][15] (in french :fr:) - [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][16] (in french :fr:) - [Github Actions : enfin des pipelines accessibles aux développeurs][talk-1] (in french :fr:)
- The next one is you. _Don't hesitate to add you to this list._ - The next one is you. _Don't hesitate to add youself to this list._
[1]: https://github.com/rlespinasse/github-slug-action/workflows/Build/badge.svg [release-badge]: https://img.shields.io/github/workflow/status/rlespinasse/github-slug-action/Release?label=Build&logo=github&style=flat-square
[2]: https://github.com/rlespinasse/github-slug-action/actions [lint-badge]: https://img.shields.io/github/workflow/status/rlespinasse/github-slug-action/Lint?label=Lint&logo=github&style=flat-square
[3]: https://github.com/rlespinasse/github-slug-action/tree/v3.x/examples [license-badge]: https://img.shields.io/github/license/rlespinasse/github-slug-action?style=flat-square
[4]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads
[5]: https://github.com/rlespinasse/github-slug-action/issues/new?assignees=&labels=enhancement&template=feature_request.md&title= [actions]: https://github.com/rlespinasse/github-slug-action/actions
[6]: https://github.com/rlespinasse/github-slug-action/releases [license]: https://github.com/rlespinasse/github-slug-action/blob/v3.x/LICENSE
[7]: https://github.com/rlespinasse/github-slug-action/issues/15 [examples]: https://github.com/rlespinasse/github-slug-action/tree/v3.x/examples
[8]: https://img.shields.io/endpoint?url=https%3A%2F%2Fapi-git-master.endbug.vercel.app%2Fapi%2Fgithub-actions%2Fused-by%3Faction%3Drlespinasse%2Fgithub-slug-action%26badge%3Dtrue [custom-variable]: https://github.com/rlespinasse/github-slug-action/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
[9]: https://github.com/search?o=desc&q=rlespinasse/github-slug-action+path%3A.github%2Fworkflows+language%3AYAML&s=&type=Code [releases]: https://github.com/rlespinasse/github-slug-action/releases
[10]: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables [issue-15]: https://github.com/rlespinasse/github-slug-action/issues/15
[11]: https://img.shields.io/github/license/rlespinasse/github-slug-action
[12]: https://github.com/rlespinasse/github-slug-action/blob/v3.x/LICENSE [github-env-vars]: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables
[13]: https://github.com/rlespinasse/github-slug-action/workflows/Lint/badge.svg [dependabot]: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot
[14]: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot [webhooks-and-events]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads
[15]: https://esensconsulting.medium.com/mettre-en-place-une-ci-cd-angular-avec-github-actions-netlify-ca0b59b99ed8 [naming-conventions]: https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables
[16]: https://www.youtube.com/watch?v=RHnTJBwcE98
[17]: [article-1]: https://esensconsulting.medium.com/mettre-en-place-une-ci-cd-angular-avec-github-actions-netlify-ca0b59b99ed8
https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables [talk-1]: https://www.youtube.com/watch?v=RHnTJBwcE98

View File

@@ -16,13 +16,13 @@ test('slug_ref:: master branch', () => {
}) })
test('slug_ref: a feature branch', () => { test('slug_ref: a feature branch', () => {
test_slugref('refs/heads/feat/new_feature', 'feat-new-feature') test_slugref('refs/heads/feat/new_feature', 'feat-new_feature')
test_slugref_cs('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('slug_ref: a fix branch', () => {
test_slugref('refs/heads/fix/issue_number', 'fix-issue-number') test_slugref('refs/heads/fix/issue_number', 'fix-issue_number')
test_slugref_cs('refs/heads/fix/issue_number', 'fix-issue-number') test_slugref_cs('refs/heads/fix/issue_number', 'fix-issue_number')
}) })
test('slug_ref: a simple tag', () => { test('slug_ref: a simple tag', () => {
@@ -36,8 +36,8 @@ test('slug_ref: a complex tag', () => {
}) })
test('slug_ref: a reference with upper case letters', () => { test('slug_ref: a reference with upper case letters', () => {
test_slugref('refs/heads/New_Awesome_Product', 'new-awesome-product') test_slugref('refs/heads/New_Awesome_Product', 'new_awesome_product')
test_slugref_cs('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('slug_ref: test trailing', () => {

69
dist/index.js vendored
View File

@@ -110,6 +110,10 @@ const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH';
*/ */
const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART'; const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART';
const GITHUB_REPOSITORY_NAME_PART = 'GITHUB_REPOSITORY_NAME_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 * Slugged outputs environments variables keys
*/ */
@@ -127,6 +131,8 @@ const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG';
const GITHUB_BASE_REF_SLUG_CS = 'GITHUB_BASE_REF_SLUG_CS'; 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 = 'GITHUB_EVENT_REF_SLUG';
const GITHUB_EVENT_REF_SLUG_CS = 'GITHUB_EVENT_REF_SLUG_CS'; 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 * URL-Slugged outputs environments variables keys
*/ */
@@ -144,6 +150,8 @@ 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_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 = 'GITHUB_EVENT_REF_SLUG_URL';
const GITHUB_EVENT_REF_SLUG_URL_CS = 'GITHUB_EVENT_REF_SLUG_URL_CS'; 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 * Shorted outputs environments variables keys
*/ */
@@ -192,6 +200,7 @@ function run() {
exportSlugUrlRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL); exportSlugUrlRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL);
exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS); exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS);
exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT); exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT);
exportBranchName();
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
@@ -253,15 +262,21 @@ function exportSecondPartSlug(inputKey, separator, outputKey) {
function exportSlugRefCS(inputKey, outputKey) { function exportSlugRefCS(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slug_1.slugref_cs(envVar)); exportSlugRefCSValue(envVar, outputKey);
} }
} }
function exportSlugRefCSValue(envVar, outputKey) {
core.exportVariable(outputKey, slug_1.slugref_cs(envVar));
}
function exportSlugRef(inputKey, outputKey) { function exportSlugRef(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slug_1.slugref(envVar)); exportSlugRefValue(envVar, outputKey);
} }
} }
function exportSlugRefValue(envVar, outputKey) {
core.exportVariable(outputKey, slug_1.slugref(envVar));
}
function exportSlugUrlCS(inputKey, outputKey) { function exportSlugUrlCS(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
@@ -305,21 +320,45 @@ function exportSecondPartSlugUrl(inputKey, separator, outputKey) {
function exportSlugUrlRefCS(inputKey, outputKey) { function exportSlugUrlRefCS(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slug_1.slugurlref_cs(envVar)); exportSlugUrlRefCSValue(envVar, outputKey);
} }
} }
function exportSlugUrlRefCSValue(envVar, outputKey) {
core.exportVariable(outputKey, slug_1.slugurlref_cs(envVar));
}
function exportSlugUrlRef(inputKey, outputKey) { function exportSlugUrlRef(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slug_1.slugurlref(envVar)); exportSlugUrlRefValue(envVar, outputKey);
} }
} }
function exportSlugUrlRefValue(envVar, outputKey) {
core.exportVariable(outputKey, slug_1.slugurlref(envVar));
}
function exportShortSha(inputKey, outputKey) { function exportShortSha(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, short_1.shortsha(envVar)); core.exportVariable(outputKey, short_1.shortsha(envVar));
} }
} }
function exportBranchName() {
//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, slug_1.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(); run();
@@ -435,6 +474,7 @@ exports.getInput = getInput;
*/ */
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) { function setOutput(name, value) {
process.stdout.write(os.EOL);
command_1.issueCommand('set-output', { name }, value); command_1.issueCommand('set-output', { name }, value);
} }
exports.setOutput = setOutput; exports.setOutput = setOutput;
@@ -738,11 +778,11 @@ exports.get_second_part = get_second_part;
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.slugurlref = exports.slugurlref_cs = exports.slugurl = exports.slugurl_cs = exports.slugref = exports.slugref_cs = exports.slug = exports.slug_cs = void 0; exports.removeRef = exports.slugurlref = exports.slugurlref_cs = exports.slugurl = exports.slugurl_cs = exports.slugref = exports.slugref_cs = exports.slug = exports.slug_cs = void 0;
const MAX_SLUG_STRING_SIZE = 63; const MAX_SLUG_STRING_SIZE = 63;
/** /**
* slug_cs will take envVar and then : * slug_cs will take envVar and then :
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -754,7 +794,7 @@ exports.slug_cs = slug_cs;
/** /**
* slug will take envVar and then : * slug will take envVar and then :
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -766,7 +806,7 @@ exports.slug = slug;
/** /**
* slugref_cs will take envVar and then : * slugref_cs will take envVar and then :
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -779,7 +819,7 @@ exports.slugref_cs = slugref_cs;
* slugref will take envVar and then : * slugref will take envVar and then :
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -796,7 +836,7 @@ exports.slugref = slugref;
* @param envVar to be slugged * @param envVar to be slugged
*/ */
function slugurl_cs(envVar) { function slugurl_cs(envVar) {
return slug_cs(replaceAnyDotToHyphen(envVar)); return slug_cs(replaceAnyNonUrlCharactersWithHyphen(envVar));
} }
exports.slugurl_cs = slugurl_cs; exports.slugurl_cs = slugurl_cs;
/** /**
@@ -808,7 +848,7 @@ exports.slugurl_cs = slugurl_cs;
* @param envVar to be slugged * @param envVar to be slugged
*/ */
function slugurl(envVar) { function slugurl(envVar) {
return slug(replaceAnyDotToHyphen(envVar)); return slug(replaceAnyNonUrlCharactersWithHyphen(envVar));
} }
exports.slugurl = slugurl; exports.slugurl = slugurl;
/** /**
@@ -840,14 +880,15 @@ function trailHyphen(envVar) {
return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), ''); return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '');
} }
function replaceAnyNonAlphanumericCharacter(envVar) { function replaceAnyNonAlphanumericCharacter(envVar) {
return envVar.replace(RegExp('[^a-zA-Z0-9.]', 'g'), '-'); return envVar.replace(RegExp('[^a-zA-Z0-9._]', 'g'), '-');
} }
function replaceAnyDotToHyphen(envVar) { function replaceAnyNonUrlCharactersWithHyphen(envVar) {
return envVar.replace(RegExp('[.]', 'g'), '-'); return envVar.replace(RegExp('[._]', 'g'), '-');
} }
function removeRef(envVar) { function removeRef(envVar) {
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), ''); return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '');
} }
exports.removeRef = removeRef;
/***/ }), /***/ }),

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

23072
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -30,10 +30,11 @@
}, },
"devDependencies": { "devDependencies": {
"@semantic-release/changelog": "^5.0.1", "@semantic-release/changelog": "^5.0.1",
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0", "@semantic-release/git": "^9.0.0",
"@types/jest": "^26.0.20", "@types/jest": "^26.0.20",
"@types/node": "^14.14.21", "@types/node": "^14.14.21",
"@typescript-eslint/parser": "^3.9.1", "@typescript-eslint/eslint-plugin": "^4.22.0",
"@vercel/ncc": "^0.23.0", "@vercel/ncc": "^0.23.0",
"eslint": "^7.18.0", "eslint": "^7.18.0",
"eslint-plugin-github": "^4.1.1", "eslint-plugin-github": "^4.1.1",
@@ -46,12 +47,21 @@
"ts-jest": "^26.4.4", "ts-jest": "^26.4.4",
"typescript": "^3.9.7" "typescript": "^3.9.7"
}, },
"files": [
"/dist"
],
"release": { "release": {
"tagFormat": "${version}", "tagFormat": "${version}",
"plugins": [ "plugins": [
"@semantic-release/commit-analyzer", "@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator", "@semantic-release/release-notes-generator",
"@semantic-release/changelog", "@semantic-release/changelog",
[
"@semantic-release/exec",
{
"prepareCmd": "git add dist"
}
],
"@semantic-release/git", "@semantic-release/git",
"@semantic-release/github" "@semantic-release/github"
], ],

View File

@@ -1,5 +1,6 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import { import {
removeRef,
slug, slug,
slug_cs, slug_cs,
slugref, slugref,
@@ -31,6 +32,11 @@ const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH'
const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART' const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART'
const GITHUB_REPOSITORY_NAME_PART = 'GITHUB_REPOSITORY_NAME_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 * Slugged outputs environments variables keys
*/ */
@@ -50,6 +56,8 @@ const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG'
const GITHUB_BASE_REF_SLUG_CS = 'GITHUB_BASE_REF_SLUG_CS' 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 = 'GITHUB_EVENT_REF_SLUG'
const GITHUB_EVENT_REF_SLUG_CS = 'GITHUB_EVENT_REF_SLUG_CS' 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 * URL-Slugged outputs environments variables keys
@@ -72,6 +80,8 @@ 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_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 = 'GITHUB_EVENT_REF_SLUG_URL'
const GITHUB_EVENT_REF_SLUG_URL_CS = 'GITHUB_EVENT_REF_SLUG_URL_CS' 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 * Shorted outputs environments variables keys
@@ -168,6 +178,8 @@ async function run(): Promise<void> {
exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS) exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS)
exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT) exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT)
exportBranchName()
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
} }
@@ -259,17 +271,25 @@ function exportSecondPartSlug(
function exportSlugRefCS(inputKey: string, outputKey: string): void { function exportSlugRefCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slugref_cs(envVar)) exportSlugRefCSValue(envVar, outputKey)
} }
} }
function exportSlugRefCSValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugref_cs(envVar))
}
function exportSlugRef(inputKey: string, outputKey: string): void { function exportSlugRef(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slugref(envVar)) exportSlugRefValue(envVar, outputKey)
} }
} }
function exportSlugRefValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugref(envVar))
}
function exportSlugUrlCS(inputKey: string, outputKey: string): void { function exportSlugUrlCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
@@ -334,17 +354,25 @@ function exportSecondPartSlugUrl(
function exportSlugUrlRefCS(inputKey: string, outputKey: string): void { function exportSlugUrlRefCS(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slugurlref_cs(envVar)) exportSlugUrlRefCSValue(envVar, outputKey)
} }
} }
function exportSlugUrlRefCSValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugurlref_cs(envVar))
}
function exportSlugUrlRef(inputKey: string, outputKey: string): void { function exportSlugUrlRef(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slugurlref(envVar)) exportSlugUrlRefValue(envVar, outputKey)
} }
} }
function exportSlugUrlRefValue(envVar: string, outputKey: string): void {
core.exportVariable(outputKey, slugurlref(envVar))
}
function exportShortSha(inputKey: string, outputKey: string): void { function exportShortSha(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
@@ -352,4 +380,22 @@ function exportShortSha(inputKey: string, outputKey: string): void {
} }
} }
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() run()

View File

@@ -2,7 +2,7 @@ const MAX_SLUG_STRING_SIZE = 63
/** /**
* slug_cs will take envVar and then : * slug_cs will take envVar and then :
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -17,7 +17,7 @@ export function slug_cs(envVar: string): string {
/** /**
* slug will take envVar and then : * slug will take envVar and then :
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -29,7 +29,7 @@ export function slug(envVar: string): string {
/** /**
* slugref_cs will take envVar and then : * slugref_cs will take envVar and then :
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -42,7 +42,7 @@ export function slugref_cs(envVar: string): string {
* slugref will take envVar and then : * slugref will take envVar and then :
* - remove refs/(heads|tags|pull)/ * - remove refs/(heads|tags|pull)/
* - put the variable content in lower case * - put the variable content in lower case
* - replace any character by `-` except `0-9`, `a-z`, and `.` * - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
* - remove leading and trailing `-` character * - remove leading and trailing `-` character
* - limit the string size to 63 characters * - limit the string size to 63 characters
* @param envVar to be slugged * @param envVar to be slugged
@@ -59,7 +59,7 @@ export function slugref(envVar: string): string {
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugurl_cs(envVar: string): string { export function slugurl_cs(envVar: string): string {
return slug_cs(replaceAnyDotToHyphen(envVar)) return slug_cs(replaceAnyNonUrlCharactersWithHyphen(envVar))
} }
/** /**
@@ -71,7 +71,7 @@ export function slugurl_cs(envVar: string): string {
* @param envVar to be slugged * @param envVar to be slugged
*/ */
export function slugurl(envVar: string): string { export function slugurl(envVar: string): string {
return slug(replaceAnyDotToHyphen(envVar)) return slug(replaceAnyNonUrlCharactersWithHyphen(envVar))
} }
/** /**
@@ -104,13 +104,13 @@ function trailHyphen(envVar: string): string {
} }
function replaceAnyNonAlphanumericCharacter(envVar: string): string { function replaceAnyNonAlphanumericCharacter(envVar: string): string {
return envVar.replace(RegExp('[^a-zA-Z0-9.]', 'g'), '-') return envVar.replace(RegExp('[^a-zA-Z0-9._]', 'g'), '-')
} }
function replaceAnyDotToHyphen(envVar: string): string { function replaceAnyNonUrlCharactersWithHyphen(envVar: string): string {
return envVar.replace(RegExp('[.]', 'g'), '-') return envVar.replace(RegExp('[._]', 'g'), '-')
} }
function removeRef(envVar: string): string { export function removeRef(envVar: string): string {
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '') return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '')
} }