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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./ - uses: ./
id: short-sha id: short-sha
with: with:
@@ -28,3 +29,19 @@ jobs:
[ ${#SHA} -eq 6 ] && exit 0 || exit 1; [ ${#SHA} -eq 6 ] && exit 0 || exit 1;
env: env:
SHA: ${{ steps.short-sha.outputs.sha }} 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 ## 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 ```yaml
name: 'build-test' name: 'build-test'
on: [push] on: [push]
@@ -13,7 +15,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: benjlevesque/short-sha@v2.1 - uses: benjlevesque/short-sha@v2.2
id: short-sha id: short-sha
with: with:
length: 6 length: 6
@@ -27,6 +29,7 @@ jobs:
## Options ## Options
| Name | Required | Default | Description | | Name | Required | Default | Description |
| ------ | -------- | ------- | ---------------------------------------- | | ------------- | -------- | ------- | ---------------------------------------- |
| length | `false` | 7 | the expected length of the shortened SHA | | 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 icon: git-pull-request
inputs: inputs:
length: length:
description: 'length of the sha1' description: 'length of the shortened sha1'
default: '7' default: '7'
required: false required: false
variable_name:
description: "name of the exported env variable"
default: "SHA"
required: false
outputs: outputs:
sha: sha:
description: 'shortened 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); const shortSha = (0, shorten_1.shorten)(sha, length);
core.debug(`Output: ${shortSha}`); core.debug(`Output: ${shortSha}`);
core.setOutput('sha', shortSha); core.setOutput('sha', shortSha);
core.exportVariable('SHA', shortSha); core.exportVariable(core.getInput('variable_name'), shortSha);
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);

View File

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