Skip to content

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

License

Notifications You must be signed in to change notification settings

gbh-tech/set-environment-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

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 }}"

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks