Git Product home page Git Product logo

create-envfile's People

Contributors

amirkx avatar angelonfira avatar dependabot[bot] avatar devcrossnet avatar dleo9307 avatar flaiers avatar heyman333 avatar iamarpitpatidar avatar konstantinklepikov avatar sobolevn avatar sumit4613 avatar taylorgorman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

create-envfile's Issues

$GITHUB_WORKSPACE is not always the hard coded path

I'm trying to use the environment file that I create in a subsequent step and it's failing because the python script is hard coded to put the file in path = "/github/workspace"

I'd like to create a change where instead of looking at that, it gets the GITHUB_WORKSPACE environment variable and sets it to that instead.

The documentation isn't very clear and I'm having trouble trying to figure it out.

I currently have this in my workflow:

name: Build and Deploy

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  
jobs:
  build-and-deploy:
    name: Build and Deploy
    runs-on: [ubuntu-latest]
    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2
    - name: Install dependencies
      run: npm install
    # - name: Run tests
    #   run: npm test
    - name: Make envfile
      uses: SpicyPizza/create-envfile@v1
      with:
        envkey_DEBUG: false
        envkey_FIRESTORE_API_TOKEN: ${{ FIRESTORE_API_TOKEN }}
        file_name: .env
    - name: Build
      run: npm run react-build
    - name: Deploy to firebase
      uses: w9jds/firebase-action@master
      with:
        args: deploy
      env: 
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Am I doing something wrong?

Provide an option to save all secrets into an .env file, instead of having to list them all as input parameters

Through Github API, it is possible to retrieve the name of all secrets at once. It is also possible to retrieve the value of a secret. That makes the workflow definition much easier, as it would eliminate the need to specify any ENVKEYs for secrets; the action could just dump all secrets instead.

Github API authentication is also painless, as every Github workflow already provides an authentication token that can be used.

How do I create the env file in a server i have provided ssh credentials for?

This is my workflow

# This is a basic workflow to help you get started with Actions

name: digitalocean-pull-and-setup-env

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the $default-branch branch
  # push:
  #   branches: [ $default-branch ]
  # pull_request:
  #   branches: [ $default-branch ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # SSH into digitalocean droplet
      - name: executing remote ssh commands using password
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          key: ${{ secrets.SSH_KEY }}


      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.

      # create the env file
      - name: Make envfile
        uses: SpicyPizza/create-envfile@v1
        with:
          DEBUG: False
          DEVELOPMENT_MODE: False
          DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET }}
          directory: /home/django/all_django_projects
          file_name: .django

i have already setup the ssh-action but it looks like it run the last step separately from the ssh action

Unable to create .env file

I got error related to file not created

        Creating file: /github/workspace/home/runner/work/ePricing/ePricing/.env
        File "/opt/action/create-envfile.py", line 47, in <module>
         with open(full_path, "w") as text_file:
         FileNotFoundError: [Errno 2] No such file or directory: '/github/workspace/home/runner/work/ePricing/ePricing/.env'

Here's the workflow

          build:
             runs-on: ubuntu-latest
             steps:
                  - uses: actions/checkout@v2
                  - uses: SpicyPizza/create-envfile@main
                    with:
                         envkey_DEBUG: false
                         envkey_DB_SERVER: ${{ secrets.DB_SERVER }}
                         directory: ePricing/
                         file_name: .env
                         fail_on_empty: false

Any ideas?

directory not working

I can't understand why the file I specified doesn't create a file, what am I doing wrong?

image

Sorted keys breaks variable dependence in the envfile

I've observed that the keys on the generated env file are sorted.
However it breaks some variables that uses other variables in the env file.
For instance:
suppose a variable name DOMAIN_NAME=example.com
envkey_DOMAIN_NAME: 'example.com'
followed by another one such as BAR_HOST_FQDN=bar.${DOMAIN_NAME}.
envkey_BAR_HOST_FQDN: "bar.${DOMAIN_NAME}"

the original env file is created such as
DOMAIN_NAME=example.com
BAR_HOST_FQDN=bar.${DOMAIN_NAME}

But the resulting translated env file is:
BAR_HOST_FQDN=bar.${DOMAIN_NAME}
DOMAIN_NAME=example.com

However, DOMAIN_NAME is not defined by the time BAR_HOST_FQDN is evaluated resulting in:
BAR_HOST_FQDN: bar
DOMAIN_NAME: example.com

which is different from the produced in the original env file:
BAR_HOST_FQDN: bar.example.com
DOMAIN_NAME: example.com

This doesn't seem to be much but it broke several large env files I have.

Unexpected input(s)

image
I'm getting this error with the example provided. Any ideas how to solve it? Am I doing something wrong?

Why directory not work?

On this image you can see, file created in . directory

image

I write in my action script media/deployment

image

Maybe I'm doing something wrong

Unrecognized named-value: 'secrets'. Located at position 1 within expression:

Hi, I tried this as action but it doesnt work

action.yml

     name: Create envfile

     on: [ push ]

      jobs:

           create-envfile:

               runs-on: ubuntu-latest

              steps:
                 - name: Make envfile
                   uses: SpicyPizza/[email protected]
                   with:
                      envkey_DEBUG: false
                      envkey_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
                      directory: thedirectory/
                      file_name: .env
                      fail_on_empty: false

workflow.yml

       name: Build and deploy Python app

       on:
              push:
                  branches:
                      - main
              workflow_dispatch:

        jobs:

               build:
                  runs-on: ubuntu-latest

                steps:
                     - name: Checkout
                       uses: actions/checkout@v2
                     - name: Get Environment Variables
                           uses: ./.github/actions/create_envfile // it fails here

Error

              Error: /home/runner/work/thedirectory/thedirectory/./.github/actions/create_envfile/action.yml (Line: 16, Col: 27):
              Error: /home/runner/work/thedirectory/thedirectory/./.github/actions/create_envfile/action.yml (Line: 16, Col: 27): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.CLIENT_SECRET

Any ideas?

key `directory` is not working

As per doc, this key should set the directory in which you want to create env file. However, it is creating env file at $GITHUB_WORKSPACE even after specifying directory or even full path.

Fail if secret is not defined

I would like the workflow step to fail if the secret is not defined. But currently, it is not the case.

    - name: Make envfile for testing environment
      uses: SpicyPizza/create-envfile@v1
      with:
        envkey_STRIPE_SECRET_KEY: ${{ secrets.SECRET_VARIABLE }}

        file_name: .env

This still passes even if secrets.SECRET_VARIABLE is not defined

Docker not found Error

The Error

Build container for action use: '/home/thamjith/actions-runner/nextjs-app/_actions/SpicyPizza/create-envfile/v1/Dockerfile'.
  Error: File not found: 'docker'

The yml file I'm using

name: Node.js CI

on:
  push:
    branches: [ main ]
  workflow_dispatch:

jobs:
  build:

    runs-on: self-hosted

    strategy:
      matrix:
        node-version: [15.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
    - name: Make envfile
      uses: SpicyPizza/create-envfile@v1
      with:
        envkey_NEXT_PUBLIC_GA_ID: ${{ secrets.NEXT_PUBLIC_GA_ID }}
        directory: './'
        file_name: '.env'
    - run: npm i
    - run: npm run build --if-present
    - run: npm run export

env file not being created / GITHUB_WORKSPACE not set

name: Create envfile

on: [ push ]

jobs:
  create-envfile:
    runs-on: ubuntu-latest
    steps:
    - name: Make envfile
      uses: SpicyPizza/[email protected]
      with:
        envkey_SOMETHING: something

I expected this to create the env file within my project directory e.g. /home/runner/work/application-name/application-name/.env

But I get the following:
Creating file: /github/workspace/.env

Only thing I can guess is GITHUB_WORKSPACE isn't set and it's defaulting to this path?
path = str(os.getenv("GITHUB_WORKSPACE", "/github/workspace"))

How to escape multiline values in .env file

First of all, thanks a million for this action, it's super useful.

I was wondering how to escape multiline env vars. let's say I have a cert that I want to pass to my .env file from a github secret. This works locally because I can wrap the cert in quotes in my local .env file. How can I accomplish the same thing with this action? I don't think it does this by default, because right now I'm getting the following error when I try to run docker-compose

Run docker compose -f docker-compose.yml -f production.yml build
unexpected character "+" in variable name near "***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\nPOSTGRES_DB=***\nPOSTGRES_HOST=***\nPOSTGRES_PASSWORD=***\nPOSTGRES_PORT=***\nPOSTGRES_USER=***\nREDIS_HOST=***\nREDIS_PASSWORD=***\nREDIS_PORT=***\n"
Error: Process completed with exit code 1.

Directory option doesn't work: no such file or directory

Hi,
I have a folder called:
"./server"

and i want to add an .env file in it.

using:
directory: server

the build return the next error:

Traceback (most recent call last):
File "/create-envfile.py", line 22, in <module>
with open(os.path.join(path, directory, file_name), "w") as text_file:
FileNotFoundError: [Errno 2] No such file or directory: 'None/server/.env'

Any ideas.

README non-explicit on wether _SECRET_ is optional.

The README is non-explicit on wether SECRET is optional in a variable name.
This seems like a tiny oversight in documentation. I'm not sure how to fix it, because I don't really know wether it is optional, or the implications of not putting _SECRET_.

App can not find the env variables

I am trying to create an .env file as part of Github Action workflow as shown below.

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Install Node.js
        uses: actions/setup-node@v1
        with:
          node-version: "10.x"
      - name: Install npm dependencies
        run: npm install
      - name: Create the .env file
        uses: SpicyPizza/create-envfile@v1
        with:
          envkey_QUERY_LIMIT: 20
          envkey_GOOGLE_RECAPTCHA_SECRET_KEY: ${{ secrets.GOOGLE_RECAPTCHA_SECRET_KEY }}
          file_name: .env
      - name: Run build task
        run: npm run build

The build job is successful but my app can not read the .env after deployment, on the server that is.
Any ideas why?

Release Version

Hey there, I hope you add a feature to get release version to env file

FileNotFoundError

Traceback (most recent call last):
File "/create-envfile.py", line 22, in
with open(os.path.join(path, directory, file_name), "w") as text_file:
FileNotFoundError: [Errno 2] No such file or directory: 'None/***/.env'

Do not mutate key name

Hello, I started to use this action for one use case I had. The issue is that for some keys, for example MyValidEnvVarName it mutates it into MYVALIDENVVARNAME. I am not sure if there is already a flag or something to not mutate the var name, I didn't find it on the documentation. Would be good having this. Currently my solution was updating the code, but for larger code (that do not depend on me only) it is kind of laborious and prone to errors.

Thanks in advance

Constant "error in your yaml syntax"

yml file:

name: Run tests
on:
  pull_request:
    branches: [master, develop]
jobs:
  create-envfile:
    runs-on: ubuntu-18.04
    steps:
    - name: Make envfile
      uses: SpicyPizza/create-envfile@v1
      with:
        CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
        NEXT_PUBLIC_CONTENTFUL_DELIVERY_TOKEN: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_DELIVERY_TOKEN }}
        NEXT_PUBLIC_CONTENTFUL_SPACE_ID: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_SPACE_ID }}
        SITE_SEARCH_API_KEY: ${{ secrets.SITE_SEARCH_API_KEY }}
        NEXT_PUBLIC_CONTENTFUL_ENVIRONMENT: master
        SITE_SEARCH_ENGINE_SLUG: test
        directory: .
        file_name: .env
      - name: Install modules
        run: yarn
      - name: Run tests
        run: yarn jest
      - name: Run Translations & Build
        run: yarn translations && yarn build

Result:

Skärmavbild 2021-05-04 kl  15 34 33

multiple .env files on different directories

I'm creating multiple .env but file doesn't appear.
When creating multiple .env files in different directories, doesn't get directory specified and overrides on all steps.

Only gets a warning
Warning: Unexpected input(s) 'envkey_DOCKER_WEB_PORT', 'envkey_DOCKER_API_PORT', 'directory', valid inputs are ['entryPoint', 'args', 'file_name']

.yml file

runs-on: self-hosted
steps:
- name: Create ROOT .env file
      uses: SpicyPizza/[email protected]
      with:
        envkey_DOCKER_WEB_PORT: ${{ secrets.DOCKER_WEB_PORT }}
        envkey_DOCKER_API_PORT: ${{ secrets.DOCKER_API_PORT }}
        directory: ./
        file_name: .env
- name: Create WEB .env file
      uses: SpicyPizza/[email protected]
      with:
        envkey_REACT_APP_API_URL: ${{ secrets.REACT_APP_API_URL }}
        directory: ./web-react
        file_name: .env

Wrong documentation for v1.1

Hello, I was trying to use version 1.1 of this action, and after a lot of failed attempts to make it work, I noticed that there is a required parameter that the example on the readme does not cover.

Inside the create-envfile.py at line 18 there is:

path = str(os.environ.get("INPUT_GITHUB_WORKSPACE"))

So it expects the user to manually input the GitHub workspace variable. If missing, that line will throw an error because it tries to output the env file into None/directory/.env.

To make it work it should be used like this:

- name: Make envfile
      uses: SpicyPizza/[email protected]
      with:
        envkey_SOME_VARIABLE: "test"
        directory: somedirectory
        github_workspace: ${{ github.workspace }}

Also, in the master branch, the title in the readme should say SpicyPizza/create-envfile@master (to use the master version) and not SpicyPizza/[email protected], which leads to confusion since the usage is a little different.

Hope it helps

Absolute path issue

I am facing issue while creating .env file
image
Traceback (most recent call last):
File "/opt/action/create-envfile.py", line 38, in
raise Exception("Absolute paths are not allowed. Please use a relative path.")
Exception: Absolute paths are not allowed. Please use a relative path. Please help to resolvee the issue @AngelOnFira

Originally posted by @ZinatSayyad in #10 (comment)

Node 20

Hi,

Is there a plan to update to use node 20?
We're starting to see these warnings on CI.
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: SpicyPizza/[email protected]. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

I think this mainly needs an update here: https://github.com/SpicyPizza/create-envfile/blob/main/action.yml#L21
But bumping some CI packages and config like #164 and https://github.com/SpicyPizza/create-envfile/blob/main/.github/workflows/check-dist.yml#L29 can probably help.

Add directory support for env file

Hey @AngelOnFira, thanks for creating this github action it helps alot.

I wanted to create .env files in a specified directory rather than at root but this feature wasn't available, that's why I forked this repository and implemented those changes.
Please checkout this forked version and if you think that it can be merged with your repo, please let me know i'll raise a PR with the required changes.

NOTE: At first, I didn't thought that you'll want to add these changes that's why I have updated README.md. Let me know if you want to add changes, then I will revert back all changes from README.md.

Thanks!

Unexpected inputs error

When running this action I get the following error output:

Unexpected input(s) 'envkey_APP_ENV', 'envkey_APP_KEY', 'envkey_MIX_APP_URL', 'envkey_APP_URL', valid inputs are ['entryPoint', 'args', 'file_name']

My yaml looks like so:

- name: Generate .env file 
  uses: SpicyPizza/create-envfile@v1
  with:
    envkey_APP_ENV: staging
    envkey_APP_KEY: 
    envkey_MIX_APP_URL: https://staging.example.com
    envkey_APP_URL: https://staging.example.com 
- run: sudo chown -R $(id -u):$(id -g) .env

APP_KEY is initially empty and gets filled in later in a later -run command.

Should these be nested under args or something?

Consider using `dump-env`

Hi! Thanks for building this action. It is extremely useful in my workflow.

And since my workflow requires to create .env files inside the build I have created dump-env sometime ago.

Its features:

  1. Creates .env files from env vars
  2. Creates .env files from .env.template
  3. Allows to mix these two

It is written in python and fits this project perfectly. Maybe we can join our forces here? 🙂

Error: docker: command not found

It throws following error when build starts;
Build container for action use: '/root/actions-runner/_work/_actions/SpicyPizza/create-envfile/v1.1/Dockerfile'.
Error: docker: command not found

Workflow file like below;
name: Continuous Deployment

on:
push:
branches:
- develop

jobs:
deployment:
runs-on: self-hosted
steps:
- name: Checkout develop branch
uses: actions/checkout@v2
with:
ref: develop

  - name: Setup Node.js
    uses: actions/setup-node@v1
    with:
      node-version: 12
  - name: Make envfile for vendure server
    uses: SpicyPizza/[email protected]
    with:
      envkey_DEBUG: true
      envkey_DB: "postgres"
      ...

Github actions not adding .env file to source code

I am facing issues with creating .env file. I am deploying my project using Google app engine. The project gets deployed but .env file is not created. Can you please help me with the issue.

This is my main.yaml file-

name: CI

on:
  push:
    branches: [ deploy ]
  pull_request:
    branches: [ deploy ]
  
jobs:
  create-envfile:
    runs-on: ubuntu-18.04
    steps:
      - name: Make envfile
        uses: SpicyPizza/create-envfile@v1
        with:
          envkey_DEBUG: False
          envkey_DATABASE_URL: ${{ secrets.DATABASE_URL }}
          envkey_USER: ${{ secrets.USER }}
          envkey_PASSWORD: ${{ secrets.PASSWORD }}
          envkey_DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
          file_name: .env

  
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Initialize Google Cloud SDK
        uses: zxyle/publish-gae-action@master
        with:
          service_account_email: ${{ secrets.GCP_SA_EMAIL }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          project_id: ${{ secrets.PROJECT_ID }}
          gae_variables: ${{ secrets.GAE_VARIABLES }}

      - name: Publish app to Google App Engine
        run: |
          gcloud auth activate-service-account ${{ secrets.GCP_SA_EMAIL }} --key-file=client-secret.json
          gcloud config set project ${{ secrets.PROJECT_ID }}
          gcloud -q app deploy app.yaml --promote

Please check the output at https://github.com/khannakshat7/Elektra/actions/runs/888591866

Warning: Unexpected input(s) 'envkey_XXX'

Hi
Using the following step:

  - name: Make envfile
      uses: SpicyPizza/[email protected]
      with:
        envkey_FROM_ADDRESS: ${{ secrets.FROM_ADDRESS }}
        envkey_SMTP_HOST: ${{ vars.SMTP_HOST }}
        envkey_SMTP_PORT: ${{ vars.SMTP_PORT }}
        envkey_SMTP_USERNAME: ${{ secrets.SMTP_USERNAME }}
        envkey_SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
        envkey_MAILDROP_INBOX: "test-maildropy-$${{github.job}}"
        envkey_SMTP_SSL_MODE: "SSL"
        directory: tests
        file_name: .env
        fail_on_empty: false
        sort_keys: false

I get this warning:

Warning: Unexpected input(s) 'envkey_FROM_ADDRESS', 'envkey_SMTP_HOST', 'envkey_SMTP_PORT', 'envkey_SMTP_USERNAME', 'envkey_SMTP_PASSWORD', 'envkey_MAILDROP_INBOX', 'envkey_SMTP_SSL_MODE', valid inputs are ['file_name', 'directory', 'fail_on_empty', 'sort_keys']

It looks like the .env file is properly generated as I don't have any key error afterward but why this warning?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.