Skip to content
info

GitHub Action

Set ENVIRONMENT env var

v0.1.2 Latest version

Set ENVIRONMENT env var

info

Set ENVIRONMENT env var

Set ENVIRONMENT and other variables

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Set ENVIRONMENT env var

uses: gbh-tech/set-environment-action@v0.1.2

Learn more about this action in gbh-tech/set-environment-action

Choose a version

Set Environment Action

Content

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:

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 for more info about the action.

- uses: gbh-tech/set-environment-action@v0.1.1
  id: env

Examples

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: gbh-tech/set-environment-action@v0.1.1
        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 }}"