Skip to content

Commit

Permalink
chore: move load .env file to top. (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy authored Jun 30, 2020
1 parent ce15798 commit 153fe2c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Load all environments from file.

```bash
docker run --rm \
-e ENV_FILE=your_env_file_path \
-e PLUGIN_ENV_FILE=your_env_file_path \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-telegram
Expand Down
15 changes: 5 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
)

Expand All @@ -15,6 +14,11 @@ var (
)

func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
_ = godotenv.Load(filename)
}

app := cli.NewApp()
app.Name = "telegram plugin"
app.Usage = "telegram plugin"
Expand Down Expand Up @@ -205,11 +209,6 @@ func main() {
Usage: "job finished",
EnvVar: "DRONE_BUILD_FINISHED",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
EnvVar: "ENV_FILE",
},
cli.BoolFlag{
Name: "github",
Usage: "Boolean value, indicates the runtime environment is GitHub Action.",
Expand Down Expand Up @@ -258,10 +257,6 @@ func main() {
}

func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}

plugin := Plugin{
GitHub: GitHub{
Workflow: c.String("github.workflow"),
Expand Down

0 comments on commit 153fe2c

Please sign in to comment.