From 35fb60e6928288df6b8ac2d1aa9521e6fc7b6bcb Mon Sep 17 00:00:00 2001 From: Sam Fredrickson Date: Sun, 17 Mar 2024 19:01:59 -0700 Subject: [PATCH] Add starting price to table; add Gitea workflows. --- .gitea/workflows/build.yaml | 38 +++++++++++++++++++++++++ .gitea/workflows/release-tag.yaml | 30 ++++++++++++++++++++ .goreleaser.yaml | 46 +++++++++++++++++++++++++++++++ moonmath.go | 14 ++++++---- 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 .gitea/workflows/build.yaml create mode 100644 .gitea/workflows/release-tag.yaml create mode 100644 .goreleaser.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..2d256df --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,38 @@ +name: Build & Test +on: + push: + branches: + - "**" + +jobs: + Main: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.22.1 + - + name: Run linter + uses: golangci/golangci-lint-action@v3 + with: + version: v1.56 + - + name: Run tests + run: go test ./... + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: 1.24.0 + args: release --clean --snapshot + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GORELEASER_FORCE_TOKEN: gitea diff --git a/.gitea/workflows/release-tag.yaml b/.gitea/workflows/release-tag.yaml new file mode 100644 index 0000000..1288262 --- /dev/null +++ b/.gitea/workflows/release-tag.yaml @@ -0,0 +1,30 @@ +name: Release +on: + push: + tags: + - v* + +jobs: + Release: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.22.1 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: 1.24.0 + args: release --clean + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GORELEASER_FORCE_TOKEN: gitea diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d6b83ad --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,46 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 1 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +gitea_urls: + api: https://code.humancabbage.net/api/v1 + download: http://code.humancabbage.net diff --git a/moonmath.go b/moonmath.go index 54ef8ba..db83bad 100644 --- a/moonmath.go +++ b/moonmath.go @@ -52,18 +52,19 @@ func initialModel() model { Width: 10, }) } - projectionRows := make([]table.Row, len(math.Goals)+1) + projectionRows := make([]table.Row, len(math.Goals)+2) for i := range projectionRows { projectionRows[i] = make(table.Row, len(projectionCols)) } - projectionRows[0][0] = "CDPR" + projectionRows[0][0] = "Starting" + projectionRows[1][0] = "CDPR" for i := range math.Goals { - projectionRows[i+1][0] = fmt.Sprintf("$%.0f", math.Goals[i]) + projectionRows[i+2][0] = fmt.Sprintf("$%.0f", math.Goals[i]) } projections := table.New( table.WithColumns(projectionCols), table.WithRows(projectionRows), - table.WithHeight(len(math.Goals)+1), + table.WithHeight(len(math.Goals)+2), table.WithStyles(tableStyle), ) @@ -110,7 +111,8 @@ func refillProjections(m *model) { never = true } - rows[0][col+1] = fmt.Sprintf("%.2f%%", (m.math.Columns[col].CDPR-1)*100) + rows[0][col+1] = fmt.Sprintf("$%.2f", m.math.Columns[col].StartingPrice) + rows[1][col+1] = fmt.Sprintf("%.2f%%", (m.math.Columns[col].CDPR-1)*100) for row := 0; row < len(m.math.Goals); row++ { var cell string if never { @@ -120,7 +122,7 @@ func refillProjections(m *model) { Projections.Dates[row]. Format("2006-01-02") } - rows[row+1][col+1] = cell + rows[row+2][col+1] = cell } } m.projections.SetRows(rows)