Environment name and DRY principles

Hey guys, :slight_smile:

I am using Github actions for the first time and I have one job named test. I want to have access to either the “dev” or “prod” string in my Github action, depending on the branch I am on.

I’ve created two environments (“dev” and “prod”) within my repository.

I’ve noticed that there doesn’t seem to be a way to access the name of those environments in github actions. From reading the docs, no github environment variables seems to exist for that purpose (note that Gitlab uses CI_ENVIRONMENT_NAME). The workflow syntax doesn’t seem to allow that either : Context and expression syntax for GitHub Actions - GitHub Docs.

Therefore, Ive created secrets within those environments: ENVIRONMENT_NAME which contains the value “dev” and “prod” depending on which environment you are on.

In my github actions, I want to have just one job, where I can identify if I am either using “dev” or “prod”. Ideally I want to keep the code DRY so I don’t want to have 2 jobs.

Is there a way for me to recuperate that value (“dev” or “prod”) without having to specify an environment at the job level. (Workflow syntax for GitHub Actions - GitHub Docs)

Ideally I just want to have something like :

jobs : 
    runs-on: ubuntu-latest
      - uses: myaction
           parameters: -myEnvironment ${{ secrets.ENVIRONMENT_NAME }}

But it seems I cannot do that, as according to the docs, I have to specify the environment within job.<jobId>.environment to access the secret on a given environment. + There doesn’t seem to be a way to recuperate environment name.

I think jobs.<job_id>.strategy.matrix is what you are looking for: