β οΈ The name of the action may be confusing, and it is not related to the ordinary meaning of theenvironment variables
, as we know on the OS level (after all, it can set environment variables anyway), but to variables on the GitHub Deployment Environments.
One way to handle deployments is to use Deployment Environments. However, there may be cases where Deployment Environment variables need to be used before the deployment process.
With this GitHub Action, you can access Deployment Environment variables from GitHub workflow not associated with any deployment. For example, this allows you to delay approval until after the planning stage but before applying it or any other situations where you must utilize Deployment Environment variables without proceeding with Environment deployment.
The action will fetch all variables from the Deployment Environment and set them in the workflow as action output and/or as environment variables on the OS level.
You cannot use the built-in GitHub Token (well-known as ${{ github.token }}
or ${{ secrets.GITHUB_TOKEN }}
) with this action because it does not support Deployment Environments read access.
You have to create a fine-grained Personal Access Token on the Developer Settings page, or for more scalable organization-wide scenarios, you can consider GitHub Apps. It has a higher rate limit than PATs but requires additional configuration steps on your GitHub workflow. Please follow the GitHub App Setup example.
No matter which way you choose the required scope for this GitHub Action is environments:read
.
The minimum required inputs are github-token
with your GitHub Token and environment
with the deployment environment name that you want to use to fetch variables.
The below example assumes the Deployment Environment name is staging
and contains two variables:
MY_VAR1
with valueLorem ipsum
FOOBAR
with valueAbc123
- name: Staging Environment Variables
id: staging-env-vars
uses: raven-actions/environment-variables@v2
with:
github-token: ${{ secrets.MY_GH_TOKEN }}
environment: staging
In the subsequence step, you can use variables in two ways.
-
as
action outputs
, where the output name is the variable key.- run: | echo "${{ steps.staging-env-vars.outputs.MY_VAR1 }}" echo "${{ steps.staging-env-vars.outputs.FOOBAR }}"
-
as
environment variables
, where the env name is the variable key.- run: | echo "${{ env.MY_VAR1 }}" echo "${FOOBAR}"
Whatever method you choose the output will be:
Lorem ipsum
Abc123
π‘ In some scenarios, you may use variables from multiple Deployment Environments in the same Job where the variable key is the same. To avoid override, you can prefix environment variables with the
env-prefix
input. See the π₯ Inputs section for more details.
Name | Type | Required | Default | Description |
---|---|---|---|---|
github-token |
string |
true |
not set | GitHub token to use for API authentication with environment:read . scope. |
environment |
string |
true |
not set | Deployment Environment name. |
output-to |
string |
false |
all |
Output type. One of: - action returns variables as action output- env returns variables as environment variables- all action output + envvars. |
env-prefix |
string |
false |
not set | Prefix for environment variables. Environment variables prefix will be upper-cased and striped from any special characters. A double underscore __ is placed between environment prefix and env name (MYPREFIX__VAR ). |
repository |
string |
false |
github.repository |
To fetch variables from Deployment Environment placed in different repository, set full repository name in the owner/repo format. |
dry-run |
boolean |
false |
false |
Whether or not to actually perform operation. Set to true for testing. Will not set outputs/envvars - just log entries. |
- The action does not have any static action outputs. Only dynamic action output based on your variables from Deployment Environment, if
output-to
isall
oraction
. - The action does not have any static environment variables outputs. Only dynamic environment variables output based on your variables from Deployment Environment, if
output-to
isall
orenv
.
Contributions to the project are welcome! Please follow Contributing Guide.
This project is distributed under the terms of the MIT license.