diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index f648506..22fd183 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -8,18 +8,18 @@ on: jobs: build: - runs-on: ubuntu-latest # You can change this to macos-latest or windows-latest if needed + runs-on: ubuntu-24.04 # You can change this to macos-latest or windows-latest if needed steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 'stable' # You can specify a specific version or 'stable' + go-version: '1.24.4' # You can specify a specific version or 'stable' - name: Build - run: go build -v ./... + run: make build - name: Test run: go test -v ./... @@ -38,4 +38,4 @@ jobs: if [ -n "$(golint./...)" ]; then echo "Go code has style issues. Please run 'golint./...' to see them." exit 1 - fi \ No newline at end of file + fi diff --git a/.gitignore b/.gitignore index 64342cf..204ec58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/twilio_sender +/sender /messages /numbers -/twilio_details.json +/config.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9ec4765..c0985a8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ image: golang:1.24 stages: - test - build - - deploy + # - deploy format: stage: test @@ -24,13 +24,13 @@ format: compile: stage: build script: - - mkdir -p mybinaries - - go build -o mybinaries ./... + - make build + artifacts: paths: - mybinaries -deploy: - stage: deploy - script: echo "Define your deployment script!" - environment: production +# deploy: + # stage: deploy + # script: echo "Define your deployment script!" + # environment: production diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3137db4 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +VERSION ?= $(shell git describe --tags 2>/dev/null || echo "dev") +COMMIT ?= $(shell git rev-parse --short HEAD) +BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) +GO_VERSION ?= $(shell go version | awk '{print $$3}') + +.PHONY: build +build: + go build -ldflags="\ + -X 'git.kundeng.us/phoenix/sender/version.Version=$(VERSION)' \ + -X 'git.kundeng.us/phoenix/sender/version.BuildTime=$(BUILD_TIME)' \ + -X 'git.kundeng.us/phoenix/sender/version.Commit=$(COMMIT)' \ + -X 'git.kundeng.us/phoenix/sender/version.GoVersion=$(GO_VERSION)'" \ + -o sender main.go + +.PHONY: install +install: + go install -ldflags="\ + -X 'git.kundeng.us/phoenix/sender/version.Version=$(VERSION)' \ + -X 'git.kundeng.us/phoenix/sender/version.BuildTime=$(BUILD_TIME)' \ + -X 'git.kundeng.us/phoenix/sender/version.Commit=$(COMMIT)' \ + -X 'git.kundeng.us/phoenix/sender/version.GoVersion=$(GO_VERSION)'" diff --git a/README.md b/README.md index b3dd98f..fa6405d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# twilio_sender -twilio_sender is a cli program to send text messages. +# sender +sender is a cli program to send text messages. ## Install twilio ``` -go build +make build ``` ## Using ``` -./twilio_sender config_path.json numbers_path.json message_path.json +./sender config_path.json numbers_path.json message_path.json ``` diff --git a/twilio_details.sample.json b/config.sample.json similarity index 100% rename from twilio_details.sample.json rename to config.sample.json diff --git a/config/config.go b/config/config.go index 127740f..93a85fc 100644 --- a/config/config.go +++ b/config/config.go @@ -5,7 +5,11 @@ import "fmt" import "os" import ( - "git.kundeng.us/phoenix/twilio_sender/models" + "git.kundeng.us/phoenix/sender/models" +) + +const ( + App_Name = "sender" ) func ParseConfig(filepath string) (config models.TwiloDetails, success bool) { diff --git a/go.mod b/go.mod index 13d7478..bb21009 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.kundeng.us/phoenix/twilio_sender +module git.kundeng.us/phoenix/sender go 1.24.4 diff --git a/main.go b/main.go index 4d2d784..cb379d2 100644 --- a/main.go +++ b/main.go @@ -4,14 +4,17 @@ import "fmt" import "os" import ( - "git.kundeng.us/phoenix/twilio_sender/config" - "git.kundeng.us/phoenix/twilio_sender/models" - "git.kundeng.us/phoenix/twilio_sender/sender" - "git.kundeng.us/phoenix/twilio_sender/util" + // "flag" + + "git.kundeng.us/phoenix/sender/config" + "git.kundeng.us/phoenix/sender/messaging" + "git.kundeng.us/phoenix/sender/models" + "git.kundeng.us/phoenix/sender/util" + // "git.kundeng.us/phoenix/sender/version" ) func main() { - fmt.Println("twilio_sender") + fmt.Println(config.App_Name) myArgs := os.Args argCount := len(myArgs) @@ -26,6 +29,16 @@ func main() { fmt.Printf("Config file path: %s\n", configPath) + // TODO: For version + /* + versionFlag := flag.Bool("version", false, "Print version information") + flag.Parse() + + if *versionFlag { + fmt.Println(version.String()) + return + } + */ cfg, _ := config.ParseConfig(configPath) cfg.PrintConfig() @@ -53,5 +66,5 @@ func main() { message.Print() - sender.SendMessages(cfg, numbers, message, 5) + messaging.SendMessages(cfg, numbers, message, 5) } diff --git a/sender/send_message.go b/messaging/messaging.go similarity index 95% rename from sender/send_message.go rename to messaging/messaging.go index 6c17ff6..c5eb428 100644 --- a/sender/send_message.go +++ b/messaging/messaging.go @@ -1,4 +1,4 @@ -package sender +package messaging import ( "encoding/json" @@ -7,7 +7,8 @@ import ( "github.com/twilio/twilio-go" twilioApi "github.com/twilio/twilio-go/rest/api/v2010" - "git.kundeng.us/phoenix/twilio_sender/models" + + "git.kundeng.us/phoenix/sender/models" ) func SendMessages(config models.TwiloDetails, numbers [](models.Number), message models.Message, secondInterval int) { diff --git a/send_messages.sh b/send_messages.sh index 4e802d3..92b9d41 100755 --- a/send_messages.sh +++ b/send_messages.sh @@ -9,7 +9,7 @@ if [[ ! -d "$root_dir" ]]; then exit fi -config_path="twilio_details.json" +config_path="config.json" numbers_part="0" numbers_path="numbers/numbers-$numbers_part.json" type_message="json" diff --git a/util/util.go b/util/util.go index b7a062a..ac31977 100644 --- a/util/util.go +++ b/util/util.go @@ -6,7 +6,7 @@ import "os" import "strings" import ( - "git.kundeng.us/phoenix/twilio_sender/models" + "git.kundeng.us/phoenix/sender/models" ) func GetPaths(args []string) (configPath string, numberPath string, messagePath string) {