aasmal97 / create-react-app-env

This Github Action generates a local .env file in a github runner for react apps, by extracting environment variables from your secrets or custom defined object, that match the prefix "REACT_APP"
https://github.com/marketplace/actions/create-react-app-env
2 stars 0 forks source link

.env file is gone after it is moved #1

Closed danilobjr closed 1 year ago

danilobjr commented 1 year ago

Hello,

I'm trying to use this action but having some issues with it. Can you help me with it?

Description

After the .env file creation, it's moved to root folder. This root folder should be the same folder of my package.json file, but I'm already running this action in my project root folder. So I tried to ls -la to see if .env file was created, but I couldn't see it.

Screenshots

Screenshot 2023-04-18 at 12 41 01

Workflow

name: Preview Deployment

on: workflow_dispatch

jobs:
  deploy-preview:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Trying to restore npm cache
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Generate .env file
        uses: aasmal97/create-react-app-env@1.1.0
        with:
          REACT_APP_SECRETS: ${{toJson(secrets)}}

      - name: Display env content
        run: cat .env

      # other steps ....
aasmal97 commented 1 year ago

Hey to help out, can you give me an outline of your project directory structure?

I think I have an idea of the issue, but I want to confirm before I make any changes to the action script.

Right now, my immediate inclination is that the project being run, contains multiple package.json files, and the .env file is placed in the directory level that is found first. However, I want to see how your project directory structure is, to see if it's something else :) !

danilobjr commented 1 year ago

@aasmal97 thanks for the rapid response!

It's a regular create-react-app application (using craco on top of that).

Root folder structure

drwxr-xr-x   30 danilo  staff     960 Apr 18 15:26 .
drwxr-xr-x    7 danilo  staff     224 Mar 31 03:01 ..
-rw-r--r--@   1 danilo  staff    8196 Apr 18 15:16 .DS_Store
-rw-r--r--    1 danilo  staff     201 Apr  5 07:36 .editorconfig
-rw-r--r--    1 danilo  staff      18 Apr  5 07:36 .env.example
-rw-r--r--    1 danilo  staff      88 Apr 18 15:23 .env.local
drwxr-xr-x   18 danilo  staff     576 Apr 18 15:20 .git
drwxr-xr-x    3 danilo  staff      96 Apr  5 20:04 .github
-rw-r--r--    1 danilo  staff     318 Apr  5 20:04 .gitignore
drwxr-xr-x    4 danilo  staff     128 Apr  5 07:36 .husky
-rw-r--r--    1 danilo  staff     117 Apr  5 07:36 .lintstagedrc
-rw-r--r--    1 danilo  staff      56 Apr  5 07:36 .prettierignore
-rw-r--r--    1 danilo  staff     362 Apr  5 07:36 .prettierrc
drwxr-xr-x    4 danilo  staff     128 Apr  6 21:12 .vercel
drwxr-xr-x    3 danilo  staff      96 Apr 18 12:51 .vscode
-rw-r--r--    1 danilo  staff    2117 Apr  5 07:36 README.md
drwxr-xr-x   10 danilo  staff     320 Apr 18 13:23 build
-rw-r--r--    1 danilo  staff     268 Apr 18 12:51 craco.config.js
-rw-r--r--    1 danilo  staff     752 Apr 17 22:54 meeting.md
drwxr-xr-x  889 danilo  staff   28448 Apr 18 13:08 node_modules
-rw-r--r--    1 danilo  staff  643226 Apr 18 12:51 package-lock.json
-rw-r--r--    1 danilo  staff    1542 Apr 18 12:51 package.json
-rw-r--r--    1 danilo  staff   28936 Apr  5 07:36 products.json
drwxr-xr-x    9 danilo  staff     288 Apr 18 15:20 public
drwxr-xr-x   15 danilo  staff     480 Apr 18 13:34 src
-rw-r--r--    1 danilo  staff    1390 Apr 18 12:51 tailwind.config.js
-rw-r--r--    1 danilo  staff      84 Apr 18 15:26 test.md
-rw-r--r--    1 danilo  staff     541 Apr  5 07:36 tsconfig.json
-rw-r--r--    1 danilo  staff     320 Apr  5 07:36 tsconfig.paths.json
-rw-r--r--    1 danilo  staff     147 Apr 18 15:20 vercel.json

If you need something more, just tell me.

danilobjr commented 1 year ago

Something came to my mind. If I may suggest it...

What about to include an input like working-directory? With that you could set manually where you want to place the .env file. It'll be a controlled situation and the developer will always know the folder destination.

What do you think?

Example

- name: Generate .env file
  uses: aasmal97/create-react-app-env@1.1.0
  with:
    working-directory: ./
    REACT_APP_SECRETS: ${{toJson(secrets)}}
aasmal97 commented 1 year ago

That sounds like a good idea :) ! I'm going to work on adding that feature but I also realized in my most recent project, the auto-detecting of the package.json location is behaving weirdly. I'm going to work on a fix for that and hopefully have it ready by the end of this week. @danilobjr

aasmal97 commented 1 year ago

This issue has been resolved :) ! In addition, there is support for multiple new inputs including a destination path