mirror of
https://github.com/rlespinasse/shortify-git-revision.git
synced 2026-06-11 16:42:45 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b1b863e54 | ||
|
|
4c6b226848 | ||
|
|
8198b7ea44 | ||
|
|
4936ef9a58 | ||
|
|
ef0d40cdf6 | ||
|
|
512ffd9023 | ||
|
|
928e740f90 | ||
|
|
3549754992 | ||
|
|
353f0c732e |
187
.github/workflows/shortify-git-revision.yaml
vendored
187
.github/workflows/shortify-git-revision.yaml
vendored
@@ -1,65 +1,216 @@
|
|||||||
name: Shortify git revision testing
|
name: Shortify Git Revision
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- v1.x
|
||||||
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
shortify-git-revision-on-os:
|
os-testing:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
concurrency:
|
|
||||||
group: shortify-git-revision-on-os-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# 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
|
||||||
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
- name: Test result 1
|
- name: Validate // Shortify an existing git revision
|
||||||
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
|
||||||
|
- 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
|
- name: Shortify an existing git revision from an env variable
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
name: ENV_VAR_COMMIT
|
name: ENV_VAR_COMMIT
|
||||||
env:
|
env:
|
||||||
ENV_VAR_COMMIT: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
ENV_VAR_COMMIT: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
- name: Test result 1
|
- name: Validate // Shortify an existing git revision from an env variable
|
||||||
run: |
|
run: |
|
||||||
[[ "${{ env.ENV_VAR_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
[[ "${{ env.ENV_VAR_COMMIT }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
||||||
[[ "${{ env.ENV_VAR_COMMIT_SHORT }}" == "88428f5" ]]
|
[[ "${{ env.ENV_VAR_COMMIT_SHORT }}" == "88428f5" ]]
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
# Test 3
|
# Test 4
|
||||||
- name: Shortify a missing git revision
|
- name: Shortify a missing git revision
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
name: MISSING_REVISION
|
name: MISSING_REVISION
|
||||||
revision: ""
|
revision: ""
|
||||||
- name: Test result 3
|
- name: Validate // Shortify a missing git revision
|
||||||
run: |
|
run: |
|
||||||
[[ -z "${{ env.MISSING_REVISION }}" ]]
|
[[ -z "${{ env.MISSING_REVISION }}" ]]
|
||||||
[[ -z "${{ env.MISSING_REVISION_SHORT }}" ]]
|
[[ -z "${{ env.MISSING_REVISION_SHORT }}" ]]
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
shortify-git-revision-release:
|
# Test 5
|
||||||
runs-on: ubuntu-latest
|
- id: test-shortify-wrong-git-revision
|
||||||
concurrency:
|
name: Shortify a wrong git revision
|
||||||
group: shortify-git-revision-release-${{ github.ref }}
|
uses: ./
|
||||||
needs: shortify-git-revision-on-os
|
with:
|
||||||
|
name: WRONG_REVISION
|
||||||
|
revision: wrongwrongwrongwrongwrongwrongwrongwrong
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Validate // Shortify a wrong git revision
|
||||||
|
run: |
|
||||||
|
[[ -z "${{ env.WRONG_REVISION }}" ]]
|
||||||
|
[[ -z "${{ env.WRONG_REVISION_SHORT }}" ]]
|
||||||
|
[[ "${{ steps.test-shortify-wrong-git-revision.outcome }}" == "failure" ]]
|
||||||
|
[[ "${{ steps.test-shortify-wrong-git-revision.conclusion }}" == "success" ]]
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
# Test 6
|
||||||
|
- name: Shortify a wrong git revision without failing
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
name: WRONG_AND_MISSING_REVISION
|
||||||
|
revision: wrongwrongwrongwrongwrongwrongwrongwrong
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Validate // Shortify a wrong git revision without failing
|
||||||
|
run: |
|
||||||
|
[[ -z "${{ env.WRONG_AND_MISSING_REVISION }}" ]]
|
||||||
|
[[ -z "${{ env.WRONG_AND_MISSING_REVISION_SHORT }}" ]]
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
# Test 7
|
||||||
|
- name: Shortify a git revision with specific length
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
name: SIZED_REVISION
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
length: 10
|
||||||
|
- name: Validate // Shortify a git revision with specific length
|
||||||
|
run: |
|
||||||
|
[[ "${{ env.SIZED_REVISION }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
||||||
|
[[ "${{ env.SIZED_REVISION_SHORT }}" == "88428f56bd" ]]
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
# Test 8
|
||||||
|
- id: test-shortify-git-revision-with-wrong-length
|
||||||
|
name: Shortify a git revision with wrong length
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
name: WRONGFULLY_SIZED_REVISION
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
length: "not_a_number"
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Validate // Shortify a git revision with wrong length
|
||||||
|
run: |
|
||||||
|
[[ -z "${{ env.WRONGFULLY_SIZED_REVISION }}" ]]
|
||||||
|
[[ -z "${{ env.WRONGFULLY_SIZED_REVISION_SHORT }}" ]]
|
||||||
|
[[ "${{ steps.test-shortify-git-revision-with-wrong-length.outcome }}" == "failure" ]]
|
||||||
|
[[ "${{ steps.test-shortify-git-revision-with-wrong-length.conclusion }}" == "success" ]]
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
# Test 9
|
||||||
|
- name: Shortify a git revision with wrong length without failing
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
name: WRONGFULLY_SIZED_REVISION
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
length: "not_a_number"
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Validate // Shortify a git revision with wrong length without failing
|
||||||
|
run: |
|
||||||
|
[[ "${{ env.WRONGFULLY_SIZED_REVISION }}" == "88428f56bd9d2751c47106bedfd148162dfa50b8" ]]
|
||||||
|
[[ "${{ 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
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: this-action
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
|
# Test 1
|
||||||
|
- name: Continue on error
|
||||||
|
uses: ./this-action
|
||||||
|
with:
|
||||||
|
name: ROOT_COMMIT
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Validate // Continue on error
|
||||||
|
run: |
|
||||||
|
[[ "${{ env.ROOT_COMMIT }}" == "" ]]
|
||||||
|
[[ "${{ env.ROOT_COMMIT_SHORT }}" == "" ]]
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
# Test 2
|
||||||
|
- name: Short on error
|
||||||
|
id: short-on-error
|
||||||
|
uses: ./this-action
|
||||||
|
with:
|
||||||
|
name: ROOT_COMMIT
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
short-on-error: true
|
||||||
|
length: 7
|
||||||
|
- name: Validate // Short on error
|
||||||
|
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:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
concurrency:
|
||||||
|
group: release-${{ github.ref }}
|
||||||
|
needs:
|
||||||
|
- os-testing
|
||||||
|
- error-os-testing
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Release
|
# Release
|
||||||
- name: Release this GitHub Action
|
- name: Release this GitHub Action
|
||||||
uses: rlespinasse/release-that@v1.x
|
uses: rlespinasse/release-that@v1
|
||||||
|
|||||||
101
README.md
101
README.md
@@ -4,25 +4,44 @@
|
|||||||
|
|
||||||
Produce short revision environment variable based on the input one.
|
Produce short revision environment variable based on the input one.
|
||||||
|
|
||||||
|
If a revision is a bad revision, this action will produce an error message and fail depending on `continue-on-error` input (This behavior can be override with `short-on-error` input).
|
||||||
|
`<NAME>`, and `<NAME>_SHORT` environment variable will only be available if the revision is not empty and valid.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
- Shortify an environment variable
|
- Shortify an environment variable
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: rlespinasse/shortify-git-revision@v1.x
|
- uses: actions/checkout@v3
|
||||||
|
- uses: rlespinasse/shortify-git-revision@v1
|
||||||
with:
|
with:
|
||||||
name: GITHUB_SHA
|
name: GITHUB_SHA
|
||||||
revision: value_to_slugify
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Will make available
|
Will make available
|
||||||
|
|
||||||
- `GITHUB_SHA_SHORT`
|
- `GITHUB_SHA_SHORT`
|
||||||
|
|
||||||
|
- Shortify an environment variable with prefix
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: rlespinasse/shortify-git-revision@v1
|
||||||
|
with:
|
||||||
|
name: GITHUB_SHA
|
||||||
|
prefix: CI_
|
||||||
|
```
|
||||||
|
|
||||||
|
Will make available
|
||||||
|
|
||||||
|
- `CI_GITHUB_SHA`
|
||||||
|
- `CI_GITHUB_SHA_SHORT`
|
||||||
|
|
||||||
- Shortify any revision
|
- Shortify any revision
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: rlespinasse/slugify-value@v1.x
|
- uses: actions/checkout@v3
|
||||||
|
- uses: rlespinasse/shortify-git-revision@v1
|
||||||
with:
|
with:
|
||||||
name: SOME_REVISION
|
name: SOME_REVISION
|
||||||
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
@@ -32,3 +51,79 @@ Produce short revision environment variable based on the input one.
|
|||||||
|
|
||||||
- `SOME_REVISION`
|
- `SOME_REVISION`
|
||||||
- `SOME_REVISION_SHORT`
|
- `SOME_REVISION_SHORT`
|
||||||
|
|
||||||
|
- Shortify a revision with a specific length
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: rlespinasse/shortify-git-revision@v1
|
||||||
|
with:
|
||||||
|
name: SIZED_REVISION
|
||||||
|
revision: 88428f56bd9d2751c47106bedfd148162dfa50b8
|
||||||
|
length: 10
|
||||||
|
```
|
||||||
|
|
||||||
|
Will make available
|
||||||
|
|
||||||
|
- `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`
|
||||||
|
|
||||||
|
If used with `revision` input, it's the name of the environment variable containing the revision to shortify.
|
||||||
|
Otherwise, the `name` input will be used (in upper case) to define a environment variable containing the `revision` input value.
|
||||||
|
|
||||||
|
### `revision`
|
||||||
|
|
||||||
|
The revision to shortify into an environment variable named `<NAME>_SHORT`.
|
||||||
|
|
||||||
|
This input is _Optional_.
|
||||||
|
|
||||||
|
### `continue-on-error`
|
||||||
|
|
||||||
|
If the input is set to `true`, this action will not fail on a bad revision
|
||||||
|
|
||||||
|
The default value is `false`.
|
||||||
|
|
||||||
|
### `short-on-error`
|
||||||
|
|
||||||
|
If the input is set to `true`, this action will short a bad revision
|
||||||
|
|
||||||
|
The default value is `false`.
|
||||||
|
|
||||||
|
> If this input is set to `true`, the input `continue-on-error` input will be ignored.
|
||||||
|
> If this input is set to `true`, the input `length` input is mandatory.
|
||||||
|
|
||||||
|
### `prefix`
|
||||||
|
|
||||||
|
The value will be prepend to each generated variable.
|
||||||
|
|
||||||
|
This input is _Optional_.
|
||||||
|
|
||||||
|
### `length`
|
||||||
|
|
||||||
|
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 |
|
||||||
|
|||||||
41
action.yml
41
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"
|
||||||
@@ -8,14 +11,44 @@ inputs:
|
|||||||
revision:
|
revision:
|
||||||
description: "Revision to short"
|
description: "Revision to short"
|
||||||
required: false
|
required: false
|
||||||
branding:
|
continue-on-error:
|
||||||
icon: "crop"
|
description: "Don't fail the action if the git revision isn't valid"
|
||||||
color: "gray-dark"
|
default: "false"
|
||||||
|
required: false
|
||||||
|
short-on-error:
|
||||||
|
description: "Still short it if the git revision isn't valid"
|
||||||
|
default: "false"
|
||||||
|
required: false
|
||||||
|
prefix:
|
||||||
|
description: "Value to prepend to each generated variable"
|
||||||
|
default: ""
|
||||||
|
required: false
|
||||||
|
length:
|
||||||
|
description: "Value to configure the length of the shorted sha"
|
||||||
|
default: ""
|
||||||
|
required: false
|
||||||
|
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:
|
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 }}
|
||||||
INPUT_REVISION: ${{ inputs.revision }}
|
INPUT_REVISION: ${{ inputs.revision }}
|
||||||
|
INPUT_CONTINUE_ON_ERROR: ${{ inputs.continue-on-error }}
|
||||||
|
INPUT_SHORT_ON_ERROR: ${{ inputs.short-on-error }}
|
||||||
|
INPUT_PREFIX: ${{ inputs.prefix }}
|
||||||
|
INPUT_LENGTH: ${{ inputs.length }}
|
||||||
|
INPUT_PUBLISH_ENV: ${{ inputs.publish-env }}
|
||||||
|
|||||||
48
shortify.sh
48
shortify.sh
@@ -4,18 +4,54 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
|
|||||||
# On MacOS,
|
# On MacOS,
|
||||||
# bash don't support substitution, so we use 'tr'
|
# bash don't support substitution, so we use 'tr'
|
||||||
NAME=$(echo "$INPUT_NAME" | tr '[:lower:]' '[:upper:]')
|
NAME=$(echo "$INPUT_NAME" | tr '[:lower:]' '[:upper:]')
|
||||||
|
PREFIX=$(echo "$INPUT_PREFIX" | tr '[:lower:]' '[:upper:]')
|
||||||
else
|
else
|
||||||
NAME=${INPUT_NAME^^}
|
NAME=${INPUT_NAME^^}
|
||||||
|
PREFIX=${INPUT_PREFIX^^}
|
||||||
fi
|
fi
|
||||||
REVISION=${INPUT_REVISION:-${!NAME}}
|
REVISION=${INPUT_REVISION:-${!NAME}}
|
||||||
|
|
||||||
if [ -z "$REVISION" ]; then
|
SHORT_LENGTH=""
|
||||||
|
if [ "${INPUT_LENGTH}" != "" ]; then
|
||||||
|
if [ "${INPUT_LENGTH}" -eq "${INPUT_LENGTH}" ] 2>/dev/null; then
|
||||||
|
SHORT_LENGTH="=${INPUT_LENGTH}"
|
||||||
|
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
|
||||||
|
echo "::error ::Invalid length: ${INPUT_LENGTH}, should be a number"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "::warning ::Invalid length: ${INPUT_LENGTH}, the default length will be used."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${REVISION}" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(git cat-file -e "$REVISION")" == "" ]; then
|
SHORT_PUBLICATION=false
|
||||||
{
|
if [ "$(git cat-file -e "${REVISION}" 2>&1)" == "" ]; then
|
||||||
echo "${NAME}=${REVISION}"
|
SHORT_VALUE=$(git rev-parse --short"${SHORT_LENGTH}" "${REVISION}")
|
||||||
echo "${NAME}_SHORT=$(git rev-parse --short "$REVISION")"
|
SHORT_PUBLICATION="true"
|
||||||
} >>"$GITHUB_ENV"
|
elif [ "${INPUT_SHORT_ON_ERROR}" == "true" ]; then
|
||||||
|
if [ -n "${INPUT_LENGTH}" ]; then
|
||||||
|
SHORT_VALUE=$(cut -c1-"${INPUT_LENGTH}" <<<"${REVISION}")
|
||||||
|
SHORT_PUBLICATION="true"
|
||||||
|
else
|
||||||
|
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
|
||||||
|
echo "revision=${REVISION}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "short=${SHORT_VALUE}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
if [ "${INPUT_PUBLISH_ENV}" == "true" ]; then
|
||||||
|
{
|
||||||
|
echo "${PREFIX}${NAME}=${REVISION}"
|
||||||
|
echo "${PREFIX}${NAME}_SHORT=${SHORT_VALUE}"
|
||||||
|
} >>"$GITHUB_ENV"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user