schdck / create-env-json

GitHub action that writes environment variables (or anything you want) to a JSON
MIT License
15 stars 15 forks source link

JSON is all uppercase #2

Open ylupien opened 4 years ago

ylupien commented 4 years ago

Hi !

Look like I have an case issue with this github action. I specified lower case in the configuration and the generated file is in uppercase.

      - name: Write hg-version.json
        uses: schdck/create-env-json@v2
        id: create-env
        with:
          file-name: './public/hg-version.json'
          version: ${{ github.sha }}
          test: '123'
{"VERSION":"695927bb3fa6176ae36ccb2216aa53dc85b5b542","TEST":"123"}

Any recommendation ?

SouthernYoda commented 4 years ago

I encountered the same issue.

@ylupien have you managed to find a resolution for this?

schdck commented 4 years ago

Hey @ylupien @SouthernYoda, sorry for the delay. I've taken a quick look into the code but haven't managed to identify what's causing this behavior. Fixing this would require some debugging, which I don't currently have the time to do. I'll take a look into it as soon as I can, but in the mean time, feel free to take a look and submit a PR if you guys find anything

SouthernYoda commented 4 years ago

This appears to be a limitation of using GitHub inputs in this way, the input keys are automatically converted to uppercase as described in the documentation for GitHub inputs. It's too bad because I really like how you specified the inputs.

"When you specify an input to an action in a workflow file or use a default input value, GitHub creates an environment variable for the input with the name INPUT_. The environment variable created converts input names to uppercase letters and replaces spaces with _ characters." (https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs)

I've forked your repo and printed the "key" variable to console. The key value is already uppercase when it is read by the script. image

A resolution might be to nest the input so the user enters in:

<arbitrary element name>: 
  key: <desired key>
  value: <value>
<arbitrary element name>:
  key: <desired key>
  value: <value>

Hope this helped, I don't have experience with node so this is as much help as I can provide for now.

dotKuro commented 3 years ago

What about?:

json-content:
  - key: foo
    value: blub
  - key: bar
    value: buz

This would eliminate the unnecessary name for each element.

metaben commented 2 years ago

A workaround is to follow this step with jacobtomlinson/gha-find-replace@v2 to overwrite the uppercase inside the json.

andrew-fennell commented 2 years ago

I just forked the repo and converted all keys to be lowercase. If anyone needs that specific functionality, you can find it here: https://github.com/andrew-fennell/create-env-json

If you need specific capitalization (not all lowercase or uppercase), such as "Key", the current release of this repo (v2) and my fork (v3) will not work for you.

I believe the underlying issue is how GitHub handles the inputs.