Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'built-test-deploy'
name: 'build-test-deploy'
on:
pull_request:
paths-ignore:
Expand Down Expand Up @@ -91,3 +91,20 @@ jobs:
ACTION_CREATE_ENV_TEST: 1
- run: cat .env
- run: grep -zP "^PROD=0\nTEST=1$" .env
test-skip-env-vars-when-include_env_vars-disabled:
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- uses: ./
with:
full_text: PROD=0
env:
ACTION_CREATE_ENV_TEST: 1
- run: cat .env
- run: grep -zP "^PROD=0$" .env
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Create .env
# Create a .env

---

This action will create a `.env` file in the directory of your choice & with the content of your choice.

```yml
- name: Create .env 🤫
uses: DeveloperRic/action-create-env@v1.0.2 # set this to the version of your choice
with:
# Write your content here if you want. The content will be trimmed & dedent will be applied.
full_text: |
PROD=1
PORT=3000
API_AUDIENCE=api.mydomain.xyz
# Specify the directory that the .env file should go in.
# This defaults to the current directory (i.e. '.')
directory: ${{ github.workspace }}/server/src
# Set this if you want the action to look in environment variables for extra content. This input is not required.
# Note: setting to false or any other value will still enable environment variable lookup.
# If you don't want this turned on, don't include the input.
include_env_vars: true
env:
# If `include_env_vars` is true, the following environment variables will be written to the .env file as:
# PROD=${{ secrets.PROD }}
# ACTION_CREATE_ENV_JOKE: ${{ secrets.ACTION_CREATE_ENV_JOKE }}
# Note: `full_text` is dumped to the .env file first and subsequently environment variables are dumped.
# This means that duplicate entries may exist in the .env file.
ACTION_CREATE_ENV_PROD: ${{ secrets.PROD }}
ACTION_CREATE_ENV_ACTION_CREATE_ENV_JOKE: ${{ secrets.ACTION_CREATE_ENV_JOKE }}
```
12 changes: 12 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ test('includes env vars', async () => {
expect(content).toEqual(`PROD=0\n_${ENV_PREFIX}_TEST=1`)
})

test('skips env vars when include_env_vars is disabled', async () => {
const args: Args = {
directory: ARTIFACTS_PATH,
full_text: 'PROD=0\n', // should be trimmed
include_env_vars: !!''
}
process.env[`${ENV_PREFIX}_TEST`] = '1'
await writeToEnvFile(args)
const content = fs.readFileSync(`${args.directory}/.env`).toString()
expect(content).toEqual(`PROD=0`)
})

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_FULL_TEXT'] = 'PROD=0'
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Create a .env file'
description: 'Create a .env file'
branding:
icon: 'box'
color: 'orange'
author: 'https://github.com/DeveloperRic'
inputs:
full_text:
Expand Down