diff --git a/.github/workflows/daily-run.yml b/.github/workflows/daily-run.yml new file mode 100644 index 0000000..ce7b487 --- /dev/null +++ b/.github/workflows/daily-run.yml @@ -0,0 +1,36 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Send daily budget notification + +on: + workflow_dispatch: + # schedule time is UTC. 12pm UTC = 7am EST + schedule: + - cron: "0 12 * * *" + +env: + SENDGRID_TOKEN: ${{ secrets.SENDGRID_TOKEN }} + SENDGRID_TEMPLATE_ID: ${{ secrets.SENDGRID_TEMPLATE_ID }} + SENDGRID_MAIL_FROM: ${{ secrets.SENDGRID_MAIL_FROM }} + SENDGRID_MAIL_FROM_NAME: "Budget Notification Service - GitHub Action" + SENDGRID_MAIL_TO: ${{ secrets.SENDGRID_MAIL_TO }} + YNAB_TOKEN: ${{ secrets.YNAB_TOKEN }} + YNAB_BUDGET_ID: ${{ secrets.YNAB_BUDGET_ID }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + # it should be possible to cache dependencies... but let's make this work first. + # cache-dependency-path: go.sum + + - name: Build + run: go run ./cmd/ynot/main.go + diff --git a/Makefile b/Makefile index f36ed9b..b6ce57b 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ test: go test -v ./... run: build - sh -c "source .env && $(BINARY_NAME)" + $(BINARY_NAME) vet: go vet $(APP) diff --git a/internal/config/config.go b/internal/config/config.go index e5c4e28..d8f3ef6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,13 +24,21 @@ type Config struct { } func NewConfig() *Config { - viper.SetConfigFile(EnvFileName) + // Read settings from environment variables + viper.AutomaticEnv() + + // Read settings from config file + viper.SetConfigFile(EnvFileName) err := viper.ReadInConfig() if err != nil { - panic(fmt.Errorf("fatal error config file: %w\n", err)) + // TODO: convert to logging instead of printing to stdout + fmt.Printf("Unable to read configuration file. Relying on envinronment variables only.\n") } + // Store settings into Config struct. + // The way viper works is that it will look for the key in the environment variables + // and if it doesn't find it, it will look for the key in the config file c := Config{} c.Sendgrid.AccessToken = viper.GetString("SENDGRID_TOKEN") c.Sendgrid.TemplateID = viper.GetString("SENDGRID_TEMPLATE_ID")