Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions .github/workflows/npm-publish.yml

This file was deleted.

46 changes: 40 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,64 @@ name: Release
on:
push:
tags:
- "*"
- "v*"
workflow_dispatch:
inputs:
tag_name:
description: "Tag to release"
required: false
type: string

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.18
go-version: "1.20"

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean --timeout 80m # Changed --rm-dist to --clean
args: release --clean --timeout 80m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-npm:
needs: release
runs-on: ubuntu-latest
# Only publish for real tag pushes (not workflow_dispatch reruns).
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org/"

- name: Sync package.json version to the tag
run: |
VERSION="${GITHUB_REF#refs/tags/v}"
echo "Publishing tuido@${VERSION}"
cd tuido-npm
npm version "${VERSION}" --no-git-tag-version --allow-same-version

- name: Install dependencies
run: cd tuido-npm && (npm ci || npm install)

- name: Publish to npm
run: cd tuido-npm && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# .goreleaser.yaml
version: 2

builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w -X github.com/nilock/tuido/utils.version=v{{ .Version }}
goos:
- darwin
- linux
Expand Down
4 changes: 4 additions & 0 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func newTUI(items []*tuido.Item, cfg config) tui {

func (t *tui) houseKeeping() {
local := utils.Version()
if local == "dev" {
// Unversioned local build; no meaningful release to compare against.
return
}
curent := utils.LatestVersion()

if local != curent {
Expand Down
2 changes: 1 addition & 1 deletion tuido-npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tuido",
"version": "0.0.17",
"version": "0.0.18",
"description": "Terminal interface for managing tasks and todos in [x]it! format",
"bin": {
"tuido": "./bin/tuido-cli.js"
Expand Down
20 changes: 19 additions & 1 deletion utils/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,34 @@ import (
"net/url"
"os"
"runtime"
"runtime/debug"
"strings"
"time"
)

const version = "v0.0.18"
// version is injected at build time by GoReleaser via
// -ldflags "-X github.com/nilock/tuido/utils.version=vX.Y.Z".
// For unversioned local builds (go build / go run) it stays "dev".
var version = "dev"

const ReleaseURL = "https://github.com/NiloCK/tuido/releases/latest"
const GitHubAPIURL = "https://api.github.com/repos/NiloCK/tuido/releases/latest"

// Version returns the currently running version of the application.
//
// Precedence:
// 1. the ldflags-injected value (release binaries),
// 2. the module version for `go install module@vX.Y.Z` builds,
// 3. "dev" for unversioned local builds.
func Version() string {
if version != "dev" {
return version
}
if info, ok := debug.ReadBuildInfo(); ok {
if v := info.Main.Version; v != "" && v != "(devel)" {
return v
}
}
return version
}

Expand Down
89 changes: 7 additions & 82 deletions utils/versioning_test.go
Original file line number Diff line number Diff line change
@@ -1,93 +1,18 @@
package utils_test

import (
"fmt"
"os"
"strconv"
"strings"
"testing"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/nilock/tuido/utils"
)

// TestVersion sanity-checks the version reporting. The concrete version is
// injected at build time by GoReleaser via -ldflags (see .goreleaser.yaml),
// so for plain `go test` builds it is expected to report the "dev" fallback.
// The old test that compared a hardcoded const against the latest git tag is
// intentionally gone: the git tag is now the single source of version truth.
func TestVersion(t *testing.T) {
// get latest tag

// print working directory
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Error getting working directory: %s", err)
}

fmt.Println("PWD:", wd)

gitRepo, err := git.PlainOpen("..")
if err != nil {
t.Fatalf("Error opening git repo: %s", err)
}

tagRefs, err := gitRepo.Tags()
tags := []string{}

tagRefs.ForEach(func(tag *plumbing.Reference) error {
tags = append(tags, tag.Name().Short())
return nil
})

fmt.Println("TAGS:", tags)

// get latest tag
var latestTag string
var latestMajor, latestMinor, latestPatch = -1, -1, -1

for _, tag := range tags {
// Remove 'v' prefix
version := strings.TrimPrefix(tag, "v")

split := strings.Split(version, ".")
if len(split) != 3 {
continue
}

major, err := strconv.Atoi(split[0])
if err != nil {
continue
}
minor, err := strconv.Atoi(split[1])
if err != nil {
continue
}
patch, err := strconv.Atoi(split[2])
if err != nil {
continue
}

// First tag or higher major version
if latestMajor == -1 || major > latestMajor {
latestMajor, latestMinor, latestPatch = major, minor, patch
latestTag = tag
continue
}

// Same major, higher minor
if major == latestMajor && minor > latestMinor {
latestMajor, latestMinor, latestPatch = major, minor, patch
latestTag = tag
continue
}

// Same major and minor, higher patch
if major == latestMajor && minor == latestMinor && patch > latestPatch {
latestMajor, latestMinor, latestPatch = major, minor, patch
latestTag = tag
}
}

want := latestTag

if got := utils.Version(); got != want {
t.Errorf("Version() = %v, want %v", got, want)
if got := utils.Version(); got == "" {
t.Errorf("Version() returned empty string")
}
}
Loading