mirror of
https://github.com/rlespinasse/github-slug-action.git
synced 2026-05-18 02:45:04 +00:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4060fda269 | ||
|
|
475d293680 | ||
|
|
0c099abd97 | ||
|
|
6c93fcbf53 | ||
|
|
38c43d3f60 | ||
|
|
275eb0d01d | ||
|
|
d1880ea5b3 | ||
|
|
66299f72e4 | ||
|
|
78985f84ec | ||
|
|
75ce03b6a0 | ||
|
|
49e1056c70 | ||
|
|
81bff0391a | ||
|
|
b956e16ac2 | ||
|
|
fad587c035 | ||
|
|
5f4806451f | ||
|
|
c8d8ee50d0 | ||
|
|
5b9fe6015d | ||
|
|
5629d21ee9 | ||
|
|
b6938fb2bd | ||
|
|
d6257a36a9 | ||
|
|
7ad978282a | ||
|
|
9f5fafb8ad | ||
|
|
750d2f7f48 | ||
|
|
2b1034b1fb | ||
|
|
1b1913be6c | ||
|
|
cc560ad7b4 | ||
|
|
549c11b4e2 | ||
|
|
68eb43656c | ||
|
|
2aba10a826 | ||
|
|
afcda09378 | ||
|
|
15f6edebdd | ||
|
|
e4699e49fc | ||
|
|
3cddc4f12d | ||
|
|
d7817bf204 | ||
|
|
4e3f956c5e | ||
|
|
f79727b5cc | ||
|
|
a3c7c5c7a1 | ||
|
|
008aa6260d | ||
|
|
3c7ae42a01 | ||
|
|
ae2430ad57 |
6
.dependabot/config.xml
Normal file
6
.dependabot/config.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
9
.github/dependabot.yml
vendored
9
.github/dependabot.yml
vendored
@@ -1,9 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
# Enable version updates for npm
|
||||
- package-ecosystem: 'npm'
|
||||
# Look for `package.json` and `lock` files in the `root` directory
|
||||
directory: '/'
|
||||
# Check the npm registry for updates every day (weekdays)
|
||||
schedule:
|
||||
interval: 'daily'
|
||||
131
.github/workflows/build.yml
vendored
Normal file
131
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- v3.x
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm ci
|
||||
- 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: ./
|
||||
- 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 }}"
|
||||
- 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 }}"
|
||||
|
||||
win-test:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- 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"
|
||||
- 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"
|
||||
65
.github/workflows/ci.yml
vendored
65
.github/workflows/ci.yml
vendored
@@ -1,65 +0,0 @@
|
||||
name: Build
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm ci
|
||||
- run: |
|
||||
npm run all
|
||||
- uses: cycjimmy/semantic-release-action@v2
|
||||
with:
|
||||
semantic_version: 17.0.7
|
||||
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 }}
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
- run: |
|
||||
echo $GITHUB_REPOSITORY_SLUG
|
||||
echo $GITHUB_REPOSITORY_SLUG_URL
|
||||
echo $GITHUB_REF_SLUG
|
||||
echo $GITHUB_HEAD_REF_SLUG
|
||||
echo $GITHUB_BASE_REF_SLUG
|
||||
echo $GITHUB_EVENT_REF_SLUG
|
||||
echo $GITHUB_REF_SLUG_URL
|
||||
echo $GITHUB_HEAD_REF_SLUG_URL
|
||||
echo $GITHUB_BASE_REF_SLUG_URL
|
||||
echo $GITHUB_EVENT_REF_SLUG_URL
|
||||
echo $GITHUB_SHA_SHORT
|
||||
|
||||
test-win:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
- run: |
|
||||
echo $env:GITHUB_REPOSITORY_SLUG
|
||||
echo $env:GITHUB_REPOSITORY_SLUG_URL
|
||||
echo $env:GITHUB_REF_SLUG
|
||||
echo $env:GITHUB_HEAD_REF_SLUG
|
||||
echo $env:GITHUB_BASE_REF_SLUG
|
||||
echo $env:GITHUB_EVENT_REF_SLUG
|
||||
echo $env:GITHUB_REF_SLUG_URL
|
||||
echo $env:GITHUB_HEAD_REF_SLUG_URL
|
||||
echo $env:GITHUB_BASE_REF_SLUG_URL
|
||||
echo $env:GITHUB_EVENT_REF_SLUG_URL
|
||||
echo $env:GITHUB_SHA_SHORT
|
||||
34
.github/workflows/codeql-analysis.yml
vendored
Normal file
34
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ v3.x, v*.x ]
|
||||
pull_request:
|
||||
branches: [ v3.x ]
|
||||
schedule:
|
||||
- cron: '0 6 * * 1'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript' ]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
31
.github/workflows/linter.yml
vendored
Normal file
31
.github/workflows/linter.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- v3.x
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Lint Code Base
|
||||
uses: github/super-linter@v3
|
||||
env:
|
||||
VALIDATE_ALL_CODEBASE: false
|
||||
VALIDATE_JAVASCRIPT_STANDARD: false
|
||||
VALIDATE_TYPESCRIPT_STANDARD: false
|
||||
LINTER_RULES_PATH: .
|
||||
JAVASCRIPT_ES_CONFIG_FILE: .eslintrc.json
|
||||
JAVASCRIPT_DEFAULT_STYLE: prettier
|
||||
DEFAULT_BRANCH: v3.x
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
FILTER_REGEX_INCLUDE: .*src/.*
|
||||
40
CHANGELOG.md
40
CHANGELOG.md
@@ -1,3 +1,43 @@
|
||||
# [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)
|
||||
|
||||
|
||||
|
||||
33
CONTRIBUTING.md
Normal file
33
CONTRIBUTING.md
Normal 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.
|
||||
|
||||
## 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=
|
||||
220
README.md
220
README.md
@@ -1,118 +1,108 @@
|
||||
# GitHub Slug action
|
||||
|
||||
[![Actions Status][1]][2]
|
||||
![GitHub Super-Linter][13]
|
||||
[![Public workflows that use this action.][8]][9]
|
||||
[![Licence][11]][12]
|
||||
|
||||
This action slug and expose some github variables.
|
||||
This GitHub Action will expose the slug/short values of [some GitHub environment variables][10] inside your GitHub workflow.
|
||||
|
||||
`Slug` a variable will
|
||||
## Table of Contents
|
||||
|
||||
- [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)
|
||||
- [Partial variables](#partial-variables)
|
||||
- [Slug variables](#slug-variables)
|
||||
- [Slug URL variables](#slug-url-variables)
|
||||
- [Short variables](#short-variables)
|
||||
- [Contribute](#contribute)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
- [One of environement variable don't work as intended](#one-of-environement-variable-dont-work-as-intended)
|
||||
- [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)
|
||||
|
||||
## Overview
|
||||
|
||||
`SLUG` on a variable will
|
||||
|
||||
- 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
|
||||
- limit the string size to 63 characters
|
||||
|
||||
Others `Slug`-ish commands are available:
|
||||
<details>
|
||||
<summary>Others <b>Slug-ish</b> commands are available</summary>
|
||||
<p>
|
||||
|
||||
- `Slug URL` a variable will be like the `slug` variable but the `.` character will also be replaced by `-`
|
||||
- `Short SHA` a variable will limit the string size to 8 characters
|
||||
- `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
|
||||
_ `<VAR>_CS` on others variables to keep the value case-sensitive
|
||||
|
||||
## Exposed environment variables
|
||||
</p>
|
||||
</details>
|
||||
|
||||
## Use this action
|
||||
|
||||
Add this in your workflow
|
||||
|
||||
```yaml
|
||||
- name: Inject slug/short variables
|
||||
uses: rlespinasse/github-slug-action@v2.x
|
||||
|
||||
- name: Print slug/short variables
|
||||
run: |
|
||||
echo "Slug variables"
|
||||
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 " repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
|
||||
echo "Slug URL variables"
|
||||
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 " repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
|
||||
echo "Short SHA variables"
|
||||
echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
|
||||
uses: rlespinasse/github-slug-action@v3.x
|
||||
```
|
||||
|
||||
Read [default environment variables][3] page for more information.
|
||||
Check for more [examples][3] (OS usage, URL use, ...)
|
||||
|
||||
### GITHUB_REF_SLUG / GITHUB_REF_SLUG_URL
|
||||
**Tip:** Use [Dependabot][14] to maintain your `github-slug-action` version updated in your GitHub workflows.
|
||||
|
||||
Slug the environment variable **GITHUB_REF**
|
||||
## Available Environment variables
|
||||
|
||||
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._
|
||||
**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].
|
||||
|
||||
| GITHUB_REF | GITHUB_REF_SLUG | GITHUB_REF_SLUG_URL |
|
||||
| ------------------------------ | ------------------- | ------------------- |
|
||||
| refs/heads/master | master | master |
|
||||
| refs/heads/feat/new_feature | feat-new-feature | feat-new-feature |
|
||||
| refs/tags/v1.0.0 | v1.0.0 | v1-0-0 |
|
||||
| refs/tags/product@1.0.0-rc.2 | product-1.0.0-rc.2 | product-1-0-0-rc-2 |
|
||||
| refs/heads/New_Awesome_Product | new-awesome-product | new-awesome-product |
|
||||
### Partial variables
|
||||
|
||||
> **NOTE :**
|
||||
> GITHUB_REF_SLUG_URL is design to be used as subdomain in an URL.
|
||||
| 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 |
|
||||
|
||||
_Additional variables (only set for forked repositories) :_
|
||||
### Slug variables
|
||||
|
||||
- `GITHUB_HEAD_REF_SLUG`/`GITHUB_HEAD_REF_SLUG_URL`, The branch of the head repository **GITHUB_HEAD_REF**
|
||||
- `GITHUB_BASE_REF_SLUG`/`GITHUB_BASE_REF_SLUG_URL`, The branch of the base repository **GITHUB_BASE_REF**
|
||||
**NOTE:** `_CS` suffix available
|
||||
|
||||
_Additional variables (only set for [create][4], and [delete][5] webhook events with `ref` data) :_
|
||||
| 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][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][4] 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`/`GITHUB_EVENT_REF_SLUG_URL`, The git reference resource associated to the webhook.
|
||||
### Slug URL variables
|
||||
|
||||
### GITHUB_REPOSITORY_SLUG / GITHUB_REPOSITORY_SLUG_URL
|
||||
**NOTE:** `_CS` suffix available
|
||||
|
||||
Slug the environment variable **GITHUB_REPOSITORY**
|
||||
| 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][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][4] 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> |
|
||||
|
||||
The owner and repository name.
|
||||
### Short variables
|
||||
|
||||
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG | GITHUB_REPOSITORY_SLUG_URL |
|
||||
| -------------------------- | -------------------------- | -------------------------- |
|
||||
| octocat/Hello-World | octocat-hello-world | octocat-hello-world |
|
||||
| rlespinasse/Hello-World.go | rlespinasse-hello-world.go | rlespinasse-hello-world-go |
|
||||
|
||||
> **NOTE :**
|
||||
> GITHUB_REPOSITORY_SLUG_URL is design to be used as subdomain in an URL.
|
||||
|
||||
### GITHUB_SHA_SHORT
|
||||
|
||||
Short the environment variable **GITHUB_SHA**
|
||||
|
||||
The commit SHA that triggered the workflow
|
||||
|
||||
| GITHUB_SHA | GITHUB_SHA_SHORT |
|
||||
| ---------------------------------------- | ---------------- |
|
||||
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |
|
||||
|
||||
### Use slug variable in an URL
|
||||
|
||||
In an URL, use `<GITHUB_VARIABLE>_SLUG_URL` instead of **<GITHUB_VARIABLE>\_SLUG** as subdomain to be compliant.
|
||||
|
||||
> **NOTE :**
|
||||
> <GITHUB*VARIABLE>\_SLUG can be used in an URL only as part of the \_resource path*.
|
||||
|
||||
```yaml
|
||||
- name: Inject slug/short variables
|
||||
uses: rlespinasse/github-slug-action@v2.x
|
||||
|
||||
- name: Deploy dummy application using slug in the 'subdomain' part
|
||||
run: |
|
||||
./deploy-application.sh --url "https://${{ env.<GITHUB_VARIABLE>_SLUG_URL }}.staging.app.mycompagny.com"
|
||||
|
||||
- name: Deploy dummy application using slug in the 'resource path' part
|
||||
run: |
|
||||
./deploy-application.sh --url "https://staging.app.mycompagny.com/${{ env.<GITHUB_VARIABLE>_SLUG }}"
|
||||
```
|
||||
| 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][4]<ul><li>`pull_request`</li><li>`pull_request_review`</li><li>`pull_request_review_comment`</li><li>`pull_request_target`</li></ul> |
|
||||
|
||||
## Contribute
|
||||
|
||||
@@ -120,7 +110,38 @@ Follow [Developers guide](DEVELOPERS.md)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Missing master branch
|
||||
### One of environement variable don'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.
|
||||
|
||||
Currently, a GitHub workflow setting a `GITHUB_` variable don't ended up in error.
|
||||
And if a custom `GITHUB_` variable is in conflict with an official `GITHUB_` variable, the offical `GITHUB_` variable will override custom one.
|
||||
|
||||
<details>
|
||||
<summary>Test workflow</summary>
|
||||
<p>
|
||||
|
||||
```yaml
|
||||
name: Test
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo ${GITHUB_REF}
|
||||
# print "refs/heads/v3.x"
|
||||
- run: echo "GITHUB_REF=one_value" >> "$GITHUB_ENV"
|
||||
- run: echo ${GITHUB_REF}
|
||||
# print "refs/heads/v3.x"
|
||||
- run: echo "GITHUB_REF_SLUG=another_value" >> "$GITHUB_ENV"
|
||||
- run: echo ${GITHUB_REF_SLUG}
|
||||
# print "another_value"
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
### An action could not be found at the URI
|
||||
|
||||
If your workflow fail on the `Set up job` task with this kind of log :
|
||||
|
||||
@@ -129,16 +150,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'
|
||||
```
|
||||
|
||||
Use the current branch `v2.x` or a version tag (see [releases pages][6]).
|
||||
> The master branch don'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 is set on **2020-10-25** after a 6-month deprecation period (more information on the [EOL issue][7])
|
||||
Please, use the current branch `v3.x` or a version tag (see [releases pages][6]) in order to fix your workflow.
|
||||
|
||||
## Thanks for talking about us
|
||||
|
||||
- [Mettre en place une CI/CD Angular avec GitHub Actions & Netlify][15] (in french :fr:)
|
||||
- [Github Actions : enfin des pipelines accessibles aux développeurs][16] (in french :fr:)
|
||||
- The next one is you. _Don't hesitate to add you to this list._
|
||||
|
||||
[1]: https://github.com/rlespinasse/github-slug-action/workflows/Build/badge.svg
|
||||
[2]: https://github.com/rlespinasse/github-slug-action/actions
|
||||
[3]: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
|
||||
[4]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#create
|
||||
[5]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#delete
|
||||
[3]: https://github.com/rlespinasse/github-slug-action/tree/v3.x/examples
|
||||
[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=
|
||||
[6]: https://github.com/rlespinasse/github-slug-action/releases
|
||||
[7]: https://github.com/rlespinasse/github-slug-action/issues/15
|
||||
[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
|
||||
[9]: https://github.com/search?o=desc&q=rlespinasse%2Frlespinasse/github-slug-action+path%3A.github%2Fworkflows+language%3AYAML&s=&type=Code
|
||||
[9]: https://github.com/search?o=desc&q=rlespinasse/github-slug-action+path%3A.github%2Fworkflows+language%3AYAML&s=&type=Code
|
||||
[10]: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables
|
||||
[11]: https://img.shields.io/github/license/rlespinasse/github-slug-action
|
||||
[12]: https://github.com/rlespinasse/github-slug-action/blob/v3.x/LICENSE
|
||||
[13]: https://github.com/rlespinasse/github-slug-action/workflows/Lint/badge.svg
|
||||
[14]: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot
|
||||
[15]: https://esensconsulting.medium.com/mettre-en-place-une-ci-cd-angular-avec-github-actions-netlify-ca0b59b99ed8
|
||||
[16]: https://www.youtube.com/watch?v=RHnTJBwcE98
|
||||
[17]:
|
||||
https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|---------|--------|--------------------|
|
||||
| 3.x | v3.x | :white_check_mark: |
|
||||
| 2.x | v2.x | :white_check_mark: |
|
||||
| 1.1.x | v1.1.x | :white_check_mark: |
|
||||
| < 1.0.x | master | :x: |
|
||||
| 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.
|
||||
|
||||
|
||||
28
__tests__/partial.test.ts
Normal file
28
__tests__/partial.test.ts
Normal 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')
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import {shortsha} from '../src/slug'
|
||||
import {shortsha} from '../src/short'
|
||||
|
||||
function test_short_sha(input: string, expected: string) {
|
||||
let actual = shortsha(input)
|
||||
|
||||
@@ -1,36 +1,48 @@
|
||||
import {slug} from '../src/slug'
|
||||
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: special caracter', () => {
|
||||
test_slug('feat-(!è§-caracter', 'feat------caracter')
|
||||
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', () => {
|
||||
@@ -38,6 +50,10 @@ test('slug: a very long string', () => {
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
|
||||
'an-awesome-feature-very-very-very-very-very-very-very-long-more'
|
||||
)
|
||||
test_slug_cs(
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more'
|
||||
)
|
||||
})
|
||||
|
||||
test('slug: short string after trailing', () => {
|
||||
@@ -45,4 +61,8 @@ test('slug: short string after trailing', () => {
|
||||
'-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-',
|
||||
'an-awesome-feature-very-very-very-very-very-very-very-long-more'
|
||||
)
|
||||
test_slug_cs(
|
||||
'-an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters-',
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,45 +1,67 @@
|
||||
import {slugref} from '../src/slug'
|
||||
import {slugref, slugref_cs} from '../src/slug'
|
||||
|
||||
function test_slug_ref(input: string, expected: string) {
|
||||
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_slug_ref('refs/heads/master', 'master')
|
||||
test_slugref('refs/heads/master', 'master')
|
||||
test_slugref_cs('refs/heads/master', 'master')
|
||||
})
|
||||
|
||||
test('slug_ref: a feature branch', () => {
|
||||
test_slug_ref('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('slug_ref: a fix branch', () => {
|
||||
test_slug_ref('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('slug_ref: a simple tag', () => {
|
||||
test_slug_ref('refs/tags/v1.0.0', 'v1.0.0')
|
||||
test_slugref('refs/tags/v1.0.0', 'v1.0.0')
|
||||
test_slugref_cs('refs/tags/v1.0.0', 'v1.0.0')
|
||||
})
|
||||
|
||||
test('slug_ref: a complex tag', () => {
|
||||
test_slug_ref('refs/tags/product@1.0.0-rc.2', 'product-1.0.0-rc.2')
|
||||
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_slug_ref('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('slug_ref: test trailing', () => {
|
||||
test_slug_ref('refs/heads/-trailing-feat-', 'trailing-feat')
|
||||
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_slug_ref('refs/heads/-refs/tags/feature/-', 'refs-tags-feature')
|
||||
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_slug_ref(
|
||||
test_slugref(
|
||||
'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'
|
||||
)
|
||||
test_slugref_cs(
|
||||
'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'
|
||||
)
|
||||
})
|
||||
|
||||
test('slug_ref: on pull-request ref', () => {
|
||||
test_slugref('refs/pull/branch', 'branch')
|
||||
test_slugref_cs('refs/pull/branch', 'branch')
|
||||
})
|
||||
|
||||
@@ -1,37 +1,52 @@
|
||||
import {slugurl} from '../src/slug'
|
||||
import {slugurl, slugurl_cs} from '../src/slug'
|
||||
|
||||
function test_slug_url(input: string, expected: string) {
|
||||
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_slug_url('word', 'word')
|
||||
test_slugurl('word', 'word')
|
||||
test_slugurl_cs('word', 'word')
|
||||
})
|
||||
|
||||
test('slug_url: a string', () => {
|
||||
test_slug_url('basic-string', 'basic-string')
|
||||
test_slugurl('basic-string', 'basic-string')
|
||||
test_slugurl_cs('basic-string', 'basic-string')
|
||||
})
|
||||
|
||||
test('slug_url: a string in camel case', () => {
|
||||
test_slug_url('camelCase', 'camelcase')
|
||||
test_slugurl('camelCase', 'camelcase')
|
||||
test_slugurl_cs('camelCase', 'camelCase')
|
||||
})
|
||||
|
||||
test('slug_url: a path', () => {
|
||||
test_slug_url('path/to/something', 'path-to-something')
|
||||
test_slugurl('path/to/something', 'path-to-something')
|
||||
test_slugurl_cs('path/to/something', 'path-to-something')
|
||||
})
|
||||
|
||||
test('slug_url: a number', () => {
|
||||
test_slug_url('4.2', '4-2')
|
||||
test_slugurl('4.2', '4-2')
|
||||
test_slugurl_cs('4.2', '4-2')
|
||||
})
|
||||
|
||||
test('slug_url: trailing', () => {
|
||||
test_slug_url('.path.to.', 'path-to')
|
||||
test_slugurl('.path.to.', 'path-to')
|
||||
test_slugurl_cs('.path.to.', 'path-to')
|
||||
})
|
||||
|
||||
test('slug_url: a very long string', () => {
|
||||
test_slug_url(
|
||||
test_slugurl(
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
|
||||
'an-awesome-feature-very-very-very-very-very-very-very-long-more'
|
||||
)
|
||||
test_slugurl_cs(
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters',
|
||||
'an-awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-more'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,45 +1,67 @@
|
||||
import {slugurlref} from '../src/slug'
|
||||
import {slugurlref, slugurlref_cs} from '../src/slug'
|
||||
|
||||
function test_slug_url_ref(input: string, expected: string) {
|
||||
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_slug_url_ref('refs/heads/master', 'master')
|
||||
test_slugurlref('refs/heads/master', 'master')
|
||||
test_slugurlref_cs('refs/heads/master', 'master')
|
||||
})
|
||||
|
||||
test('slug_url_ref: a feature branch', () => {
|
||||
test_slug_url_ref('refs/heads/feat/new_feature', 'feat-new-feature')
|
||||
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_slug_url_ref('refs/heads/fix/issue_number', 'fix-issue-number')
|
||||
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: a simple tag', () => {
|
||||
test_slug_url_ref('refs/tags/v1.0.0', 'v1-0-0')
|
||||
test_slugurlref('refs/tags/v1.0.0', 'v1-0-0')
|
||||
test_slugurlref_cs('refs/tags/v1.0.0', 'v1-0-0')
|
||||
})
|
||||
|
||||
test('slug_url_ref: a complex tag', () => {
|
||||
test_slug_url_ref('refs/tags/product@1.0.0-rc.2', 'product-1-0-0-rc-2')
|
||||
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_slug_url_ref('refs/heads/New_Awesome_Product', 'new-awesome-product')
|
||||
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_slug_url_ref(
|
||||
test_slugurlref(
|
||||
'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'
|
||||
)
|
||||
test_slugurlref_cs(
|
||||
'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'
|
||||
)
|
||||
})
|
||||
|
||||
test('slug_url_ref: test trailing', () => {
|
||||
test_slug_url_ref('refs/heads/-an-awesome-Feature-', 'an-awesome-feature')
|
||||
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_slug_url_ref('refs/heads/.an-awesome-Feature.', 'an-awesome-feature')
|
||||
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')
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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: 'node12'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
icon: "crop"
|
||||
color: "orange"
|
||||
icon: "minimize"
|
||||
color: "blue"
|
||||
|
||||
288
dist/index.js
vendored
288
dist/index.js
vendored
@@ -92,6 +92,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(186));
|
||||
const slug_1 = __webpack_require__(565);
|
||||
const short_1 = __webpack_require__(213);
|
||||
const partial_1 = __webpack_require__(373);
|
||||
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
|
||||
@@ -102,20 +105,50 @@ 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';
|
||||
/**
|
||||
* Slugged outputs environments variables keys
|
||||
*/
|
||||
const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG';
|
||||
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL';
|
||||
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_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL';
|
||||
const GITHUB_HEAD_REF_SLUG_URL = 'GITHUB_HEAD_REF_SLUG_URL';
|
||||
const GITHUB_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL';
|
||||
const GITHUB_SHA_SHORT = 'GITHUB_SHA_SHORT';
|
||||
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';
|
||||
/**
|
||||
* 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';
|
||||
/**
|
||||
* 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';
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -124,17 +157,40 @@ function run() {
|
||||
const eventData = yield Promise.resolve().then(() => __importStar(require(eventPath)));
|
||||
if (eventData.hasOwnProperty('ref')) {
|
||||
core.exportVariable(GITHUB_EVENT_REF_SLUG, slug_1.slugref(eventData.ref));
|
||||
core.exportVariable(GITHUB_EVENT_REF_SLUG_CS, slug_1.slugref_cs(eventData.ref));
|
||||
core.exportVariable(GITHUB_EVENT_REF_SLUG_URL, slug_1.slugurlref(eventData.ref));
|
||||
core.exportVariable(GITHUB_EVENT_REF_SLUG_URL_CS, slug_1.slugurlref_cs(eventData.ref));
|
||||
}
|
||||
else if (eventData.hasOwnProperty('pull_request')) {
|
||||
core.exportVariable(GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT, short_1.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);
|
||||
}
|
||||
catch (error) {
|
||||
@@ -142,24 +198,116 @@ function run() {
|
||||
}
|
||||
});
|
||||
}
|
||||
function exportFirstPart(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, partial_1.get_first_part(envVar, separator));
|
||||
}
|
||||
}
|
||||
function exportSecondPart(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, partial_1.get_second_part(envVar, separator));
|
||||
}
|
||||
}
|
||||
function exportSlugCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slug_cs(envVar));
|
||||
}
|
||||
}
|
||||
function exportSlug(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slug(envVar));
|
||||
}
|
||||
}
|
||||
function exportFirstPartSlugCS(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_first_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slug_cs(value));
|
||||
}
|
||||
}
|
||||
function exportFirstPartSlug(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_first_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slug(value));
|
||||
}
|
||||
}
|
||||
function exportSecondPartSlugCS(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_second_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slug_cs(value));
|
||||
}
|
||||
}
|
||||
function exportSecondPartSlug(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_second_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slug(value));
|
||||
}
|
||||
}
|
||||
function exportSlugRefCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugref_cs(envVar));
|
||||
}
|
||||
}
|
||||
function exportSlugRef(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugref(envVar));
|
||||
}
|
||||
}
|
||||
function exportSlugUrlCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugurl_cs(envVar));
|
||||
}
|
||||
}
|
||||
function exportSlugUrl(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugurl(envVar));
|
||||
}
|
||||
}
|
||||
function exportFirstPartSlugUrlCS(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_first_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slugurl_cs(value));
|
||||
}
|
||||
}
|
||||
function exportFirstPartSlugUrl(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_first_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slugurl(value));
|
||||
}
|
||||
}
|
||||
function exportSecondPartSlugUrlCS(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_second_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slugurl_cs(value));
|
||||
}
|
||||
}
|
||||
function exportSecondPartSlugUrl(inputKey, separator, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
const value = partial_1.get_second_part(envVar, separator);
|
||||
core.exportVariable(outputKey, slug_1.slugurl(value));
|
||||
}
|
||||
}
|
||||
function exportSlugUrlRefCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugurlref_cs(envVar));
|
||||
}
|
||||
}
|
||||
function exportSlugUrlRef(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
@@ -169,7 +317,7 @@ function exportSlugUrlRef(inputKey, outputKey) {
|
||||
function exportShortSha(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.shortsha(envVar));
|
||||
core.exportVariable(outputKey, short_1.shortsha(envVar));
|
||||
}
|
||||
}
|
||||
run();
|
||||
@@ -420,6 +568,27 @@ function getState(name) {
|
||||
exports.getState = getState;
|
||||
//# sourceMappingURL=core.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 213:
|
||||
/***/ (function(__unusedmodule, exports) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.shortsha = void 0;
|
||||
const SHORT_SHA_SIZE = 8;
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - limit the string size to 8 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function shortsha(envVar) {
|
||||
return envVar.substring(0, SHORT_SHA_SIZE);
|
||||
}
|
||||
exports.shortsha = shortsha;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 278:
|
||||
@@ -532,6 +701,35 @@ function escapeProperty(s) {
|
||||
}
|
||||
//# sourceMappingURL=command.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 373:
|
||||
/***/ (function(__unusedmodule, exports) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.get_second_part = exports.get_first_part = void 0;
|
||||
/**
|
||||
* Get the first part of envVar
|
||||
* @param envVar to be split
|
||||
* @param separator of the split
|
||||
*/
|
||||
function get_first_part(envVar, separator) {
|
||||
return envVar.replace(RegExp(`${separator}.*$`), '');
|
||||
}
|
||||
exports.get_first_part = get_first_part;
|
||||
/**
|
||||
* Get the second part of envVar
|
||||
* @param envVar to be split
|
||||
* @param separator of the split
|
||||
*/
|
||||
function get_second_part(envVar, separator) {
|
||||
return envVar.replace(RegExp(`^.*${separator}`), '');
|
||||
}
|
||||
exports.get_second_part = get_second_part;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 565:
|
||||
@@ -540,9 +738,19 @@ function escapeProperty(s) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.shortsha = exports.slugurlref = exports.slugurl = exports.slugref = exports.slug = void 0;
|
||||
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 SHORT_SHA_SIZE = 8;
|
||||
/**
|
||||
* slug_cs will take envVar and then :
|
||||
* - replace any character by `-` except `0-9`, `a-z`, and `.`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function slug_cs(envVar) {
|
||||
return trailHyphen(replaceAnyNonAlphanumericCharacter(envVar)).substring(0, MAX_SLUG_STRING_SIZE);
|
||||
}
|
||||
exports.slug_cs = slug_cs;
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - put the variable content in lower case
|
||||
@@ -552,12 +760,24 @@ const SHORT_SHA_SIZE = 8;
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function slug(envVar) {
|
||||
return trailHyphen(replaceAnyNonAlphanumericCaracter(envVar.toLowerCase())).substring(0, MAX_SLUG_STRING_SIZE);
|
||||
return slug_cs(envVar.toLowerCase());
|
||||
}
|
||||
exports.slug = slug;
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - remove refs/(heads|tags)/
|
||||
* slugref_cs will take envVar and then :
|
||||
* - remove refs/(heads|tags|pull)/
|
||||
* - replace any character by `-` except `0-9`, `a-z`, and `.`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function slugref_cs(envVar) {
|
||||
return slug_cs(removeRef(envVar));
|
||||
}
|
||||
exports.slugref_cs = slugref_cs;
|
||||
/**
|
||||
* 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 and trailing `-` character
|
||||
@@ -565,11 +785,22 @@ exports.slug = slug;
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function slugref(envVar) {
|
||||
return slug(removeRef(envVar.toLowerCase()));
|
||||
return slugref_cs(envVar.toLowerCase());
|
||||
}
|
||||
exports.slugref = slugref;
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* slugurl_cs will take envVar and then :
|
||||
* - replace any character by `-` except `0-9`, `a-z`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function slugurl_cs(envVar) {
|
||||
return slug_cs(replaceAnyDotToHyphen(envVar));
|
||||
}
|
||||
exports.slugurl_cs = slugurl_cs;
|
||||
/**
|
||||
* slugurl will take envVar and then :
|
||||
* - put the variable content in lower case
|
||||
* - replace any character by `-` except `0-9`, `a-z`
|
||||
* - remove leading and trailing `-` character
|
||||
@@ -581,8 +812,20 @@ function slugurl(envVar) {
|
||||
}
|
||||
exports.slugurl = slugurl;
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - remove refs/(heads|tags)/
|
||||
* slugurlref_cs will take envVar and then :
|
||||
* - remove refs/(heads|tags|pull)/
|
||||
* - replace any character by `-` except `0-9`, `a-z`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function slugurlref_cs(envVar) {
|
||||
return slugurl_cs(slugref_cs(envVar));
|
||||
}
|
||||
exports.slugurlref_cs = slugurlref_cs;
|
||||
/**
|
||||
* 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 and trailing `-` character
|
||||
@@ -593,26 +836,17 @@ function slugurlref(envVar) {
|
||||
return slugurl(slugref(envVar));
|
||||
}
|
||||
exports.slugurlref = slugurlref;
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - limit the string size to 8 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
function shortsha(envVar) {
|
||||
return envVar.substring(0, SHORT_SHA_SIZE);
|
||||
}
|
||||
exports.shortsha = shortsha;
|
||||
function trailHyphen(envVar) {
|
||||
return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '');
|
||||
}
|
||||
function replaceAnyNonAlphanumericCaracter(envVar) {
|
||||
return envVar.replace(RegExp('[^a-z0-9.]', 'g'), '-');
|
||||
function replaceAnyNonAlphanumericCharacter(envVar) {
|
||||
return envVar.replace(RegExp('[^a-zA-Z0-9.]', 'g'), '-');
|
||||
}
|
||||
function replaceAnyDotToHyphen(envVar) {
|
||||
return envVar.replace(RegExp('[.]', 'g'), '-');
|
||||
}
|
||||
function removeRef(envVar) {
|
||||
return envVar.replace(RegExp('^refs/(heads|tags)/'), '');
|
||||
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '');
|
||||
}
|
||||
|
||||
|
||||
|
||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
96
docs/github-variables.md
Normal file
96
docs/github-variables.md
Normal 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
28
docs/partial-variables.md
Normal 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
27
docs/short-variables.md
Normal 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
109
docs/slug-url-variables.md
Normal 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
105
docs/slug-variables.md
Normal 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
|
||||
34
examples/linux-usage.yml
Normal file
34
examples/linux-usage.yml
Normal 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
34
examples/macos-usage.yml
Normal 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
20
examples/url-use.yml
Normal 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.mycompany.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.mycompany.com/${{ env.GITHUB_REF_SLUG_URL }}"
|
||||
34
examples/windows-usage.yml
Normal file
34
examples/windows-usage.yml
Normal 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"
|
||||
20612
package-lock.json
generated
20612
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@@ -29,21 +29,21 @@
|
||||
"@actions/core": "^1.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/changelog": "5.0.1",
|
||||
"@semantic-release/git": "9.0.0",
|
||||
"@types/jest": "^26.0.10",
|
||||
"@types/node": "^14.6.0",
|
||||
"@semantic-release/changelog": "^5.0.1",
|
||||
"@semantic-release/git": "^9.0.0",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/node": "^14.14.21",
|
||||
"@typescript-eslint/parser": "^3.9.1",
|
||||
"@vercel/ncc": "^0.23.0",
|
||||
"eslint": "^7.5.0",
|
||||
"eslint": "^7.18.0",
|
||||
"eslint-plugin-github": "^4.1.1",
|
||||
"eslint-plugin-jest": "^23.20.0",
|
||||
"jest": "^26.4.2",
|
||||
"jest-circus": "^26.4.1",
|
||||
"js-yaml": "^3.14.0",
|
||||
"prettier": "2.0.5",
|
||||
"semantic-release": "17.0.7",
|
||||
"ts-jest": "^26.3.0",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"js-yaml": "^3.14.1",
|
||||
"prettier": "^2.2.1",
|
||||
"semantic-release": "^17.4.0",
|
||||
"ts-jest": "^26.4.4",
|
||||
"typescript": "^3.9.7"
|
||||
},
|
||||
"release": {
|
||||
@@ -56,8 +56,8 @@
|
||||
"@semantic-release/github"
|
||||
],
|
||||
"branches": [
|
||||
"v1.1.x",
|
||||
"v2.x"
|
||||
"v2.x",
|
||||
"v3.x"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
270
src/main.ts
270
src/main.ts
@@ -1,5 +1,18 @@
|
||||
import * as core from '@actions/core'
|
||||
import {slugref, slug, slugurl, slugurlref, shortsha} from './slug'
|
||||
import {
|
||||
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
|
||||
@@ -12,20 +25,60 @@ 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'
|
||||
|
||||
/**
|
||||
* Slugged outputs environments variables keys
|
||||
*/
|
||||
const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG'
|
||||
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL'
|
||||
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_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL'
|
||||
const GITHUB_HEAD_REF_SLUG_URL = 'GITHUB_HEAD_REF_SLUG_URL'
|
||||
const GITHUB_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL'
|
||||
const GITHUB_SHA_SHORT = 'GITHUB_SHA_SHORT'
|
||||
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'
|
||||
|
||||
/**
|
||||
* 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'
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
@@ -34,24 +87,85 @@ async function run(): Promise<void> {
|
||||
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)
|
||||
} catch (error) {
|
||||
@@ -59,6 +173,34 @@ async function run(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -66,6 +208,61 @@ function exportSlug(inputKey: string, outputKey: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
core.exportVariable(outputKey, slugref_cs(envVar))
|
||||
}
|
||||
}
|
||||
|
||||
function exportSlugRef(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
@@ -73,6 +270,12 @@ function exportSlugRef(inputKey: string, outputKey: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -80,6 +283,61 @@ function exportSlugUrl(inputKey: string, outputKey: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
core.exportVariable(outputKey, slugurlref_cs(envVar))
|
||||
}
|
||||
}
|
||||
|
||||
function exportSlugUrlRef(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
|
||||
17
src/partial.ts
Normal file
17
src/partial.ts
Normal 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
10
src/short.ts
Normal 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)
|
||||
}
|
||||
91
src/slug.ts
91
src/slug.ts
@@ -1,35 +1,69 @@
|
||||
const MAX_SLUG_STRING_SIZE = 63
|
||||
const SHORT_SHA_SIZE = 8
|
||||
|
||||
/**
|
||||
* slug_cs will take envVar and then :
|
||||
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
export function slug_cs(envVar: string): string {
|
||||
return trailHyphen(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 `.`
|
||||
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
export function slug(envVar: string): string {
|
||||
return trailHyphen(
|
||||
replaceAnyNonAlphanumericCaracter(envVar.toLowerCase())
|
||||
).substring(0, MAX_SLUG_STRING_SIZE)
|
||||
return slug_cs(envVar.toLowerCase())
|
||||
}
|
||||
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - remove refs/(heads|tags)/
|
||||
* slugref_cs will take envVar and then :
|
||||
* - remove refs/(heads|tags|pull)/
|
||||
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 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 `.`
|
||||
* - replace any character by `-` except `0-9`, `a-z`, `.`, and `_`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
export function slugref(envVar: string): string {
|
||||
return slug(removeRef(envVar.toLowerCase()))
|
||||
return slugref_cs(envVar.toLowerCase())
|
||||
}
|
||||
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* slugurl_cs will take envVar and then :
|
||||
* - replace any character by `-` except `0-9`, `a-z`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 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 and trailing `-` character
|
||||
@@ -37,12 +71,24 @@ export function slugref(envVar: string): string {
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
export function slugurl(envVar: string): string {
|
||||
return slug(replaceAnyDotToHyphen(envVar))
|
||||
return slug(replaceAnyNonUrlCharactersWithHyphen(envVar))
|
||||
}
|
||||
|
||||
/**
|
||||
* slug will take envVar and then :
|
||||
* - remove refs/(heads|tags)/
|
||||
* slugurlref_cs will take envVar and then :
|
||||
* - remove refs/(heads|tags|pull)/
|
||||
* - replace any character by `-` except `0-9`, `a-z`
|
||||
* - remove leading and trailing `-` character
|
||||
* - limit the string size to 63 characters
|
||||
* @param envVar to be slugged
|
||||
*/
|
||||
export function slugurlref_cs(envVar: string): string {
|
||||
return slugurl_cs(slugref_cs(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 and trailing `-` character
|
||||
@@ -53,27 +99,18 @@ export function slugurlref(envVar: string): string {
|
||||
return slugurl(slugref(envVar))
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
|
||||
function trailHyphen(envVar: string): string {
|
||||
return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '')
|
||||
}
|
||||
|
||||
function replaceAnyNonAlphanumericCaracter(envVar: string): string {
|
||||
return envVar.replace(RegExp('[^a-z0-9.]', 'g'), '-')
|
||||
function replaceAnyNonAlphanumericCharacter(envVar: string): string {
|
||||
return envVar.replace(RegExp('[^a-zA-Z0-9._]', 'g'), '-')
|
||||
}
|
||||
|
||||
function replaceAnyDotToHyphen(envVar: string): string {
|
||||
return envVar.replace(RegExp('[.]', 'g'), '-')
|
||||
function replaceAnyNonUrlCharactersWithHyphen(envVar: string): string {
|
||||
return envVar.replace(RegExp('[._]', 'g'), '-')
|
||||
}
|
||||
|
||||
function removeRef(envVar: string): string {
|
||||
return envVar.replace(RegExp('^refs/(heads|tags)/'), '')
|
||||
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user