4 Commits
v1.4.0 ... v1

Author SHA1 Message Date
Romain Lespinasse
c90ba7007e feat: support GHES step output management 2022-10-31 19:45:56 +01:00
Romain Lespinasse
3b1b863e54 fix: use environment file to manage outputs 2022-10-15 21:26:27 +02:00
rlespinasse
4c6b226848 feat: expose short value as output 2022-04-17 21:03:27 +02:00
Romain Lespinasse
8198b7ea44 ci: enable build on fork pull request 2022-03-27 07:27:36 +02:00
4 changed files with 87 additions and 14 deletions

View File

@@ -1,5 +1,9 @@
name: Shortify Git Revision
on: [push]
on:
push:
branches:
- v1.x
pull_request:
jobs:
os-testing:
strategy:
@@ -13,6 +17,7 @@ jobs:
# Test 1
- name: Shortify an existing git revision
id: shortify-an-existing-git-revision
uses: ./
with:
name: ROOT_COMMIT
@@ -21,6 +26,8 @@ jobs:
run: |
[[ "${{ env.ROOT_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
[[ "${{ 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
# Test 2
@@ -134,6 +141,22 @@ jobs:
[[ "${{ env.WRONGFULLY_SIZED_REVISION_SHORT }}" == "88428f5" ]]
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:
strategy:
fail-fast: false
@@ -162,6 +185,7 @@ jobs:
# Test 2
- name: Short on error
id: short-on-error
uses: ./this-action
with:
name: ROOT_COMMIT
@@ -172,6 +196,8 @@ jobs:
run: |
[[ "${{ env.ROOT_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
[[ "${{ 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
release:

View File

@@ -68,6 +68,19 @@ If a revision is a bad revision, this action will produce an error message and f
- `SIZED_REVISION`
- `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
### `name`
@@ -107,3 +120,10 @@ This input is _Optional_.
the `short` sha produce will have the length defined by the input.
This input is _Optional_.
## Outputs
| Output | Description |
| -------- | --------------------------- |
| revision | The revision to be shortify |
| short | Revision Short |

View File

@@ -1,6 +1,9 @@
name: "Shortify Git Revision"
description: "Github Action to shortify a git revision"
author: "Romain Lespinasse"
branding:
icon: "crop"
color: "gray-dark"
inputs:
name:
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"
default: ""
required: false
branding:
icon: "crop"
color: "gray-dark"
publish-env:
description: "Publish short as environment variable"
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:
using: "composite"
steps:
- run: $GITHUB_ACTION_PATH/shortify.sh
- id: shortify
run: $GITHUB_ACTION_PATH/shortify.sh
shell: bash
env:
INPUT_NAME: ${{ inputs.name }}
@@ -39,3 +51,4 @@ runs:
INPUT_SHORT_ON_ERROR: ${{ inputs.short-on-error }}
INPUT_PREFIX: ${{ inputs.prefix }}
INPUT_LENGTH: ${{ inputs.length }}
INPUT_PUBLISH_ENV: ${{ inputs.publish-env }}

View File

@@ -27,22 +27,36 @@ if [ -z "${REVISION}" ]; then
exit 0
fi
SHORT_PUBLICATION=false
if [ "$(git cat-file -e "${REVISION}" 2>&1)" == "" ]; then
{
echo "${PREFIX}${NAME}=${REVISION}"
echo "${PREFIX}${NAME}_SHORT=$(git rev-parse --short"${SHORT_LENGTH}" "${REVISION}")"
} >>"$GITHUB_ENV"
SHORT_VALUE=$(git rev-parse --short"${SHORT_LENGTH}" "${REVISION}")
SHORT_PUBLICATION="true"
elif [ "${INPUT_SHORT_ON_ERROR}" == "true" ]; then
if [ -n "${INPUT_LENGTH}" ]; then
{
echo "${PREFIX}${NAME}=${REVISION}"
echo "${PREFIX}${NAME}_SHORT=$(cut -c1-"${INPUT_LENGTH}" <<<"${REVISION}")"
} >>"$GITHUB_ENV"
SHORT_VALUE=$(cut -c1-"${INPUT_LENGTH}" <<<"${REVISION}")
SHORT_PUBLICATION="true"
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
fi
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
echo "::error ::Invalid revision: ${REVISION} from ${NAME}"
exit 1
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