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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Build, vet, test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: go vet
run: go vet ./...

- name: go test
run: go test ./...

- name: go build
run: go build -o esp .

- name: Validate GoReleaser config
uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
args: check
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*'

permissions:
contents: write

jobs:
release:
name: GoReleaser
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.espFile.yaml
.worktrees/
.claude/
/esp
/dist/

# Test binary, build with `go test -c`
*.test
Expand Down
64 changes: 64 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 2

before:
hooks:
- go mod tidy
- go test ./...

builds:
- id: esp
binary: esp
main: .
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: darwin
goarch: amd64
ldflags:
- -s -w
- -X github.com/AbsolutOD/esp/cmd.version={{.Tag}}
- -X github.com/AbsolutOD/esp/cmd.commit={{.ShortCommit}}
- -X github.com/AbsolutOD/esp/cmd.date={{.Date}}

archives:
- id: esp
name_template: "esp_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
formats: [tar.gz]
files:
- LICENSE
- README.md

checksum:
name_template: "checksums.txt"
algorithm: sha256

changelog:
sort: asc
use: git
groups:
- title: Features
regexp: '^.*?feat(\(.+\))??!?:.+$'
order: 0
- title: Fixes
regexp: '^.*?fix(\(.+\))??!?:.+$'
order: 1
- title: Others
order: 999
filters:
exclude:
- '^docs:'
- '^test:'
- '^chore:'
- merge conflict
- Merge pull request
- Merge remote-tracking branch
- Merge branch

release:
draft: false
15 changes: 14 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,31 @@ import (
"github.com/spf13/cobra"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

func newVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Version of esp",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
return runVersion()
},
}
}

func versionString() string {
return fmt.Sprintf("esp %s (commit %s, built %s)", version, commit, date)
}

func runVersion() error {
fmt.Println("ESP version 0.2.0")
fmt.Println(versionString())
return nil
}
47 changes: 46 additions & 1 deletion cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
package cmd

import "testing"
import (
"bytes"
"io"
"os"
"testing"

"github.com/AbsolutOD/esp/internal/app"
)

func TestVersionCmd_NoAWSEnvVars(t *testing.T) {
unsetEnv(t, "AWS_DEFAULT_REGION")
unsetEnv(t, "AWS_PROFILE")

a := &App{Config: app.New(false)}
a.Config.Backend = "ssm"
root := newRootCmd(a)
root.AddCommand(newVersionCmd())
root.SetArgs([]string{"version"})

// Capture stdout — runVersion uses fmt.Println, which writes to os.Stdout.
r, w, _ := os.Pipe()
origStdout := os.Stdout
os.Stdout = w
t.Cleanup(func() { os.Stdout = origStdout })

err := root.Execute()
_ = w.Close()
out, _ := io.ReadAll(r)

if err != nil {
t.Fatalf("Execute() returned error %v; expected nil (version should bypass AWS checks)", err)
}
got := string(bytes.TrimRight(out, "\n"))
want := "esp dev (commit none, built unknown)"
if got != want {
t.Errorf("stdout = %q, want %q", got, want)
}
}

func TestRunVersion(t *testing.T) {
if err := runVersion(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

func TestVersionString_Defaults(t *testing.T) {
got := versionString()
want := "esp dev (commit none, built unknown)"
if got != want {
t.Fatalf("versionString() = %q, want %q", got, want)
}
}
Loading
Loading