Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
Merge pull request #1 from cadusk/feature-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cadusk authored Nov 23, 2024
2 parents 2a9ea93 + bbe77ec commit bfb5618
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/daily-run.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test:
go test -v ./...

run: build
sh -c "source .env && $(BINARY_NAME)"
$(BINARY_NAME)

vet:
go vet $(APP)
Expand Down
12 changes: 10 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bfb5618

Please sign in to comment.