https://github.com/rezigned/setup-env-action
Github Action for setting up environment variables dynamically
https://github.com/rezigned/setup-env-action
Last synced: about 1 year ago
JSON representation
Github Action for setting up environment variables dynamically
- Host: GitHub
- URL: https://github.com/rezigned/setup-env-action
- Owner: rezigned
- License: mit
- Created: 2023-04-29T16:31:54.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T07:34:19.000Z (about 1 year ago)
- Last Synced: 2025-03-25T08:34:48.339Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://github.com/marketplace/actions/set-up-environment-variables-action
- Size: 283 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Setup Environment Variable (dynamically)
This action sets up environment variables by evaluating the values with shell command first.
## Usage
**Basic**:
```yaml
steps:
- uses: rezigned/setup-env-action@v1
with:
env: |
GIT_SHORT_SHA: $(git rev-parse --short HEAD)
- run: |
echo ${{ env.GIT_SHORT_SHA }}
```
**Using variable name at input-level**:
> [!WARNING]
> Although this works. Github will send a warning message like 'VAR NAME' is not a valid input. This is because Github only allows input names defined in `action.yml`.
```yaml
steps:
- uses: rezigned/setup-env-action@v1
with:
GIT_SHORT_SHA: $(git rev-parse --short HEAD)
```
**Specifying shell**:
The `sh` shell is used by default. User can speicfy other shell by using `shell` input. For example:
```yaml
- uses: rezigned/setup-env-action@v1
with:
env: |
GIT_SHORT_SHA: $(git rev-parse --short HEAD)
shell: bash
```
## Why?
Github workflow currently [doesn't](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#env) allow user to set `env` value by referring to existing `env`.
> *Variables in the env `map` cannot be defined in terms of other variables in the map.*
For example, this won't work:
```yml
...
env:
DOMAIN: https://example.com
steps:
- name: Check status
env:
API_URL: ${{ env.DOMAIN }}/api
```
The current solution recommended by Github is to add extra step and add variable into `GITHUB_ENV` file.
For example:
```yml
steps:
- name: Set up envs
run: |
echo "API_URL=$DOMAIN/api" >> $GITHUB_ENV
- name: Check status
run: |
echo $API_URL // https://example.com/api
```