Task: Allow dotenv files that do not exist

Created on 14 Sep 2020  路  4Comments  路  Source: go-task/task

A typical workflow involving .env files is:

  1. .env is in .gitignore
  2. A project repository includes a .env.example file
  3. A "first run" script creates a .env from .env.example in the developers environment

I would like to use task instead of make, and as part of that I need to use task for my project's "first run" script -- which creates the .env file. Unfortunately, task throws an error because .env doesn't yet exist.

version: '3'

dotenv: ['.env']

tasks:
  default:
    cmds:
      - cp -n .env.example .env # contrived example
open .env: no such file or directory

There's an issue in the godotenv project (https://github.com/joho/godotenv/issues/99) associated with this use-case as the error is being thrown by that library, however I've noticed in the tests for task it is explicitly intended that an error is thrown when the .env file does not exist.

Once the issue is fixed in godotenv it would be good to have the intended behaviour of task reviewed -- https://github.com/go-task/task/blob/master/task_test.go#L832

enhancement

Most helpful comment

This is now fixed in master

All 4 comments

This is blocking for us as well.

We moved from Makefile to Taskfile but taskfile has .env as mandatory.

We used following code in Makefile.

-include .env
export

equivalent is not available in taskfile, when developer misses to checkin empty .env file, CI fails.

I missed this scenario when I was testing. I will push a PR in a day or two.

Hi @shrink, thanks for opening this issue!

This suggestion is reasonable indeed

This is now fixed in master

Was this page helpful?
0 / 5 - 0 ratings