1
0
mirror of https://github.com/benjlevesque/short-sha.git synced 2025-12-06 09:47:49 +01:00

Enable customization of env variable name

This commit is contained in:
Benjamin Levesque
2023-03-19 11:36:59 +01:00
parent 07f50eae02
commit 36eb8c5309
5 changed files with 33 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
id: short-sha
with:
@@ -28,3 +29,19 @@ jobs:
[ ${#SHA} -eq 6 ] && exit 0 || exit 1;
env:
SHA: ${{ steps.short-sha.outputs.sha }}
- name: validate env
run: |
echo $SHA;
[ ${#SHA} -eq 6 ] && exit 0 || exit 1;
env:
SHA: ${{ env.SHA }}
- uses: ./
with:
variable_name: "SHORT_SHA"
- name: validate custom env
run: |
echo $SHORT_SHA;
[ ${#SHA} -eq 6 ] && exit 0 || exit 1;
env:
SHORT_SHA: ${{ env.SHORT_SHA }}

View File

@@ -4,6 +4,8 @@
## Usage
You can access the shortened value with either `${{ steps.short-sha.outputs.sha }}` (`short-sha` being the name of the action step) or `${{ env.SHA }}`.
```yaml
name: 'build-test'
on: [push]
@@ -13,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: benjlevesque/short-sha@v2.1
- uses: benjlevesque/short-sha@v2.2
id: short-sha
with:
length: 6
@@ -28,5 +30,6 @@ jobs:
## Options
| Name | Required | Default | Description |
| ------ | -------- | ------- | ---------------------------------------- |
| ------------- | -------- | ------- | ---------------------------------------- |
| length | `false` | 7 | the expected length of the shortened SHA |
| variable_name | `false` | `SHA` | the name of the exported env variable |

View File

@@ -6,9 +6,13 @@ branding:
icon: git-pull-request
inputs:
length:
description: 'length of the sha1'
description: 'length of the shortened sha1'
default: '7'
required: false
variable_name:
description: "name of the exported env variable"
default: "SHA"
required: false
outputs:
sha:
description: 'shortened SHA'

2
dist/index.js vendored
View File

@@ -52,7 +52,7 @@ function run() {
const shortSha = (0, shorten_1.shorten)(sha, length);
core.debug(`Output: ${shortSha}`);
core.setOutput('sha', shortSha);
core.exportVariable('SHA', shortSha);
core.exportVariable(core.getInput('variable_name'), shortSha);
}
catch (error) {
core.setFailed(error.message);

View File

@@ -12,7 +12,7 @@ async function run(): Promise<void> {
core.debug(`Output: ${shortSha}`)
core.setOutput('sha', shortSha)
core.exportVariable('SHA', shortSha)
core.exportVariable(core.getInput('variable_name'), shortSha)
} catch (error) {
core.setFailed(error.message)
}