mirror of
https://github.com/rlespinasse/shortify-git-revision.git
synced 2026-06-13 01:14:18 +00:00
feat: support prepend text to variable names
This commit is contained in:
19
.github/workflows/shortify-git-revision.yaml
vendored
19
.github/workflows/shortify-git-revision.yaml
vendored
@@ -27,6 +27,19 @@ jobs:
|
||||
shell: bash
|
||||
|
||||
# Test 2
|
||||
- name: Shortify an existing git revision with prefix
|
||||
uses: ./
|
||||
with:
|
||||
name: ROOT_COMMIT
|
||||
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||
prefix: CI_
|
||||
- name: Validate // Shortify an existing git revision with prefix
|
||||
run: |
|
||||
[[ "${{ env.ROOT_COMMIT }}" == "${{ env.CI_ROOT_COMMIT }}" ]]
|
||||
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "${{ env.CI_ROOT_COMMIT_SHORT }}" ]]
|
||||
shell: bash
|
||||
|
||||
# Test 3
|
||||
- name: Shortify an existing git revision from an env variable
|
||||
uses: ./
|
||||
with:
|
||||
@@ -39,7 +52,7 @@ jobs:
|
||||
[[ "${{ env.ENV_VAR_COMMIT_SHORT }}" == "88428f5" ]]
|
||||
shell: bash
|
||||
|
||||
# Test 3
|
||||
# Test 4
|
||||
- name: Shortify a missing git revision
|
||||
uses: ./
|
||||
with:
|
||||
@@ -51,7 +64,7 @@ jobs:
|
||||
[[ -z "${{ env.MISSING_REVISION_SHORT }}" ]]
|
||||
shell: bash
|
||||
|
||||
# Test 4
|
||||
# Test 5
|
||||
- id: test-shortify-wrong-git-revision
|
||||
name: Shortify a wrong git revision
|
||||
uses: ./
|
||||
@@ -67,7 +80,7 @@ jobs:
|
||||
[[ "${{ steps.test-shortify-wrong-git-revision.conclusion }}" == "success" ]]
|
||||
shell: bash
|
||||
|
||||
# Test 5
|
||||
# Test 6
|
||||
- name: Shortify a wrong git revision without failing
|
||||
uses: ./
|
||||
with:
|
||||
|
||||
20
README.md
20
README.md
@@ -21,6 +21,20 @@ If a revision is a bad revision, this action will produce an error message and f
|
||||
|
||||
- `GITHUB_SHA_SHORT`
|
||||
|
||||
- Shortify an environment variable with prefix
|
||||
|
||||
```yaml
|
||||
- uses: rlespinasse/shortify-git-revision@v1.x
|
||||
with:
|
||||
name: GITHUB_SHA
|
||||
prefix: CI_
|
||||
```
|
||||
|
||||
Will make available
|
||||
|
||||
- `CI_GITHUB_SHA`
|
||||
- `CI_GITHUB_SHA_SHORT`
|
||||
|
||||
- Shortify any revision
|
||||
|
||||
```yaml
|
||||
@@ -53,3 +67,9 @@ This input is _Optional_.
|
||||
If the input is set to `true`, this action will not fail on a bad revision
|
||||
|
||||
The default value is `false`.
|
||||
|
||||
### `prefix`
|
||||
|
||||
The value will be prepend to each generated variable.
|
||||
|
||||
This input is _Optional_.
|
||||
|
||||
@@ -12,6 +12,10 @@ inputs:
|
||||
description: "Don't fail the action if the git revision isn't valid"
|
||||
default: "false"
|
||||
required: false
|
||||
prefix:
|
||||
description: "Value to prepend to each generated variable"
|
||||
default: ""
|
||||
required: false
|
||||
branding:
|
||||
icon: "crop"
|
||||
color: "gray-dark"
|
||||
@@ -24,3 +28,4 @@ runs:
|
||||
INPUT_NAME: ${{ inputs.name }}
|
||||
INPUT_REVISION: ${{ inputs.revision }}
|
||||
INPUT_CONTINUE_ON_ERROR: ${{ inputs.continue-on-error }}
|
||||
INPUT_PREFIX: ${{ inputs.prefix }}
|
||||
|
||||
@@ -4,8 +4,10 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# On MacOS,
|
||||
# bash don't support substitution, so we use 'tr'
|
||||
NAME=$(echo "$INPUT_NAME" | tr '[:lower:]' '[:upper:]')
|
||||
PREFIX=$(echo "$INPUT_PREFIX" | tr '[:lower:]' '[:upper:]')
|
||||
else
|
||||
NAME=${INPUT_NAME^^}
|
||||
PREFIX=${INPUT_PREFIX^^}
|
||||
fi
|
||||
REVISION=${INPUT_REVISION:-${!NAME}}
|
||||
|
||||
@@ -15,8 +17,8 @@ fi
|
||||
|
||||
if [ "$(git cat-file -e "$REVISION" 2>&1)" == "" ]; then
|
||||
{
|
||||
echo "${NAME}=${REVISION}"
|
||||
echo "${NAME}_SHORT=$(git rev-parse --short "$REVISION")"
|
||||
echo "${PREFIX}${NAME}=${REVISION}"
|
||||
echo "${PREFIX}${NAME}_SHORT=$(git rev-parse --short "$REVISION")"
|
||||
} >>"$GITHUB_ENV"
|
||||
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
|
||||
echo "::error ::Invalid revision: $REVISION from $NAME"
|
||||
|
||||
Reference in New Issue
Block a user