Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gbh-tech/set-environment-action

Outputs an environment variable by the key 'ENVIRONMENT' based on the triggering GitHub event. and git ref name.
https://github.com/gbh-tech/set-environment-action

action environment github set utility

Last synced: about 3 hours ago
JSON representation

Outputs an environment variable by the key 'ENVIRONMENT' based on the triggering GitHub event. and git ref name.

Awesome Lists containing this project

README

        

# Set Environment Action

## Content

- [Overview](#overview)
- [Environments](#environments)
- [Environment mapping](#environment-mapping)
- [Usage](#usage)
- [Examples](#examples)

## Overview

This GitHub Action facilitates setting the environment name based on the
triggering workflow and git ref.

> ⚠️ This action is tailored for our specific needs and development workflow,
> at this moment, you cannot change the triggering events or the environment
> tag. Only use if you can adapt it on your workflow!

The action exposes the environment name value in two different contexts:

- Outputs
- [env context]

## Environments

This action can output the following environment names:

- `stage`
- `uat`
- `production`

## Environment mapping

The environment name mapping is as follows:

- Push event on a branch with name `main` -> Outputs environment **stage**.
- Tag push matching `v[0-9].[0-9].[0-9]-uat.[0-9]` -> Outputs **uat**.
- Tag matching `v[0-9].[0-9].[0-9]` -> Outputs **production**.

The Action uses `github.ref_name` to determine the branch or tag name.

## Usage

See [action.yml](action.yml) for more info about the action.

```yaml
- uses: gbh-tech/[email protected]
id: env
```

### Examples

```yaml
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gbh-tech/[email protected]
id: env

# Using outputs
- name: Show the selected environment name using output
env:
ENVIRONMENT: ${{ steps.env.outputs.environment }}
run: echo "Environment is ${ENVIRONMENT}"

# Using env. context
- name: Show the selected environment name using env context
run: echo "Environment is ${{ env.ENVIRONMENT }}"
```

[env context]: https://docs.github.com/en/actions/learn-github-actions/contexts#example-contents-of-the-env-context