Skip to content

Commit

Permalink
feat: try to add go-releaser
Browse files Browse the repository at this point in the history
  • Loading branch information
Primexz committed Apr 26, 2024
1 parent 8c71da1 commit ae89aad
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 38 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run Gosec
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
gosec:
name: GoSec Security Scanner
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Install GoSec 2.18.2
run: |
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.19.0
- name: Run Gosec Security Scanner
run: |
cd radicalvpnd
$(go env GOPATH)/bin/gosec ./...
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release

on:
push:
tags:
- v*

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
id: go

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
project_name: kraken-dca
builds:
- goos:
- linux
- darwin
goarch:
- amd64
- arm
- arm64
goarm:
- "6"
- "7"
release:
draft: true
snapshot:
name_template: "{{ .Version }}-{{.ShortCommit}}"
checksum:
name_template: "{{ .ProjectName }}_checksums.txt"
dockers:
- image_templates:
- "gcr.io/primexz/kraken_dca:{{ .Tag }}"
- "gcr.io/primexz/kraken_dca:latest"
changelog:
use: github
sort: asc
20 changes: 3 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
FROM golang:1.22
FROM scratch

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

COPY . /app/

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /kraken_dca

EXPOSE 8080

# Run
CMD ["/kraken_dca"]
ENTRYPOINT ["/kraken-dca"]
COPY kraken-dca /
17 changes: 3 additions & 14 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func run() {

log.Println("Next Fiat deposit required at", timeOfEmptyFiat)

updateFiatBalance(fiatAmount)
lastFiatBalance = fiatAmount
}

lastBtcFiatPrice = kraken.GetCurrentBtcFiatPrice()
Expand All @@ -60,22 +60,11 @@ func run() {

if (timeOfNextOrder.Before(time.Now()) || newFiatMoney) && !initialRun {
log.Println("Placing bitcoin purchase order. ₿")

kraken.BuyBtc()

calculateTimeOfNextOrder()
}

log.Println("Next order in", fmtDuration(time.Until(timeOfNextOrder)), timeOfNextOrder)
}

func calculateTimeOfNextOrder() {
fiatValueInBtc := fiatAmount / lastBtcFiatPrice
orderAmountUntilRefill := fiatValueInBtc / config.KrakenOrderSize

now := time.Now().UnixMilli()
timeOfNextOrder = time.UnixMilli((timeOfEmptyFiat.UnixMilli()-now)/int64(orderAmountUntilRefill) + now)
}

func updateFiatBalance(fiat float64) {
lastFiatBalance = fiat
}
}
27 changes: 27 additions & 0 deletions bot/calculations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package bot

import (
"time"

"github.com/primexz/KrakenDCA/config"
)

func computeNextFiatDepositDay() time.Time {
date := addMonthsToTime(1, time.Now())

//get the first day of the month
return date.AddDate(0, 0, -date.Day()+1)
}

func calculateTimeOfNextOrder() {
orderAmountUntilRefill := getOrderAmountUntilRefill()

now := time.Now().UnixMilli()
timeOfNextOrder = time.UnixMilli((timeOfEmptyFiat.UnixMilli()-now)/int64(orderAmountUntilRefill) + now)
}

func getOrderAmountUntilRefill() float64 {
fiatValueInBtc := fiatAmount / lastBtcFiatPrice

return fiatValueInBtc / config.KrakenOrderSize
}
7 changes: 0 additions & 7 deletions bot/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import (
"time"
)

func computeNextFiatDepositDay() time.Time {
date := addMonthsToTime(1, time.Now())

//get the first day of the month
return date.AddDate(0, 0, -date.Day()+1)
}

func addMonthsToTime(months int, time time.Time) time.Time {
return time.AddDate(0, months, 0)
}
Expand Down

0 comments on commit ae89aad

Please sign in to comment.