Set environments at runtime

hey all
in my repository i have 3 branches, main, staging, production
i’m searching for a way to set the environment at runtime to be able to use the proper secrets

i have tried:
1 environment: ${GITHUB_REF##*/}
which get the branch name if i set it to env: key but not for the environment

2 environment:
if: github.ref == ‘refs/heads/main’
name: main

this works but only for the first IF, when i add more it fails

any way to get the environment dynamically or based on branch name?
thanks

see here: How to set environment attribute dynamically in a workflow? - #4 by dradetsky. apparently you need the

environment:
  name: ${{ github.event.inputs.envName }}

type syntax