very_good_workflows icon indicating copy to clipboard operation
very_good_workflows copied to clipboard

feat: way to inject secrts to setup step

Open Ahmadajami opened this issue 1 year ago • 4 comments

Description

flutter_package workflow:

way to inject multiple secrets and env to {setup} step so we can make an env file with github secrest

Requirements

setup: env: first: second: secrets: first_one: second:

Additional Context

No response

Ahmadajami avatar Jan 08 '25 13:01 Ahmadajami

@Ahmadajami Not sure this helps or covers what you want to achieve, but this is how I solved a similar sounding issue:

build:
    uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
    with:
      flutter_channel: stable
      min_coverage: 80
      # Define ENV variables using secrets before running build_runner
      setup: |
        APP_URL=${{ secrets.APP_URL }} \
        APP_ANON_KEY=${{ secrets.APP_ANON_KEY }} \
        flutter pub run build_runner build --delete-conflicting-outputs
    secrets: inherit # Ensure secrets are accessible

I use the envied package to manage environment variables. It looks for the .env file specified by path and it also checks for the required variables (like APP_URL and APP_ANON_KEY) in the system environment variables if they aren't found in the file.

stfnfrnk avatar Apr 16 '25 21:04 stfnfrnk

@stfnfrnk im also using envied package i will try your way but where can i make the secrets inherit

Ahmadajami avatar Apr 16 '25 22:04 Ahmadajami

I did define the Actions secrets and variables under /settings/secrets/actions in Github. Then in your main.yml:

build:
    uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
    with:
      flutter_channel: stable
      min_coverage: 80
      # Inject secrets as environment variables during setup
      setup: |
        echo "APP_URL=$APP_URL" > .env
        echo "APP_ANON_KEY=$APP_ANON_KEY" >> .env
        flutter pub run build_runner build --delete-conflicting-outputs
    secrets: inherit # This makes the secrets from your repo available to this job

secrets: inherit allows all secrets from your repository (here APP_URL and APP_ANON_KEY) to be available inside the workflow. Workflow syntax for GitHub Actions

stfnfrnk avatar Apr 17 '25 05:04 stfnfrnk

@stfnfrnk How would you handle this setup if you are also using GitHub Environments (dev, stg, prod) with secrets scoped to those environments?

Bartozo avatar Jun 19 '25 21:06 Bartozo