From 36eb8c530990ceac5ddf3c0bc32d02c677ae9706 Mon Sep 17 00:00:00 2001 From: Benjamin Levesque <14175665+benjlevesque@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:36:59 +0100 Subject: [PATCH] Enable customization of env variable name --- .github/workflows/test.yml | 17 +++++++++++++++++ README.md | 15 +++++++++------ action.yml | 6 +++++- dist/index.js | 2 +- src/main.ts | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f31c95..d2e9d46 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} \ No newline at end of file diff --git a/README.md b/README.md index 8115b24..2e16d5e 100644 --- a/README.md +++ b/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 | diff --git a/action.yml b/action.yml index 91584df..0e51b14 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index 0e0ff0a..5970ce4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); diff --git a/src/main.ts b/src/main.ts index b88eb98..cdb1870 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,7 +12,7 @@ async function run(): Promise { 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) }