Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from Sonlis/add-ci
Browse files Browse the repository at this point in the history
Add ci
  • Loading branch information
Sonlis authored Dec 19, 2023
2 parents 29d2aa4 + 89b54f7 commit 04ae979
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 10 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: BuildAndPublish
on:
workflow_dispatch:
inputs:
version:
description: Version to publish
required: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.0'
- name: Install dependencies
run: go mod tidy
- name: Test with the Go CLI
run: make test
- name: Build binary
run: go build cmd/server/server.go -o server
- name: Build docker image
run: |
docker buildx build --push \
--tag bastibast/athene-events-reminder:${{ github.event.inputs.version }} \
--platform linux/amd64,linux/arm/v7,linux/arm64 .
11 changes: 11 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Test
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Test with the Go CLI
run: make test
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3 as packages
RUN apk --update add ca-certificates
RUN apk add tzdata

FROM scratch
WORKDIR /opt/app

COPY --from=packages /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=packages /usr/share/zoneinfo /usr/share/zoneinfo
COPY server server

USER 1001
ENTRYPOINT ["./server"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gotest:
compose:
docker-compose up -d
sleep 3
PGPASSWORD=test_pass psql -h localhost -p 5447 -U test_user -d test -c "CREATE TABLE IF NOT EXISTS reminder(chat_id int, event_id int, reminder_time timestamp);"
PGPASSWORD=test_pass psql -h localhost -p 5447 -U test_user -d test -c "CREATE TABLE IF NOT EXISTS reminder(chat_id int, event_id int, reminder_time timestamptz);"

.PHONY: clean
clean:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ services:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
POSTGRES_DB: test
TZ: UTC
ports:
- 5447:5432
2 changes: 0 additions & 2 deletions internal/handle/buttonHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handle

import (
"context"
"fmt"

"strconv"
"strings"
Expand All @@ -21,7 +20,6 @@ func handleEventInfo(ctx context.Context, ilmo *event.Ilmo, query tgbotapi.Callb
if err != nil {
return text, markup, err
}
fmt.Println(event.RegistrationStartDate)
reminderSet, err := db.CheckReminder(ctx, message.Chat.ID, event.ID)
if err != nil {
return text, markup, err
Expand Down
4 changes: 1 addition & 3 deletions internal/handle/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ var backButton = "Back"
// buildEventsMarkup builds the markup structure returned when a single event is requested.
func buildEventInfoMarkup(event event.Event, reminderSet bool) tgbotapi.InlineKeyboardMarkup {
// Set the reminde to be 5 minutes before the event registration starts.
// Also remove 2 hours to the time, because the event is in UTC+2, while the db time is in UTC.
// Should be removed once the db timezone is correctly set.
reminderTime := event.RegistrationStartDate.Add(time.Duration(-5) * time.Minute).Add(time.Duration(-2) * time.Hour).Format("2006-01-02T15:04:05Z07:00")
reminderTime := event.RegistrationStartDate.Add(time.Duration(-5) * time.Minute).UTC().Format("2006-01-02T15:04:05Z07:00")
if reminderSet {
return tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow(
Expand Down
1 change: 1 addition & 0 deletions internal/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func getReminders(ctx context.Context, db *database.DB, i *event.Ilmo) ([]Remind
if err := rows.Scan(&reminder.ChatId, &reminder.EventId, &reminder.ReminderTime); err != nil {
return nil, err
}
reminder.ReminderTime = reminder.ReminderTime.UTC()
reminders = append(reminders, reminder)
}
if err := rows.Err(); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions internal/notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func TestGetReminders(t *testing.T) {

timeToInsert := time.Date(2023, 12, 8, 16, 0, 0, 0, time.UTC)

currentTime := time.Now().Add(time.Second * 30).Add(time.Duration(-2) * time.Hour)

currentTime := time.Now().Add(time.Second * 30).UTC()
err = db_conn.CreateReminder(context.Background(), 1, 1, timeToInsert)
if err != nil {
t.Errorf("Failed to create reminder: %v", err)
Expand All @@ -48,11 +47,11 @@ func TestGetReminders(t *testing.T) {
if err != nil {
t.Errorf("Error while getting reminders: %v", err)
}
want := Reminder{2, 2, currentTime.UTC().Add(time.Hour * 2)}
want := Reminder{2, 2, currentTime}
if len(reminders) != 1 {
t.Errorf("Expected 1 reminder, got %v", len(reminders))
}
if reminders[0] != want {
if !reminders[0].ReminderTime.Truncate(time.Second).Equal(want.ReminderTime.Truncate(time.Second)) {
t.Errorf("Expected %v, got %v", want, reminders[0])
}
}
Expand Down

0 comments on commit 04ae979

Please sign in to comment.