mirror of
https://github.com/rlespinasse/github-slug-action.git
synced 2026-05-17 18:35:07 +00:00
feat: add GITHUB_REF_NAME env var
GITHUB_REF_NAME will contain the reference name (branch or tag) - based on GITHUB_HEAD_REF in a pull-request event context, - based on GITHUB_REF in others event contexts.
This commit is contained in:
committed by
GitHub
parent
b71a8a1cbc
commit
12a7510630
21
.github/workflows/build-os-dependent.yml
vendored
21
.github/workflows/build-os-dependent.yml
vendored
@@ -41,6 +41,10 @@ jobs:
|
||||
echo "Short SHA variables"
|
||||
echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
|
||||
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
|
||||
echo "Branch Name"
|
||||
echo " raw : ${{ env.GITHUB_BRANCH_NAME }}"
|
||||
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG }}"
|
||||
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL }}"
|
||||
- name: Case Sensitive Output
|
||||
run: |
|
||||
echo "Slug variables"
|
||||
@@ -59,6 +63,9 @@ jobs:
|
||||
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL_CS }}"
|
||||
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL_CS }}"
|
||||
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}"
|
||||
echo "Branch Name"
|
||||
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG_CS }}"
|
||||
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL_CS }}"
|
||||
|
||||
use-on-macos:
|
||||
runs-on: macos-latest
|
||||
@@ -92,6 +99,10 @@ jobs:
|
||||
echo "Short SHA variables"
|
||||
echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
|
||||
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
|
||||
echo "Branch Name"
|
||||
echo " raw : ${{ env.GITHUB_BRANCH_NAME }}"
|
||||
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG }}"
|
||||
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL }}"
|
||||
- name: Case Sensitive Output
|
||||
run: |
|
||||
echo "Slug variables"
|
||||
@@ -110,6 +121,9 @@ jobs:
|
||||
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL_CS }}"
|
||||
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL_CS }}"
|
||||
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}"
|
||||
echo "Branch Name"
|
||||
echo " slug : ${{ env.GITHUB_BRANCH_NAME_SLUG_CS }}"
|
||||
echo " slug url : ${{ env.GITHUB_BRANCH_NAME_SLUG_URL_CS }}"
|
||||
|
||||
use-on-windows:
|
||||
runs-on: windows-latest
|
||||
@@ -143,6 +157,10 @@ jobs:
|
||||
echo "Short SHA variables"
|
||||
echo " sha : $env:GITHUB_SHA_SHORT"
|
||||
echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT"
|
||||
echo "Branch Name"
|
||||
echo " raw : $env:GITHUB_BRANCH_NAME"
|
||||
echo " slug : $env:GITHUB_BRANCH_NAME_SLUG"
|
||||
echo " slug url : $env:GITHUB_BRANCH_NAME_SLUG_URL"
|
||||
- name: Case Sensitive Output
|
||||
run: |
|
||||
echo "Slug variables"
|
||||
@@ -161,3 +179,6 @@ jobs:
|
||||
echo " head ref : $env:GITHUB_HEAD_REF_SLUG_URL_CS"
|
||||
echo " base ref : $env:GITHUB_BASE_REF_SLUG_URL_CS"
|
||||
echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL_CS"
|
||||
echo "Branch Name"
|
||||
echo " slug : $env:GITHUB_BRANCH_NAME_SLUG_CS"
|
||||
echo " slug url : $env:GITHUB_BRANCH_NAME_SLUG_URL_CS"
|
||||
|
||||
2
.github/workflows/release-dryrun.yml
vendored
2
.github/workflows/release-dryrun.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
with:
|
||||
branches: |
|
||||
[
|
||||
"${{ env.GITHUB_REF_SLUG }}"
|
||||
"${{ env.GITHUB_REF_NAME }}"
|
||||
]
|
||||
dry_run: true
|
||||
env:
|
||||
|
||||
44
README.md
44
README.md
@@ -2,7 +2,6 @@
|
||||
|
||||
[![Release][release-badge]][releases]
|
||||
![Lint][lint-badge]
|
||||
[![Public workflows that use this action][use-count-badge]][who-use-it]
|
||||
[![Licence][license-badge]][license]
|
||||
|
||||
This GitHub Action will expose the slug/short values of [some GitHub environment variables][github-env-vars] inside your GitHub workflow.
|
||||
@@ -14,6 +13,7 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
|
||||
- [Overview](#overview)
|
||||
- [Use this action](#use-this-action)
|
||||
- [Available Environment variables](#available-environment-variables)
|
||||
- [Enhanced variables](#enhanced-variables)
|
||||
- [Partial variables](#partial-variables)
|
||||
- [Slug variables](#slug-variables)
|
||||
- [Slug URL variables](#slug-url-variables)
|
||||
@@ -49,6 +49,8 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
|
||||
</p>
|
||||
</details>
|
||||
|
||||
Additional enhanced environment variables can be compute to help you around GitHub environment variables.
|
||||
|
||||
## Use this action
|
||||
|
||||
Add this in your workflow
|
||||
@@ -66,6 +68,14 @@ Check for more [examples][examples] (OS usage, URL use, ...)
|
||||
|
||||
**Note**: If you don't find what you search for, read more about [available `GitHub` variables](docs/github-variables.md), and propose a [new custom variable][custom-variable].
|
||||
|
||||
### Enhanced variables
|
||||
|
||||
- `GITHUB_REF_NAME` will contains the reference name (branch or tag)
|
||||
- based on `GITHUB_HEAD_REF` in a [`pull-request*`][webhooks-and-events] event context,
|
||||
- based on `GITHUB_REF` in others event context.
|
||||
|
||||
**NOTE:** All enhanced variables are available in all **slug** formats.
|
||||
|
||||
### Partial variables
|
||||
|
||||
| Variable | Partial version of | Description |
|
||||
@@ -85,28 +95,28 @@ Check for more [examples][examples] (OS usage, URL use, ...)
|
||||
| [GITHUB_REF_SLUG](docs/slug-variables.md#github_ref_slug) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
|
||||
| [GITHUB_HEAD_REF_SLUG](docs/slug-variables.md#github_head_ref_slug) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][event-pull-request] event and forked repositories. |
|
||||
| [GITHUB_BASE_REF_SLUG](docs/slug-variables.md#github_base_ref_slug) | GITHUB_BASE_REF | The branch of the base repository.<br>Only set for [pull-request][event-pull-request] event and forked repositories. |
|
||||
| [GITHUB_EVENT_REF_SLUG](docs/slug-variables.md#github_event_ref_slug) | _github.event.ref_ | <br>Only set for [following webhook events][4]<ul><li>`create`</li><li>`delete`</li></ul> |
|
||||
| [GITHUB_EVENT_REF_SLUG](docs/slug-variables.md#github_event_ref_slug) | _github.event.ref_ | <br>Only set for [following webhook events][webhooks-and-events]<ul><li>`create`</li><li>`delete`</li></ul> |
|
||||
|
||||
### Slug URL variables
|
||||
|
||||
**NOTE:** `_CS` suffix available
|
||||
|
||||
| Variable | Slug URL version of | Description |
|
||||
| --------------------------------------------------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------- |
|
||||
| [GITHUB_REPOSITORY_SLUG_URL](docs/slug-url-variables.md#github_repository_slug_url) | GITHUB_REPOSITORY | The owner and repository name. |
|
||||
| [GITHUB_REPOSITORY<br>_OWNER_PART_SLUG_URL](docs/slug-variables.md#github_repository_owner_part_slug_url) | GITHUB_REPOSITORY_OWNER_PART | The owner name. |
|
||||
| [GITHUB_REPOSITORY<br>_NAME_PART_SLUG_URL](docs/slug-variables.md#github_repository_name_part_slug_url) | GITHUB_REPOSITORY_NAME_PART | The repository name. |
|
||||
| [GITHUB_REF_SLUG_URL](docs/slug-url-variables.md#github_ref_slug_url) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
|
||||
| [GITHUB_HEAD_REF_SLUG_URL](docs/slug-url-variables.md#github_head_ref_slug_url) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][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> |
|
||||
| Variable | Slug URL version of | Description |
|
||||
| --------------------------------------------------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
||||
| [GITHUB_REPOSITORY_SLUG_URL](docs/slug-url-variables.md#github_repository_slug_url) | GITHUB_REPOSITORY | The owner and repository name. |
|
||||
| [GITHUB_REPOSITORY<br>_OWNER_PART_SLUG_URL](docs/slug-variables.md#github_repository_owner_part_slug_url) | GITHUB_REPOSITORY_OWNER_PART | The owner name. |
|
||||
| [GITHUB_REPOSITORY<br>_NAME_PART_SLUG_URL](docs/slug-variables.md#github_repository_name_part_slug_url) | GITHUB_REPOSITORY_NAME_PART | The repository name. |
|
||||
| [GITHUB_REF_SLUG_URL](docs/slug-url-variables.md#github_ref_slug_url) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
|
||||
| [GITHUB_HEAD_REF_SLUG_URL](docs/slug-url-variables.md#github_head_ref_slug_url) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][webhooks-and-events] event and forked repositories. |
|
||||
| [GITHUB_BASE_REF_SLUG_URL](docs/slug-url-variables.md#github_base_ref_slug_url) | GITHUB_BASE_REF | The branch of the base repository.<br>Only set for [pull-request][webhooks-and-events] event and forked repositories. |
|
||||
| [GITHUB_EVENT_REF_SLUG_URL](docs/slug-url-variables.md#github_event_ref_slug_url) | _github.event.ref_ | <br>Only set for [following webhook events][webhooks-and-events]<ul><li>`create`</li><li>`delete`</li></ul> |
|
||||
|
||||
### Short variables
|
||||
|
||||
| Variable | Short version of | Description |
|
||||
| -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [GITHUB_SHA_SHORT](docs/short-variables.md#github_sha_short) | GITHUB_SHA | The commit SHA that triggered the workflow. |
|
||||
| [GITHUB_EVENT<br>_PULL_REQUEST<br>_HEAD_SHA_SHORT](docs/short-variables.md#github_event_pull_request_head_sha_short) | _github.event<br>.pull_request<br>.head.sha_ | The commit SHA on pull request that trigger workflow.<br>Only set for [following webhook events][4]<ul><li>`pull_request`</li><li>`pull_request_review`</li><li>`pull_request_review_comment`</li><li>`pull_request_target`</li></ul> |
|
||||
| Variable | Short version of | Description |
|
||||
| -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [GITHUB_SHA_SHORT](docs/short-variables.md#github_sha_short) | GITHUB_SHA | The commit SHA that triggered the workflow. |
|
||||
| [GITHUB_EVENT<br>_PULL_REQUEST<br>_HEAD_SHA_SHORT](docs/short-variables.md#github_event_pull_request_head_sha_short) | _github.event<br>.pull_request<br>.head.sha_ | The commit SHA on pull request that trigger workflow.<br>Only set for [following webhook events][webhooks-and-events]<ul><li>`pull_request`</li><li>`pull_request_review`</li><li>`pull_request_review_comment`</li><li>`pull_request_target`</li></ul> |
|
||||
|
||||
## Contribute
|
||||
|
||||
@@ -168,7 +178,6 @@ Please, use the current branch `v3.x` or a version tag (see [releases pages][rel
|
||||
|
||||
[release-badge]: https://img.shields.io/github/workflow/status/rlespinasse/github-slug-action/Release?label=Build&logo=github&style=flat-square
|
||||
[lint-badge]: https://img.shields.io/github/workflow/status/rlespinasse/github-slug-action/Lint?label=Lint&logo=github&style=flat-square
|
||||
[use-count-badge]: https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fapi-git-master.endbug.vercel.app%2Fapi%2Fgithub-actions%2Fused-by%3Faction%3Drlespinasse%2Fgithub-slug-action%26badge%3Dtrue
|
||||
[license-badge]: https://img.shields.io/github/license/rlespinasse/github-slug-action?style=flat-square
|
||||
|
||||
[actions]: https://github.com/rlespinasse/github-slug-action/actions
|
||||
@@ -178,10 +187,9 @@ Please, use the current branch `v3.x` or a version tag (see [releases pages][rel
|
||||
[releases]: https://github.com/rlespinasse/github-slug-action/releases
|
||||
[issue-15]: https://github.com/rlespinasse/github-slug-action/issues/15
|
||||
|
||||
[who-use-it]: https://github.com/search?o=desc&q=rlespinasse/github-slug-action+path%3A.github%2Fworkflows+language%3AYAML&s=&type=Code
|
||||
[github-env-vars]: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables
|
||||
[dependabot]: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot
|
||||
[event-pull-request]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads
|
||||
[webhooks-and-events]: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads
|
||||
[naming-conventions]: https://docs.github.com/en/actions/reference/environment-variables#naming-conventions-for-environment-variables
|
||||
|
||||
[article-1]: https://esensconsulting.medium.com/mettre-en-place-une-ci-cd-angular-avec-github-actions-netlify-ca0b59b99ed8
|
||||
|
||||
51
dist/index.js
vendored
51
dist/index.js
vendored
@@ -110,6 +110,10 @@ const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH';
|
||||
*/
|
||||
const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART';
|
||||
const GITHUB_REPOSITORY_NAME_PART = 'GITHUB_REPOSITORY_NAME_PART';
|
||||
/**
|
||||
* New environments variables keys
|
||||
*/
|
||||
const GITHUB_REF_NAME = 'GITHUB_REF_NAME';
|
||||
/**
|
||||
* Slugged outputs environments variables keys
|
||||
*/
|
||||
@@ -127,6 +131,8 @@ const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG';
|
||||
const GITHUB_BASE_REF_SLUG_CS = 'GITHUB_BASE_REF_SLUG_CS';
|
||||
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG';
|
||||
const GITHUB_EVENT_REF_SLUG_CS = 'GITHUB_EVENT_REF_SLUG_CS';
|
||||
const GITHUB_REF_NAME_SLUG = 'GITHUB_REF_NAME_SLUG';
|
||||
const GITHUB_REF_NAME_SLUG_CS = 'GITHUB_REF_NAME_SLUG_CS';
|
||||
/**
|
||||
* URL-Slugged outputs environments variables keys
|
||||
*/
|
||||
@@ -144,6 +150,8 @@ const GITHUB_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL';
|
||||
const GITHUB_BASE_REF_SLUG_URL_CS = 'GITHUB_BASE_REF_SLUG_URL_CS';
|
||||
const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL';
|
||||
const GITHUB_EVENT_REF_SLUG_URL_CS = 'GITHUB_EVENT_REF_SLUG_URL_CS';
|
||||
const GITHUB_REF_NAME_SLUG_URL = 'GITHUB_REF_NAME_SLUG_URL';
|
||||
const GITHUB_REF_NAME_SLUG_URL_CS = 'GITHUB_REF_NAME_SLUG_URL_CS';
|
||||
/**
|
||||
* Shorted outputs environments variables keys
|
||||
*/
|
||||
@@ -192,6 +200,7 @@ function run() {
|
||||
exportSlugUrlRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL);
|
||||
exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS);
|
||||
exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT);
|
||||
exportBranchName();
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
@@ -253,15 +262,21 @@ function exportSecondPartSlug(inputKey, separator, outputKey) {
|
||||
function exportSlugRefCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugref_cs(envVar));
|
||||
exportSlugRefCSValue(envVar, outputKey);
|
||||
}
|
||||
}
|
||||
function exportSlugRefCSValue(envVar, outputKey) {
|
||||
core.exportVariable(outputKey, slug_1.slugref_cs(envVar));
|
||||
}
|
||||
function exportSlugRef(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugref(envVar));
|
||||
exportSlugRefValue(envVar, outputKey);
|
||||
}
|
||||
}
|
||||
function exportSlugRefValue(envVar, outputKey) {
|
||||
core.exportVariable(outputKey, slug_1.slugref(envVar));
|
||||
}
|
||||
function exportSlugUrlCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
@@ -305,21 +320,45 @@ function exportSecondPartSlugUrl(inputKey, separator, outputKey) {
|
||||
function exportSlugUrlRefCS(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugurlref_cs(envVar));
|
||||
exportSlugUrlRefCSValue(envVar, outputKey);
|
||||
}
|
||||
}
|
||||
function exportSlugUrlRefCSValue(envVar, outputKey) {
|
||||
core.exportVariable(outputKey, slug_1.slugurlref_cs(envVar));
|
||||
}
|
||||
function exportSlugUrlRef(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slug_1.slugurlref(envVar));
|
||||
exportSlugUrlRefValue(envVar, outputKey);
|
||||
}
|
||||
}
|
||||
function exportSlugUrlRefValue(envVar, outputKey) {
|
||||
core.exportVariable(outputKey, slug_1.slugurlref(envVar));
|
||||
}
|
||||
function exportShortSha(inputKey, outputKey) {
|
||||
const envVar = process.env[inputKey];
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, short_1.shortsha(envVar));
|
||||
}
|
||||
}
|
||||
function exportBranchName() {
|
||||
//GITHUB_HEAD_REF is only set for pull request events https://docs.github.com/en/actions/reference/environment-variables
|
||||
const isPullRequest = !!process.env.GITHUB_HEAD_REF;
|
||||
let refName;
|
||||
if (isPullRequest) {
|
||||
refName = process.env.GITHUB_HEAD_REF;
|
||||
}
|
||||
else {
|
||||
refName = process.env.GITHUB_REF;
|
||||
}
|
||||
if (refName) {
|
||||
core.exportVariable(GITHUB_REF_NAME, slug_1.removeRef(refName));
|
||||
exportSlugRefValue(refName, GITHUB_REF_NAME_SLUG);
|
||||
exportSlugRefCSValue(refName, GITHUB_REF_NAME_SLUG_CS);
|
||||
exportSlugUrlRefValue(refName, GITHUB_REF_NAME_SLUG_URL);
|
||||
exportSlugUrlRefCSValue(refName, GITHUB_REF_NAME_SLUG_URL_CS);
|
||||
}
|
||||
}
|
||||
run();
|
||||
|
||||
|
||||
@@ -435,6 +474,7 @@ exports.getInput = getInput;
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function setOutput(name, value) {
|
||||
process.stdout.write(os.EOL);
|
||||
command_1.issueCommand('set-output', { name }, value);
|
||||
}
|
||||
exports.setOutput = setOutput;
|
||||
@@ -738,7 +778,7 @@ exports.get_second_part = get_second_part;
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.slugurlref = exports.slugurlref_cs = exports.slugurl = exports.slugurl_cs = exports.slugref = exports.slugref_cs = exports.slug = exports.slug_cs = void 0;
|
||||
exports.removeRef = exports.slugurlref = exports.slugurlref_cs = exports.slugurl = exports.slugurl_cs = exports.slugref = exports.slugref_cs = exports.slug = exports.slug_cs = void 0;
|
||||
const MAX_SLUG_STRING_SIZE = 63;
|
||||
/**
|
||||
* slug_cs will take envVar and then :
|
||||
@@ -848,6 +888,7 @@ function replaceAnyNonUrlCharactersWithHyphen(envVar) {
|
||||
function removeRef(envVar) {
|
||||
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '');
|
||||
}
|
||||
exports.removeRef = removeRef;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
54
src/main.ts
54
src/main.ts
@@ -1,5 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import {
|
||||
removeRef,
|
||||
slug,
|
||||
slug_cs,
|
||||
slugref,
|
||||
@@ -31,6 +32,11 @@ const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH'
|
||||
const GITHUB_REPOSITORY_OWNER_PART = 'GITHUB_REPOSITORY_OWNER_PART'
|
||||
const GITHUB_REPOSITORY_NAME_PART = 'GITHUB_REPOSITORY_NAME_PART'
|
||||
|
||||
/**
|
||||
* New environments variables keys
|
||||
*/
|
||||
const GITHUB_REF_NAME = 'GITHUB_REF_NAME'
|
||||
|
||||
/**
|
||||
* Slugged outputs environments variables keys
|
||||
*/
|
||||
@@ -50,6 +56,8 @@ const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG'
|
||||
const GITHUB_BASE_REF_SLUG_CS = 'GITHUB_BASE_REF_SLUG_CS'
|
||||
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG'
|
||||
const GITHUB_EVENT_REF_SLUG_CS = 'GITHUB_EVENT_REF_SLUG_CS'
|
||||
const GITHUB_REF_NAME_SLUG = 'GITHUB_REF_NAME_SLUG'
|
||||
const GITHUB_REF_NAME_SLUG_CS = 'GITHUB_REF_NAME_SLUG_CS'
|
||||
|
||||
/**
|
||||
* URL-Slugged outputs environments variables keys
|
||||
@@ -72,6 +80,8 @@ const GITHUB_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL'
|
||||
const GITHUB_BASE_REF_SLUG_URL_CS = 'GITHUB_BASE_REF_SLUG_URL_CS'
|
||||
const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL'
|
||||
const GITHUB_EVENT_REF_SLUG_URL_CS = 'GITHUB_EVENT_REF_SLUG_URL_CS'
|
||||
const GITHUB_REF_NAME_SLUG_URL = 'GITHUB_REF_NAME_SLUG_URL'
|
||||
const GITHUB_REF_NAME_SLUG_URL_CS = 'GITHUB_REF_NAME_SLUG_URL_CS'
|
||||
|
||||
/**
|
||||
* Shorted outputs environments variables keys
|
||||
@@ -168,6 +178,8 @@ async function run(): Promise<void> {
|
||||
exportSlugUrlRefCS(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG_URL_CS)
|
||||
|
||||
exportShortSha(GITHUB_SHA, GITHUB_SHA_SHORT)
|
||||
|
||||
exportBranchName()
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
@@ -259,17 +271,25 @@ function exportSecondPartSlug(
|
||||
function exportSlugRefCS(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slugref_cs(envVar))
|
||||
exportSlugRefCSValue(envVar, outputKey)
|
||||
}
|
||||
}
|
||||
|
||||
function exportSlugRefCSValue(envVar: string, outputKey: string): void {
|
||||
core.exportVariable(outputKey, slugref_cs(envVar))
|
||||
}
|
||||
|
||||
function exportSlugRef(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slugref(envVar))
|
||||
exportSlugRefValue(envVar, outputKey)
|
||||
}
|
||||
}
|
||||
|
||||
function exportSlugRefValue(envVar: string, outputKey: string): void {
|
||||
core.exportVariable(outputKey, slugref(envVar))
|
||||
}
|
||||
|
||||
function exportSlugUrlCS(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
@@ -334,17 +354,25 @@ function exportSecondPartSlugUrl(
|
||||
function exportSlugUrlRefCS(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slugurlref_cs(envVar))
|
||||
exportSlugUrlRefCSValue(envVar, outputKey)
|
||||
}
|
||||
}
|
||||
|
||||
function exportSlugUrlRefCSValue(envVar: string, outputKey: string): void {
|
||||
core.exportVariable(outputKey, slugurlref_cs(envVar))
|
||||
}
|
||||
|
||||
function exportSlugUrlRef(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
core.exportVariable(outputKey, slugurlref(envVar))
|
||||
exportSlugUrlRefValue(envVar, outputKey)
|
||||
}
|
||||
}
|
||||
|
||||
function exportSlugUrlRefValue(envVar: string, outputKey: string): void {
|
||||
core.exportVariable(outputKey, slugurlref(envVar))
|
||||
}
|
||||
|
||||
function exportShortSha(inputKey: string, outputKey: string): void {
|
||||
const envVar = process.env[inputKey]
|
||||
if (envVar) {
|
||||
@@ -352,4 +380,22 @@ function exportShortSha(inputKey: string, outputKey: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
function exportBranchName(): void {
|
||||
//GITHUB_HEAD_REF is only set for pull request events https://docs.github.com/en/actions/reference/environment-variables
|
||||
const isPullRequest = !!process.env.GITHUB_HEAD_REF
|
||||
let refName
|
||||
if (isPullRequest) {
|
||||
refName = process.env.GITHUB_HEAD_REF
|
||||
} else {
|
||||
refName = process.env.GITHUB_REF
|
||||
}
|
||||
if (refName) {
|
||||
core.exportVariable(GITHUB_REF_NAME, removeRef(refName))
|
||||
exportSlugRefValue(refName, GITHUB_REF_NAME_SLUG)
|
||||
exportSlugRefCSValue(refName, GITHUB_REF_NAME_SLUG_CS)
|
||||
exportSlugUrlRefValue(refName, GITHUB_REF_NAME_SLUG_URL)
|
||||
exportSlugUrlRefCSValue(refName, GITHUB_REF_NAME_SLUG_URL_CS)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
@@ -111,6 +111,6 @@ function replaceAnyNonUrlCharactersWithHyphen(envVar: string): string {
|
||||
return envVar.replace(RegExp('[._]', 'g'), '-')
|
||||
}
|
||||
|
||||
function removeRef(envVar: string): string {
|
||||
export function removeRef(envVar: string): string {
|
||||
return envVar.replace(RegExp('^refs/(heads|tags|pull)/'), '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user