### Full Combined Example with Advanced Options Source: https://context7.com/0ndt/envfile/llms.txt Demonstrates a comprehensive configuration including selective inclusion/exclusion of secrets, prefixing, case conversion (without converting the prefix), and writing to a custom file. This example showcases fine-grained control over secret management. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} include: DB_PASSWORD, API_KEY, SERVICE_* exclude: SERVICE_INTERNAL prefix: PROD_ convert: snake convert_prefix: false file: .env.production override: false - run: | echo "$PROD_db_password" # DB_PASSWORD → PROD_db_password echo "$PROD_api_key" # API_KEY → PROD_api_key cat .env.production # .env.production: # PROD_db_password= # PROD_api_key= # PROD_service_worker= (SERVICE_WORKER matched, SERVICE_INTERNAL excluded) ``` -------------------------------- ### After: Using secrets-to-dotenv Action Source: https://github.com/0ndt/envfile/blob/main/README.md Shows how to use the secrets-to-dotenv action to achieve the same result as the manual method, simplifying the workflow. ```yaml - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} - run: echo "Value of MY_SECRET1: $MY_SECRET1" ``` -------------------------------- ### Before: Manual Secret Export Source: https://github.com/0ndt/envfile/blob/main/README.md Demonstrates the manual process of exporting secrets to environment variables and a .env file before using this action. ```yaml - run: echo "Value of MY_SECRET1: $MY_SECRET1" env: MY_SECRET1: ${{ secrets.MY_SECRET1 }} MY_SECRET2: ${{ secrets.MY_SECRET2 }} MY_SECRET3: ${{ secrets.MY_SECRET3 }} - run: | echo "MY_SECRET1=${{ secrets.MY_SECRET1 }}" >> .env echo "MY_SECRET2=${{ secrets.MY_SECRET2 }}" >> .env echo "MY_SECRET3=${{ secrets.MY_SECRET3 }}" >> .env ... ``` -------------------------------- ### Basic Usage of secrets-to-dotenv Source: https://github.com/0ndt/envfile/blob/main/README.md The most basic configuration for the action, exporting all secrets as environment variables and to a .env file. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} - run: echo "Value of MY_SECRET: $MY_SECRET" ``` -------------------------------- ### Custom .env File Name Source: https://github.com/0ndt/envfile/blob/main/README.md Configure the action to write secrets to a custom file name instead of the default '.env'. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} file: .prod.env ``` -------------------------------- ### Export All Secrets to .env and Environment Variables Source: https://context7.com/0ndt/envfile/llms.txt Exports all repository secrets as environment variables and writes them to the default .env file. Ensure secrets are passed as a JSON blob using `toJSON(secrets)`. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} - run: echo "Value of MY_SECRET: $MY_SECRET" ``` -------------------------------- ### Disable File Output, Export Only Environment Variables Source: https://context7.com/0ndt/envfile/llms.txt Pass an empty string to the `file` input to skip writing any file. Secrets will only be available as environment variables. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} file: "" - run: echo "$MY_SECRET" ``` -------------------------------- ### Control Prefix Conversion with `convert_prefix` Source: https://context7.com/0ndt/envfile/llms.txt The `convert_prefix` option (defaults to `true`) determines if the specified `prefix` string is also converted according to the `convert` setting. Set to `false` to preserve the original prefix casing. ```yaml # Prefix IS converted (convert_prefix: true) steps: - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} prefix: PREFIX_ convert: snake convert_prefix: true - run: echo "$prefix_my_secret_1" # MY_SECRET_1 → PREFIX_MY_SECRET_1 → prefix_my_secret_1 ``` ```yaml # Prefix is NOT converted (convert_prefix: false) steps: - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} prefix: PREFIX_ convert: snake convert_prefix: false - run: echo "$PREFIX_my_secret_1" # MY_SECRET_1 → PREFIX_MY_SECRET_1 → PREFIX_my_secret_1 (prefix preserved) ``` -------------------------------- ### Add a Prefix to All Exported Secret Keys Source: https://context7.com/0ndt/envfile/llms.txt Prepends a specified string to every exported secret name using the `prefix` input. This helps in namespacing secrets. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} prefix: APP_ - run: echo "$APP_MY_SECRET" ``` -------------------------------- ### Write Secrets to a Custom File Path Source: https://context7.com/0ndt/envfile/llms.txt Writes all secrets to a specified file path instead of the default .env. Set the `file` input to your desired path. An empty string disables file output. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} file: .prod.env - run: cat .prod.env ``` -------------------------------- ### Write File Only, No Environment Variables Export Source: https://context7.com/0ndt/envfile/llms.txt Use the `no_env: true` input to write secrets to a file without exporting them into the runner's environment. This is useful when secrets should only be persisted to a file. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} no_env: true - run: cat .env ``` -------------------------------- ### Convert Secret Key Case Source: https://context7.com/0ndt/envfile/llms.txt Converts all exported secret names to a specified case format using the `convert` input. Supported values include `lower`, `upper`, `camel`, `constant`, `pascal`, and `snake`. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} convert: lower ``` -------------------------------- ### Include Specific Secrets Source: https://github.com/0ndt/envfile/blob/main/README.md Specify secrets to be included. Only these secrets will be exported or written to the file. Supports comma-separated values and regex patterns. Non-existent secrets are ignored. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} include: MY_SECRET, MY_OTHER_SECRETS* - run: echo "Value of MY_SECRET: $MY_SECRET" ``` -------------------------------- ### Control Secret Override Behavior Source: https://github.com/0ndt/envfile/blob/main/README.md Configure whether the action should override existing environment variables. Defaults to true. ```yaml env: MY_SECRET: DONT_OVERRIDE steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} override: false - run: echo "Value of MY_SECRET: $MY_SECRET" Value of MY_SECRET: DONT_OVERRIDE ``` -------------------------------- ### Convert Secrets to Snake Case Source: https://context7.com/0ndt/envfile/llms.txt Utilize `convert: snake` to convert secret keys to snake_case. This is a common convention for environment variables in many applications and frameworks. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} convert: snake - run: echo "$my_secret_1" # MY_SECRET_1 → my_secret_1 ``` -------------------------------- ### Control Prefix Inclusion During Conversion Source: https://github.com/0ndt/envfile/blob/main/README.md Determines whether the prefix is included when converting secret names. Defaults to true. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} prefix: PREFIX_ convert: lower convert_prefix: false - run: env # E.g. secret with MY_SECRET would become PREFIX_my_secret ``` -------------------------------- ### Convert Secrets to Lowercase Source: https://context7.com/0ndt/envfile/llms.txt Use the `convert: lower` option to transform all secret keys to lowercase. This is useful when your application expects lowercase environment variables. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} convert: lower - run: echo "$my_secret_1" # MY_SECRET_1 → my_secret_1 ``` -------------------------------- ### Convert Secret Names Source: https://github.com/0ndt/envfile/blob/main/README.md Converts all exported secret names to a specified case format (e.g., lower, upper, camel). Available formats are listed in the change-case library. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} convert: lower - run: echo "Value of my_secret: $my_secret" ``` -------------------------------- ### Add Prefix to Secrets Source: https://github.com/0ndt/envfile/blob/main/README.md Adds a specified prefix to all exported secret names. Useful for namespacing secrets. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} prefix: PREFIXED_ - run: echo "Value of PREFIXED_MY_SECRET: $PREFIXED_MY_SECRET" ``` -------------------------------- ### Disable File Output Source: https://github.com/0ndt/envfile/blob/main/README.md Use this option to prevent the action from writing secrets to a file, only exporting them as environment variables. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} file: ``` -------------------------------- ### Convert Secrets to CamelCase Source: https://context7.com/0ndt/envfile/llms.txt Employ `convert: camel` to change secret keys to camelCase. This is beneficial for applications or languages that commonly use camelCase for variable naming. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} convert: camel - run: echo "$mySecret_1" # MY_SECRET_1 → mySecret_1 ``` -------------------------------- ### Disable Environment Variable Export Source: https://github.com/0ndt/envfile/blob/main/README.md Use this option to prevent the action from exporting secrets as environment variables, only writing them to the file. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} no_env: true ``` -------------------------------- ### Export Only Specific Secrets Using Include Filter Source: https://context7.com/0ndt/envfile/llms.txt Restricts export to only secrets whose names match the provided list or regex pattern. Use the `include` input for this purpose. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} include: MY_SECRET, DEPLOY_* - run: | echo "$MY_SECRET" # exported echo "$OTHER_SECRET" # NOT exported (not matched) ``` -------------------------------- ### Control Overwriting with `override: false` Source: https://context7.com/0ndt/envfile/llms.txt Set `override: false` to prevent the action from overwriting existing environment variables. This ensures that pre-defined variables in your workflow (e.g., in the `env` block) are preserved. ```yaml env: MY_SECRET: DONT_OVERRIDE steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} override: false - run: echo "$MY_SECRET" # Output: DONT_OVERRIDE # (value from the workflow env block is preserved, not overwritten by the secret) ``` -------------------------------- ### Exclude Specific Secrets Source: https://github.com/0ndt/envfile/blob/main/README.md Specify secrets to be excluded from being exported or written to the file. Supports comma-separated values and regex patterns. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} exclude: MY_SECRET, MY_OTHER_SECRETS* # MY_SECRET is not exported ``` -------------------------------- ### Exclude Specific Secrets Using Exclude Filter Source: https://context7.com/0ndt/envfile/llms.txt Excludes matched secrets from export using a comma-separated list or regex pattern provided to the `exclude` input. The `github_token` is always excluded automatically. ```yaml steps: - uses: actions/checkout@v3 - uses: 0ndt/envfile@v2 with: secrets: ${{ toJSON(secrets) }} exclude: MY_SECRET_1, INTERNAL_* - run: echo "$MY_SECRET_2" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.