Skip to content

Commit

Permalink
Fail if key is empty (#39)
Browse files Browse the repository at this point in the history
* Added fail case, added tests

* Fixed empty key error message
  • Loading branch information
AngelOnFira committed Feb 15, 2022
1 parent 5f7e9a8 commit 5c1cd6f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,37 @@ jobs:
then
echo "ERR"
fi
should-fail-test-absolute-path:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Create folder
run: |
mkdir -p subdir
- name: Make envfile
uses: ./
with:
envkey_DEBUG: false
directory: /home


should-fail-test-bad-secret:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Create folder
run: |
mkdir -p subdir
- name: Make envfile
uses: ./
with:
envkey_SECRET_KEY: ${{ secrets.NON_EXISTENT_SECRET }}
8 changes: 7 additions & 1 deletion src/create-envfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
# Make sure the env keys are sorted to have reproducible output
for key in sorted(env_keys):
if key.startswith("INPUT_ENVKEY_"):
out_file += "{}={}\n".format(key.split("INPUT_ENVKEY_")[1], os.getenv(key))
value = os.getenv(key, "")

# If the key is empty, throw an error.
if value == "":
raise Exception(f"Empty env key found: {key}")

out_file += "{}={}\n".format(key.split("INPUT_ENVKEY_")[1], value)

# get directory name in which we want to create .env file
directory = str(os.getenv("INPUT_DIRECTORY", ""))
Expand Down

0 comments on commit 5c1cd6f

Please sign in to comment.