mirror of
https://github.com/benjlevesque/short-sha.git
synced 2025-12-06 01:37:51 +01:00
Enable customization of env variable name
This commit is contained in:
17
.github/workflows/test.yml
vendored
17
.github/workflows/test.yml
vendored
@@ -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 }}
|
||||
15
README.md
15
README.md
@@ -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,20 +15,21 @@ 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
|
||||
- run: echo $SHA
|
||||
env:
|
||||
env:
|
||||
SHA: ${{ steps.short-sha.outputs.sha }}
|
||||
- run: echo $SHA
|
||||
env:
|
||||
env:
|
||||
SHA: ${{ env.SHA }}
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
| Name | Required | Default | Description |
|
||||
| ------ | -------- | ------- | ---------------------------------------- |
|
||||
| length | `false` | 7 | the expected length of the shortened SHA |
|
||||
| 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 |
|
||||
|
||||
@@ -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
2
dist/index.js
vendored
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user