mirror of
https://github.com/rlespinasse/shortify-git-revision.git
synced 2026-06-11 16:42:45 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c90ba7007e | ||
|
|
3b1b863e54 | ||
|
|
4c6b226848 | ||
|
|
8198b7ea44 |
28
.github/workflows/shortify-git-revision.yaml
vendored
28
.github/workflows/shortify-git-revision.yaml
vendored
@@ -1,5 +1,9 @@
|
|||||||
name: Shortify Git Revision
|
name: Shortify Git Revision
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- v1.x
|
||||||
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
os-testing:
|
os-testing:
|
||||||
strategy:
|
strategy:
|
||||||
@@ -13,6 +17,7 @@ jobs:
|
|||||||
|
|
||||||
# Test 1
|
# Test 1
|
||||||
- name: Shortify an existing git revision
|
- name: Shortify an existing git revision
|
||||||
|
id: shortify-an-existing-git-revision
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
name: ROOT_COMMIT
|
name: ROOT_COMMIT
|
||||||
@@ -21,6 +26,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
[[ "${{ env.ROOT_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
[[ "${{ env.ROOT_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
||||||
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "88428f5" ]]
|
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "88428f5" ]]
|
||||||
|
[[ "${{ env.ROOT_COMMIT }}" == "${{ steps.shortify-an-existing-git-revision.outputs.revision }}" ]]
|
||||||
|
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "${{ steps.shortify-an-existing-git-revision.outputs.short }}" ]]
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
# Test 2
|
# Test 2
|
||||||
@@ -134,6 +141,22 @@ jobs:
|
|||||||
[[ "${{ env.WRONGFULLY_SIZED_REVISION_SHORT }}" == "88428f5" ]]
|
[[ "${{ env.WRONGFULLY_SIZED_REVISION_SHORT }}" == "88428f5" ]]
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
# Test 10
|
||||||
|
- name: Shortify an existing git revision without env publication
|
||||||
|
id: shortify-an-existing-git-revision-without-env-publication
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
name: SHORT_WITHOUT_ENV_PUBLICATION
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
publish-env: false
|
||||||
|
- name: Validate // Shortify an existing git revision without env publication
|
||||||
|
run: |
|
||||||
|
[[ -z "${{ env.SHORT_WITHOUT_ENV_PUBLICATION }}" ]]
|
||||||
|
[[ -z "${{ env.SHORT_WITHOUT_ENV_PUBLICATION }}" ]]
|
||||||
|
[[ "${{ steps.shortify-an-existing-git-revision-without-env-publication.outputs.revision }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
||||||
|
[[ "${{ steps.shortify-an-existing-git-revision-without-env-publication.outputs.short }}" == "88428f5" ]]
|
||||||
|
shell: bash
|
||||||
|
|
||||||
error-os-testing:
|
error-os-testing:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@@ -162,6 +185,7 @@ jobs:
|
|||||||
|
|
||||||
# Test 2
|
# Test 2
|
||||||
- name: Short on error
|
- name: Short on error
|
||||||
|
id: short-on-error
|
||||||
uses: ./this-action
|
uses: ./this-action
|
||||||
with:
|
with:
|
||||||
name: ROOT_COMMIT
|
name: ROOT_COMMIT
|
||||||
@@ -172,6 +196,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
[[ "${{ env.ROOT_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
[[ "${{ env.ROOT_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
||||||
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "88428f5" ]]
|
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "88428f5" ]]
|
||||||
|
[[ "${{ env.ROOT_COMMIT }}" == "${{ steps.short-on-error.outputs.revision }}" ]]
|
||||||
|
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "${{ steps.short-on-error.outputs.short }}" ]]
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
release:
|
release:
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -68,6 +68,19 @@ If a revision is a bad revision, this action will produce an error message and f
|
|||||||
- `SIZED_REVISION`
|
- `SIZED_REVISION`
|
||||||
- `SIZED_REVISION_SHORT` (with value `88428f56bd`)
|
- `SIZED_REVISION_SHORT` (with value `88428f56bd`)
|
||||||
|
|
||||||
|
- Shortify without publishing the environment variables
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: rlespinasse/shortify-git-revision@v1
|
||||||
|
with:
|
||||||
|
name: GITHUB_SHA
|
||||||
|
```
|
||||||
|
|
||||||
|
Will **not** make available
|
||||||
|
|
||||||
|
- `GITHUB_SHA_SHORT`
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
### `name`
|
### `name`
|
||||||
@@ -107,3 +120,10 @@ This input is _Optional_.
|
|||||||
the `short` sha produce will have the length defined by the input.
|
the `short` sha produce will have the length defined by the input.
|
||||||
|
|
||||||
This input is _Optional_.
|
This input is _Optional_.
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
| Output | Description |
|
||||||
|
| -------- | --------------------------- |
|
||||||
|
| revision | The revision to be shortify |
|
||||||
|
| short | Revision Short |
|
||||||
|
|||||||
21
action.yml
21
action.yml
@@ -1,6 +1,9 @@
|
|||||||
name: "Shortify Git Revision"
|
name: "Shortify Git Revision"
|
||||||
description: "Github Action to shortify a git revision"
|
description: "Github Action to shortify a git revision"
|
||||||
author: "Romain Lespinasse"
|
author: "Romain Lespinasse"
|
||||||
|
branding:
|
||||||
|
icon: "crop"
|
||||||
|
color: "gray-dark"
|
||||||
inputs:
|
inputs:
|
||||||
name:
|
name:
|
||||||
description: "Environment variable that will hold the value and serve as prefix to shortify value"
|
description: "Environment variable that will hold the value and serve as prefix to shortify value"
|
||||||
@@ -24,13 +27,22 @@ inputs:
|
|||||||
description: "Value to configure the length of the shorted sha"
|
description: "Value to configure the length of the shorted sha"
|
||||||
default: ""
|
default: ""
|
||||||
required: false
|
required: false
|
||||||
branding:
|
publish-env:
|
||||||
icon: "crop"
|
description: "Publish short as environment variable"
|
||||||
color: "gray-dark"
|
default: "true"
|
||||||
|
required: false
|
||||||
|
outputs:
|
||||||
|
revision:
|
||||||
|
description: "The revision to be shortify"
|
||||||
|
value: ${{ steps.shortify.outputs.revision }}
|
||||||
|
short:
|
||||||
|
description: "Revision Short"
|
||||||
|
value: ${{ steps.shortify.outputs.short }}
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- run: $GITHUB_ACTION_PATH/shortify.sh
|
- id: shortify
|
||||||
|
run: $GITHUB_ACTION_PATH/shortify.sh
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
INPUT_NAME: ${{ inputs.name }}
|
INPUT_NAME: ${{ inputs.name }}
|
||||||
@@ -39,3 +51,4 @@ runs:
|
|||||||
INPUT_SHORT_ON_ERROR: ${{ inputs.short-on-error }}
|
INPUT_SHORT_ON_ERROR: ${{ inputs.short-on-error }}
|
||||||
INPUT_PREFIX: ${{ inputs.prefix }}
|
INPUT_PREFIX: ${{ inputs.prefix }}
|
||||||
INPUT_LENGTH: ${{ inputs.length }}
|
INPUT_LENGTH: ${{ inputs.length }}
|
||||||
|
INPUT_PUBLISH_ENV: ${{ inputs.publish-env }}
|
||||||
|
|||||||
32
shortify.sh
32
shortify.sh
@@ -27,22 +27,36 @@ if [ -z "${REVISION}" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SHORT_PUBLICATION=false
|
||||||
if [ "$(git cat-file -e "${REVISION}" 2>&1)" == "" ]; then
|
if [ "$(git cat-file -e "${REVISION}" 2>&1)" == "" ]; then
|
||||||
{
|
SHORT_VALUE=$(git rev-parse --short"${SHORT_LENGTH}" "${REVISION}")
|
||||||
echo "${PREFIX}${NAME}=${REVISION}"
|
SHORT_PUBLICATION="true"
|
||||||
echo "${PREFIX}${NAME}_SHORT=$(git rev-parse --short"${SHORT_LENGTH}" "${REVISION}")"
|
|
||||||
} >>"$GITHUB_ENV"
|
|
||||||
elif [ "${INPUT_SHORT_ON_ERROR}" == "true" ]; then
|
elif [ "${INPUT_SHORT_ON_ERROR}" == "true" ]; then
|
||||||
if [ -n "${INPUT_LENGTH}" ]; then
|
if [ -n "${INPUT_LENGTH}" ]; then
|
||||||
{
|
SHORT_VALUE=$(cut -c1-"${INPUT_LENGTH}" <<<"${REVISION}")
|
||||||
echo "${PREFIX}${NAME}=${REVISION}"
|
SHORT_PUBLICATION="true"
|
||||||
echo "${PREFIX}${NAME}_SHORT=$(cut -c1-"${INPUT_LENGTH}" <<<"${REVISION}")"
|
|
||||||
} >>"$GITHUB_ENV"
|
|
||||||
else
|
else
|
||||||
echo "::error ::The input 'lenght' is mandatory with 'short-on-error' set to 'true'"
|
echo "::error ::The input 'length' is mandatory with 'short-on-error' set to 'true'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
|
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
|
||||||
echo "::error ::Invalid revision: ${REVISION} from ${NAME}"
|
echo "::error ::Invalid revision: ${REVISION} from ${NAME}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "${SHORT_PUBLICATION}" == "true" ]; then
|
||||||
|
if [ -f "$GITHUB_OUTPUT" ]; then
|
||||||
|
echo "revision=${REVISION}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "short=${SHORT_VALUE}" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "::set-output name=revision::${REVISION}"
|
||||||
|
echo "::set-output name=short::${SHORT_VALUE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then
|
||||||
|
{
|
||||||
|
echo "${PREFIX}${NAME}=${REVISION}"
|
||||||
|
echo "${PREFIX}${NAME}_SHORT=${SHORT_VALUE}"
|
||||||
|
} >>"$GITHUB_ENV"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user