Feature request: set variable name
Closed this issue · 7 comments
Hi,
I would like to use the variable $SHORT_SHA (rather than SHA), similar to Google Cloud Build:
$SHORT_SHA : the first seven characters of COMMIT_SHA
When defining this action:
id: short-sha
with:
length: 7
variable_name: SHORT_SHA
Hello @sdarwin,
you can already do this SHA
isn't set by this action, but in the workflow:
name: 'build-test'
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: benjlevesque/short-sha@v2.1
id: short-sha
with:
length: 6
- run: echo $SHORT_SHA
env:
SHORT_SHA: ${{ steps.short-sha.outputs.sha }}
- run: echo $WHATEVER_SHA
env:
WHATEVER_SHA: ${{ env.SHORT_SHA}}
Hi @benjlevesque,
- That example doesn't work as-is, if you copy and paste it, because "env.SHORT_SHA" isn't defined.
Run echo $WHATEVER_SHA
echo $WHATEVER_SHA
shell: /usr/bin/bash -e {0}
env:
DOCKER_BUILDKIT: 1
DOCKER_IMAGE: us-central1-docker.pkg.dev/boostorg-project1/website/website
DOCKER_REGISTRY: us-central1-docker.pkg.dev
pythonLocation: /opt/hostedtoolcache/Python/3.9.16/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.16/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
Python[2](https://github.com/sdarwin/boost.org/actions/runs/4438378024/jobs/7789371452#step:8:2)_ROOT_DIR: /opt/hostedtoolcache/Python/[3](https://github.com/sdarwin/boost.org/actions/runs/4438378024/jobs/7789371452#step:8:3).9.16/x6[4](https://github.com/sdarwin/boost.org/actions/runs/4438378024/jobs/7789371452#step:8:4)
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.1[6](https://github.com/sdarwin/boost.org/actions/runs/4438378024/jobs/7789371452#step:8:6)/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.[9](https://github.com/sdarwin/boost.org/actions/runs/4438378024/jobs/7789371452#step:8:9).16/x64/lib
SHA: ef6c41
WHATEVER_SHA:
- "env.SHORT_SHA" is precisely what I was asking about. If this github action created it, then you could use that in other steps by referring to
${{ env.SHORT_SHA }}
.
Currently, with this plugin, you can refer to ${{ env.SHA }}
directly, without needed to redefine it or add an env block such as:
env:
SHA: ${{ steps.short-sha.outputs.sha }}
In your code, you can just call ${{ env.SHA }}
. What I am suggesting is to be able to use ${{ env.SHORT_SHA }}
instead, then use it in other steps without an env block. I would prefer to not add an env block to every subsequent step.
my bad, it should have been
- run: echo $WHATEVER_SHA
env:
WHATEVER_SHA: ${{ steps.short-sha.outputs.sha }}
I understand what you're saying... I'm not 100% sure if this is possible, do you have links to docs or example of other github actions that behave like this?
In the file main.ts, it seems to be exporting the variable SHA as an environment variable:
core.exportVariable('SHA', shortSha)
So, instead of using the hardcoded string 'SHA' it could be a variable ${variable_name} which is input from the action.
Something else, when reading the README file there is an example but not an explanation. It's interesting to see both in documentation. Maybe prior to the example it could say:
"This action exposes two ways to access the generated short sha value. Either ${{ steps.short-sha.outputs.sha }}
or ${{ env.SHA }}
."
Of course 🤦♂️ my bad, thanks
I've pushed a new version including your request. Hope it helps...
Awesome! Thanks.