feat: support partial GITHUB_REPOSITORY

This commit is contained in:
rlespinasse
2021-01-25 20:49:01 +01:00
committed by Romain Lespinasse
parent 49e1056c70
commit 75ce03b6a0
16 changed files with 467 additions and 71 deletions

View File

@@ -41,18 +41,25 @@ jobs:
- uses: ./ - uses: ./
- name: Output - name: Output
run: | run: |
echo "Partial variables"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART }}"
echo "Slug variables" 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 " ref : ${{ env.GITHUB_REF_SLUG }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}" echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}" echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
echo "Slug URL variables" 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 " ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}" echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}" echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : ${{ env.GITHUB_SHA_SHORT }}" echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}" echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
@@ -64,18 +71,25 @@ jobs:
- uses: ./ - uses: ./
- name: Output - name: Output
run: | run: |
echo "Partial variables"
echo " repository owner : $env:GITHUB_REPOSITORY_OWNER_PART"
echo " repository name : $env:GITHUB_REPOSITORY_NAME_PART"
echo "Slug variables" 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 " ref : $env:GITHUB_REF_SLUG"
echo " head ref : $env:GITHUB_HEAD_REF_SLUG" echo " head ref : $env:GITHUB_HEAD_REF_SLUG"
echo " base ref : $env:GITHUB_BASE_REF_SLUG" echo " base ref : $env:GITHUB_BASE_REF_SLUG"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG" echo " event ref : $env:GITHUB_EVENT_REF_SLUG"
echo " repository : $env:GITHUB_REPOSITORY_SLUG"
echo "Slug URL variables" 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 " ref : $env:GITHUB_REF_SLUG_URL"
echo " head ref : $env:GITHUB_HEAD_REF_SLUG_URL" echo " head ref : $env:GITHUB_HEAD_REF_SLUG_URL"
echo " base ref : $env:GITHUB_BASE_REF_SLUG_URL" echo " base ref : $env:GITHUB_BASE_REF_SLUG_URL"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL" echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL"
echo " repository : $env:GITHUB_REPOSITORY_SLUG_URL"
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : $env:GITHUB_SHA_SHORT" echo " sha : $env:GITHUB_SHA_SHORT"
echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT" echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT"

View File

@@ -14,6 +14,7 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
- [Overview](#overview) - [Overview](#overview)
- [Use this action](#use-this-action) - [Use this action](#use-this-action)
- [Available Environment variables](#available-environment-variables) - [Available Environment variables](#available-environment-variables)
- [Partial variables](#partial-variables)
- [Slug variables](#slug-variables) - [Slug variables](#slug-variables)
- [Slug URL variables](#slug-url-variables) - [Slug URL variables](#slug-url-variables)
- [Short variables](#short-variables) - [Short variables](#short-variables)
@@ -25,7 +26,7 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
## Overview ## Overview
`SLUG` a variable will `SLUG` on a variable will
- put the variable content in lower case - put the variable content in lower case
- replace any character by `-` except `0-9`, `a-z`, and `.` - replace any character by `-` except `0-9`, `a-z`, and `.`
@@ -36,8 +37,9 @@ This GitHub Action will expose the slug/short values of [some GitHub environment
<summary>Others <b>Slug-ish</b> commands are available</summary> <summary>Others <b>Slug-ish</b> commands are available</summary>
<p> <p>
- `SLUG_URL` a variable to have a `slug` variable compliant to be used in an URL (Like `SLUG` but `.` is also replaced by `-`) - `SLUG_URL` on a variable to have a `slug` variable compliant to be used in an URL (Like `SLUG` but `.` is also replaced by `-`)
- `SHORT` a variable will limit the string size to 8 characters (useful for _sha_ value) - `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
</p> </p>
</details> </details>
@@ -59,24 +61,35 @@ Check for more [examples][3] (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][5]. **Note**: If you don't find what you search for, read more about [available `GitHub` variables](docs/github-variables.md), and propose a [new custom variable][5].
### Partial variables
| Variable | Partial version of | Description |
| -------------------------------------------------------------------------------------- | ------------------ | ------------------------------------------------------ |
| [GITHUB_REPOSITORY_OWNER_PART](docs/partial-variables.md#github_repository_owner_part) | GITHUB_REPOSITORY | The Owner part of GITHUB_REPOSITORY variable |
| [GITHUB_REPOSITORY_NAME_PART](docs/partial-variables.md#github_repository_name_part) | GITHUB_REPOSITORY | The Repository name part of GITHUB_REPOSITORY variable |
### Slug variables ### Slug variables
| Variable | Slug version of | Description | | Variable | Slug version of | Description |
| ----------------------------------------------------------------------- | ------------------ | ----------------------------------------------------------------------------------------- | | --------------------------------------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------- |
| [GITHUB_REPOSITORY_SLUG](docs/slug-variables.md#github_repository_slug) | GITHUB_REPOSITORY | The owner and repository name. | | [GITHUB_REPOSITORY_SLUG](docs/slug-variables.md#github_repository_slug) | GITHUB_REPOSITORY | The owner and repository name. |
| [GITHUB_REPOSITORY_OWNER_PART_SLUG](docs/slug-variables.md#github_repository_owner_part_slug) | GITHUB_REPOSITORY_OWNER_PART | The owner name. |
| [GITHUB_REPOSITORY_NAME_PART_SLUG](docs/slug-variables.md#github_repository_name_part_slug) | GITHUB_REPOSITORY_NAME_PART | The repository name. |
| [GITHUB_REF_SLUG](docs/slug-variables.md#github_ref_slug) | GITHUB_REF | The branch or tag ref that triggered the workflow. | | [GITHUB_REF_SLUG](docs/slug-variables.md#github_ref_slug) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
| [GITHUB_HEAD_REF_SLUG](docs/slug-variables.md#github_head_ref_slug) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for forked repositories. | | [GITHUB_HEAD_REF_SLUG](docs/slug-variables.md#github_head_ref_slug) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][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 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](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> |
### Slug URL variables ### Slug URL variables
| Variable | Slug version of | Description | | Variable | Slug URL version of | Description |
| ----------------------------------------------------------------------------------- | ------------------ | ----------------------------------------------------------------------------------------- | | ----------------------------------------------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------- |
| [GITHUB_REPOSITORY_SLUG_URL](docs/slug-url-variables.md#github_repository_slug_url) | GITHUB_REPOSITORY | The owner and repository name. | | [GITHUB_REPOSITORY_SLUG_URL](docs/slug-url-variables.md#github_repository_slug_url) | GITHUB_REPOSITORY | The owner and repository name. |
| [GITHUB_REPOSITORY_OWNER_PART_SLUG_URL](docs/slug-variables.md#github_repository_owner_part_slug_url) | GITHUB_REPOSITORY_OWNER_PART | The owner name. |
| [GITHUB_REPOSITORY_NAME_PART_SLUG_URL](docs/slug-variables.md#github_repository_name_part_slug_url) | GITHUB_REPOSITORY_NAME_PART | The repository name. |
| [GITHUB_REF_SLUG_URL](docs/slug-url-variables.md#github_ref_slug_url) | GITHUB_REF | The branch or tag ref that triggered the workflow. | | [GITHUB_REF_SLUG_URL](docs/slug-url-variables.md#github_ref_slug_url) | GITHUB_REF | The branch or tag ref that triggered the workflow. |
| [GITHUB_HEAD_REF_SLUG_URL](docs/slug-url-variables.md#github_head_ref_slug_url) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for forked repositories. | | [GITHUB_HEAD_REF_SLUG_URL](docs/slug-url-variables.md#github_head_ref_slug_url) | GITHUB_HEAD_REF | The branch of the head repository.<br>Only set for [pull-request][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 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> | | [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> |
### Short variables ### Short variables

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

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

View File

@@ -1,4 +1,4 @@
import {shortsha} from '../src/slug' import {shortsha} from '../src/short'
function test_short_sha(input: string, expected: string) { function test_short_sha(input: string, expected: string) {
let actual = shortsha(input) let actual = shortsha(input)

136
dist/index.js vendored
View File

@@ -92,6 +92,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(186)); const core = __importStar(__webpack_require__(186));
const slug_1 = __webpack_require__(565); 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 * 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 * see https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
@@ -102,20 +105,35 @@ const GITHUB_HEAD_REF = 'GITHUB_HEAD_REF';
const GITHUB_BASE_REF = 'GITHUB_BASE_REF'; const GITHUB_BASE_REF = 'GITHUB_BASE_REF';
const GITHUB_SHA = 'GITHUB_SHA'; const GITHUB_SHA = 'GITHUB_SHA';
const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH'; 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 * Slugged outputs environments variables keys
*/ */
const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG'; const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG';
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL'; const GITHUB_REPOSITORY_OWNER_PART_SLUG = 'GITHUB_REPOSITORY_OWNER_PART_SLUG';
const GITHUB_REPOSITORY_NAME_PART_SLUG = 'GITHUB_REPOSITORY_NAME_PART_SLUG';
const GITHUB_REF_SLUG = 'GITHUB_REF_SLUG'; const GITHUB_REF_SLUG = 'GITHUB_REF_SLUG';
const GITHUB_HEAD_REF_SLUG = 'GITHUB_HEAD_REF_SLUG'; const GITHUB_HEAD_REF_SLUG = 'GITHUB_HEAD_REF_SLUG';
const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG'; const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG';
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG';
/**
* URL-Slugged outputs environments variables keys
*/
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL';
const GITHUB_REPOSITORY_OWNER_PART_SLUG_URL = 'GITHUB_REPOSITORY_OWNER_PART_SLUG_URL';
const GITHUB_REPOSITORY_NAME_PART_SLUG_URL = 'GITHUB_REPOSITORY_NAME_PART_SLUG_URL';
const GITHUB_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL'; const GITHUB_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL';
const GITHUB_HEAD_REF_SLUG_URL = 'GITHUB_HEAD_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_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL';
const GITHUB_SHA_SHORT = 'GITHUB_SHA_SHORT';
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG';
const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL'; const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL';
/**
* 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'; const GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT = 'GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT';
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@@ -128,11 +146,17 @@ function run() {
core.exportVariable(GITHUB_EVENT_REF_SLUG_URL, slug_1.slugurlref(eventData.ref)); core.exportVariable(GITHUB_EVENT_REF_SLUG_URL, slug_1.slugurlref(eventData.ref));
} }
else if (eventData.hasOwnProperty('pull_request')) { else if (eventData.hasOwnProperty('pull_request')) {
core.exportVariable(GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT, slug_1.shortsha(eventData.pull_request.head.sha)); 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); exportSlug(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG);
exportFirstPartSlug(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_OWNER_PART_SLUG);
exportSecondPartSlug(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_NAME_PART_SLUG);
exportSlugUrl(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_URL); exportSlugUrl(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_URL);
exportFirstPartSlugUrl(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_OWNER_PART_SLUG_URL);
exportSecondPartSlugUrl(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_NAME_PART_SLUG_URL);
exportSlugRef(GITHUB_REF, GITHUB_REF_SLUG); exportSlugRef(GITHUB_REF, GITHUB_REF_SLUG);
exportSlugRef(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG); exportSlugRef(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG);
exportSlugRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG); exportSlugRef(GITHUB_BASE_REF, GITHUB_BASE_REF_SLUG);
@@ -146,12 +170,38 @@ 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 exportSlug(inputKey, outputKey) { function exportSlug(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slug_1.slug(envVar)); core.exportVariable(outputKey, slug_1.slug(envVar));
} }
} }
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 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 exportSlugRef(inputKey, outputKey) { function exportSlugRef(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
@@ -164,6 +214,20 @@ function exportSlugUrl(inputKey, outputKey) {
core.exportVariable(outputKey, slug_1.slugurl(envVar)); core.exportVariable(outputKey, slug_1.slugurl(envVar));
} }
} }
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 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 exportSlugUrlRef(inputKey, outputKey) { function exportSlugUrlRef(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
@@ -173,7 +237,7 @@ function exportSlugUrlRef(inputKey, outputKey) {
function exportShortSha(inputKey, outputKey) { function exportShortSha(inputKey, outputKey) {
const envVar = process.env[inputKey]; const envVar = process.env[inputKey];
if (envVar) { if (envVar) {
core.exportVariable(outputKey, slug_1.shortsha(envVar)); core.exportVariable(outputKey, short_1.shortsha(envVar));
} }
} }
run(); run();
@@ -424,6 +488,27 @@ function getState(name) {
exports.getState = getState; exports.getState = getState;
//# sourceMappingURL=core.js.map //# 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: /***/ 278:
@@ -536,6 +621,35 @@ function escapeProperty(s) {
} }
//# sourceMappingURL=command.js.map //# 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: /***/ 565:
@@ -544,9 +658,8 @@ function escapeProperty(s) {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.shortsha = exports.slugurlref = exports.slugurl = exports.slugref = exports.slug = void 0; exports.slugurlref = exports.slugurl = exports.slugref = exports.slug = void 0;
const MAX_SLUG_STRING_SIZE = 63; const MAX_SLUG_STRING_SIZE = 63;
const SHORT_SHA_SIZE = 8;
/** /**
* slug will take envVar and then : * slug will take envVar and then :
* - put the variable content in lower case * - put the variable content in lower case
@@ -597,15 +710,6 @@ function slugurlref(envVar) {
return slugurl(slugref(envVar)); return slugurl(slugref(envVar));
} }
exports.slugurlref = slugurlref; 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) { function trailHyphen(envVar) {
return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), ''); return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '');
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

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

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

View File

@@ -5,6 +5,8 @@
- [Slug URL Variables](#slug-url-variables) - [Slug URL Variables](#slug-url-variables)
- [Table of Contents](#table-of-contents) - [Table of Contents](#table-of-contents)
- [GITHUB_REPOSITORY_SLUG_URL](#github_repository_slug_url) - [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_REF_SLUG_URL](#github_ref_slug_url)
- [GITHUB_HEAD_REF_SLUG_URL](#github_head_ref_slug_url) - [GITHUB_HEAD_REF_SLUG_URL](#github_head_ref_slug_url)
- [GITHUB_BASE_REF_SLUG_URL](#github_base_ref_slug_url) - [GITHUB_BASE_REF_SLUG_URL](#github_base_ref_slug_url)
@@ -17,9 +19,34 @@ Slug URL the environment variable **GITHUB_REPOSITORY**
The owner and repository name. The owner and repository name.
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG_URL | | GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG_URL |
| -------------------------- | -------------------------- | | ---------------------------- | ---------------------------- |
| octocat/Hello-World | octocat-hello-world | | octocat/Hello-World | octocat-hello-world |
| rlespinasse/Hello-World.go | rlespinasse-hello-world-go | | 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 ## GITHUB_REF_SLUG_URL
@@ -67,7 +94,7 @@ _Only set for forked repositories._
Slug URL the variable **github.event.ref** Slug URL the variable **github.event.ref**
The git reference resource associated to triggered webhook. The git reference resource associated to triggered webhook.
_[Only set for `create`, and `delete` webhook events][4]._ _Only set for [`create`, and `delete`][1] events._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG_URL | | GITHUB_REF | GITHUB_HEAD_REF_SLUG_URL |
| ------------------------------ | ------------------------ | | ------------------------------ | ------------------------ |

View File

@@ -5,6 +5,8 @@
- [Slug Variables](#slug-variables) - [Slug Variables](#slug-variables)
- [Table of Contents](#table-of-contents) - [Table of Contents](#table-of-contents)
- [GITHUB_REPOSITORY_SLUG](#github_repository_slug) - [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_REF_SLUG](#github_ref_slug)
- [GITHUB_HEAD_REF_SLUG](#github_head_ref_slug) - [GITHUB_HEAD_REF_SLUG](#github_head_ref_slug)
- [GITHUB_BASE_REF_SLUG](#github_base_ref_slug) - [GITHUB_BASE_REF_SLUG](#github_base_ref_slug)
@@ -17,9 +19,34 @@ Slug the environment variable **GITHUB_REPOSITORY**
The owner and repository name. The owner and repository name.
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG | | GITHUB_REPOSITORY | GITHUB_REPOSITORY_SLUG |
| -------------------------- | -------------------------- | | ---------------------------- | ---------------------------- |
| octocat/Hello-World | octocat-hello-world | | octocat/Hello-World | octocat-hello-world |
| rlespinasse/Hello-World.go | rlespinasse-hello-world.go | | 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 ## GITHUB_REF_SLUG
@@ -41,7 +68,7 @@ _If neither a branch or tag is available for the event type, the variable will n
Slug the environment variable **GITHUB_HEAD_REF** Slug the environment variable **GITHUB_HEAD_REF**
The branch of the head repository. The branch of the head repository.
_Only set for forked repositories._ _Only set for [`pull-request`][1] event and forked repositories._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG | | GITHUB_REF | GITHUB_HEAD_REF_SLUG |
| ------------------------------ | -------------------- | | ------------------------------ | -------------------- |
@@ -54,7 +81,7 @@ _Only set for forked repositories._
Slug the environment variable **GITHUB_BASE_REF** Slug the environment variable **GITHUB_BASE_REF**
The branch of the base repository. The branch of the base repository.
_Only set for forked repositories._ _Only set for [`pull-request`][1] event and forked repositories._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG | | GITHUB_REF | GITHUB_HEAD_REF_SLUG |
| ------------------------------ | -------------------- | | ------------------------------ | -------------------- |
@@ -67,7 +94,7 @@ _Only set for forked repositories._
Slug the variable **github.event.ref** Slug the variable **github.event.ref**
The git reference resource associated to triggered webhook. The git reference resource associated to triggered webhook.
_[Only set for `create`, and `delete` webhook events][4]._ _Only set for [`create`, and `delete`][1] events._
| GITHUB_REF | GITHUB_HEAD_REF_SLUG | | GITHUB_REF | GITHUB_HEAD_REF_SLUG |
| ------------------------------ | -------------------- | | ------------------------------ | -------------------- |

View File

@@ -10,18 +10,25 @@ jobs:
- uses: rlespinasse/github-slug-action@v3.x - uses: rlespinasse/github-slug-action@v3.x
- name: Output - name: Output
run: | run: |
echo "Partial variables"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART }}"
echo "Slug variables" 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 " ref : ${{ env.GITHUB_REF_SLUG }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}" echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}" echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
echo "Slug URL variables" 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 " ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}" echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}" echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : ${{ env.GITHUB_SHA_SHORT }}" echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}" echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"

View File

@@ -10,18 +10,25 @@ jobs:
- uses: rlespinasse/github-slug-action@v3.x - uses: rlespinasse/github-slug-action@v3.x
- name: Output - name: Output
run: | run: |
echo "Partial variables"
echo " repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART }}"
echo " repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART }}"
echo "Slug variables" 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 " ref : ${{ env.GITHUB_REF_SLUG }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}" echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}" echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG }}"
echo "Slug URL variables" 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 " ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}" echo " head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}" echo " base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}" echo " event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
echo " repository : ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : ${{ env.GITHUB_SHA_SHORT }}" echo " sha : ${{ env.GITHUB_SHA_SHORT }}"
echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}" echo " pull request sha : ${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"

View File

@@ -10,18 +10,25 @@ jobs:
- uses: rlespinasse/github-slug-action@v3.x - uses: rlespinasse/github-slug-action@v3.x
- name: Output - name: Output
run: | run: |
echo "Partial variables"
echo " repository owner : $env:GITHUB_REPOSITORY_OWNER_PART"
echo " repository name : $env:GITHUB_REPOSITORY_NAME_PART"
echo "Slug variables" 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 " ref : $env:GITHUB_REF_SLUG"
echo " head ref : $env:GITHUB_HEAD_REF_SLUG" echo " head ref : $env:GITHUB_HEAD_REF_SLUG"
echo " base ref : $env:GITHUB_BASE_REF_SLUG" echo " base ref : $env:GITHUB_BASE_REF_SLUG"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG" echo " event ref : $env:GITHUB_EVENT_REF_SLUG"
echo " repository : $env:GITHUB_REPOSITORY_SLUG"
echo "Slug URL variables" 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 " ref : $env:GITHUB_REF_SLUG_URL"
echo " head ref : $env:GITHUB_HEAD_REF_SLUG_URL" echo " head ref : $env:GITHUB_HEAD_REF_SLUG_URL"
echo " base ref : $env:GITHUB_BASE_REF_SLUG_URL" echo " base ref : $env:GITHUB_BASE_REF_SLUG_URL"
echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL" echo " event ref : $env:GITHUB_EVENT_REF_SLUG_URL"
echo " repository : $env:GITHUB_REPOSITORY_SLUG_URL"
echo "Short SHA variables" echo "Short SHA variables"
echo " sha : $env:GITHUB_SHA_SHORT" echo " sha : $env:GITHUB_SHA_SHORT"
echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT" echo " pull request sha : $env:GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT"

View File

@@ -1,5 +1,9 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {slugref, slug, slugurl, slugurlref, shortsha} from './slug' import {slugref, slug, slugurl, slugurlref} 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 * Inputs environments variables keys from Github actions job
@@ -12,20 +16,40 @@ const GITHUB_BASE_REF = 'GITHUB_BASE_REF'
const GITHUB_SHA = 'GITHUB_SHA' const GITHUB_SHA = 'GITHUB_SHA'
const GITHUB_EVENT_PATH = 'GITHUB_EVENT_PATH' 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 * Slugged outputs environments variables keys
*/ */
const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG' const GITHUB_REPOSITORY_SLUG = 'GITHUB_REPOSITORY_SLUG'
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL' const GITHUB_REPOSITORY_OWNER_PART_SLUG = 'GITHUB_REPOSITORY_OWNER_PART_SLUG'
const GITHUB_REPOSITORY_NAME_PART_SLUG = 'GITHUB_REPOSITORY_NAME_PART_SLUG'
const GITHUB_REF_SLUG = 'GITHUB_REF_SLUG' const GITHUB_REF_SLUG = 'GITHUB_REF_SLUG'
const GITHUB_HEAD_REF_SLUG = 'GITHUB_HEAD_REF_SLUG' const GITHUB_HEAD_REF_SLUG = 'GITHUB_HEAD_REF_SLUG'
const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG' const GITHUB_BASE_REF_SLUG = 'GITHUB_BASE_REF_SLUG'
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG'
/**
* URL-Slugged outputs environments variables keys
*/
const GITHUB_REPOSITORY_SLUG_URL = 'GITHUB_REPOSITORY_SLUG_URL'
const GITHUB_REPOSITORY_OWNER_PART_SLUG_URL =
'GITHUB_REPOSITORY_OWNER_PART_SLUG_URL'
const GITHUB_REPOSITORY_NAME_PART_SLUG_URL =
'GITHUB_REPOSITORY_NAME_PART_SLUG_URL'
const GITHUB_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL' const GITHUB_REF_SLUG_URL = 'GITHUB_REF_SLUG_URL'
const GITHUB_HEAD_REF_SLUG_URL = 'GITHUB_HEAD_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_BASE_REF_SLUG_URL = 'GITHUB_BASE_REF_SLUG_URL'
const GITHUB_SHA_SHORT = 'GITHUB_SHA_SHORT'
const GITHUB_EVENT_REF_SLUG = 'GITHUB_EVENT_REF_SLUG'
const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL' const GITHUB_EVENT_REF_SLUG_URL = 'GITHUB_EVENT_REF_SLUG_URL'
/**
* Shorted outputs environments variables keys
*/
const GITHUB_SHA_SHORT = 'GITHUB_SHA_SHORT'
const GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT = const GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT =
'GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT' 'GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT'
@@ -48,9 +72,32 @@ async function run(): Promise<void> {
} }
} }
exportFirstPart(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_OWNER_PART)
exportSecondPart(GITHUB_REPOSITORY, SEPARATOR, GITHUB_REPOSITORY_NAME_PART)
exportSlug(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG) exportSlug(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG)
exportFirstPartSlug(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_OWNER_PART_SLUG
)
exportSecondPartSlug(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_NAME_PART_SLUG
)
exportSlugUrl(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_URL) exportSlugUrl(GITHUB_REPOSITORY, GITHUB_REPOSITORY_SLUG_URL)
exportFirstPartSlugUrl(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_OWNER_PART_SLUG_URL
)
exportSecondPartSlugUrl(
GITHUB_REPOSITORY,
SEPARATOR,
GITHUB_REPOSITORY_NAME_PART_SLUG_URL
)
exportSlugRef(GITHUB_REF, GITHUB_REF_SLUG) exportSlugRef(GITHUB_REF, GITHUB_REF_SLUG)
exportSlugRef(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG) exportSlugRef(GITHUB_HEAD_REF, GITHUB_HEAD_REF_SLUG)
@@ -66,6 +113,28 @@ 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 exportSlug(inputKey: string, outputKey: string): void { function exportSlug(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
@@ -73,6 +142,30 @@ function exportSlug(inputKey: string, outputKey: string): void {
} }
} }
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 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 exportSlugRef(inputKey: string, outputKey: string): void { function exportSlugRef(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {
@@ -87,6 +180,30 @@ function exportSlugUrl(inputKey: string, outputKey: string): void {
} }
} }
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 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 exportSlugUrlRef(inputKey: string, outputKey: string): void { function exportSlugUrlRef(inputKey: string, outputKey: string): void {
const envVar = process.env[inputKey] const envVar = process.env[inputKey]
if (envVar) { if (envVar) {

17
src/partial.ts Normal file
View File

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

10
src/short.ts Normal file
View File

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

View File

@@ -1,5 +1,4 @@
const MAX_SLUG_STRING_SIZE = 63 const MAX_SLUG_STRING_SIZE = 63
const SHORT_SHA_SIZE = 8
/** /**
* slug will take envVar and then : * slug will take envVar and then :
@@ -53,15 +52,6 @@ export function slugurlref(envVar: string): string {
return slugurl(slugref(envVar)) 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 { function trailHyphen(envVar: string): string {
return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '') return envVar.replace(RegExp('^-*', 'g'), '').replace(RegExp('-*$', 'g'), '')
} }