Skip to content

Commit

Permalink
Enable customization of env variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque committed Mar 19, 2023
1 parent 07f50ea commit 36eb8c5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: ./
id: short-sha
with:
Expand All @@ -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 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 36eb8c5

Please sign in to comment.