I’m trying to refactor a workflow that manages different environment deployments to use the GitHub environments feature, but I got stuck on how to use both global and environment secrets.
For a bit of context, my aim is to use the same workflow, but depending on the branch name (that matches a environment), get values from that environment.
All the secrets and vars have the same name for each environment, just different values, and then I have repo level secrets and variables, that are common for all envs (e.g. AWS keys).
Let’s say I have a workflow that its triggered for each merge to dev, staging or main branches, then I have some steps:
- name: Configure AWS credentials
if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
// Those I'd like to get from global
aws-access-key-id: ${{ secrets.PIPELINE_USER_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIPELINE_USER_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Build, tag, and push Client image to Amazon ECR
if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }}
uses: docker/build-push-action@v5
with:
build-args: |
// Those I'd like to get from environments (Ideally set dynamically)
NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }}
NEXTAUTH_URL=${{ vars.NEXTAUTH_URL }}
NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}
Then I would use the same workflow file, using the branch name to reference the environment, so that I can get the right values
Does anyone have any working example?