Skip to content

Commit b71a04b

Browse files
committed
Reorg, add goreleaser, update readme
1 parent 64d3cee commit b71a04b

File tree

10 files changed

+87
-126
lines changed

10 files changed

+87
-126
lines changed

.github/workflows/release.yml

+18-75
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,34 @@
1-
name: Build and Release
1+
name: Build and Release Go Project
22

33
on:
44
push:
55
tags:
66
- "v*"
77

8+
permissions:
9+
contents: write
10+
packages: write
11+
812
jobs:
913
build:
1014
runs-on: ubuntu-latest
11-
strategy:
12-
matrix:
13-
goos: [darwin, windows, linux]
14-
goarch: [amd64, arm64]
15-
exclude:
16-
- goos: darwin
17-
goarch: arm64
18-
1915
steps:
20-
- name: Check out code
21-
uses: actions/checkout@v2
16+
- name: Checkout code
17+
uses: actions/checkout@v4
2218

2319
- name: Set up Go
24-
uses: actions/setup-go@v2
25-
with:
26-
go-version: "^1.17"
27-
28-
- name: Build Project
29-
run: |
30-
export GOOS=${{ matrix.goos }}
31-
export GOARCH=${{ matrix.goarch }}
32-
go build -o build/my_app_${{ matrix.goos }}_${{ matrix.goarch }}
33-
34-
- name: Upload Artifacts
35-
uses: actions/upload-artifact@v2
20+
uses: actions/setup-go@v5
3621
with:
37-
name: my_app_${{ matrix.goos }}_${{ matrix.goarch }}
38-
path: build/my_app_${{ matrix.goos }}_${{ matrix.goarch }}
22+
go-version-file: "go.mod"
3923

40-
release:
41-
runs-on: ubuntu-latest
42-
needs: build
43-
steps:
44-
- name: Check out code
45-
uses: actions/checkout@v2
46-
47-
- name: Download Artifacts
48-
uses: actions/download-artifact@v2
49-
with:
50-
path: build/
51-
52-
- name: Create Release
53-
id: create_release
54-
uses: actions/create-release@v1
55-
with:
56-
tag_name: ${{ github.ref }}
57-
release_name: Release ${{ github.ref }}
58-
draft: false
59-
prerelease: false
60-
61-
- name: Upload Release Assets
62-
uses: actions/upload-release-asset@v1
63-
with:
64-
upload_url: ${{ steps.create_release.outputs.upload_url }}
65-
asset_path: build/my_app_darwin_amd64
66-
asset_name: my_app_darwin_amd64
67-
asset_content_type: application/octet-stream
68-
69-
- name: Upload Release Assets
70-
uses: actions/upload-release-asset@v1
71-
with:
72-
upload_url: ${{ steps.create_release.outputs.upload_url }}
73-
asset_path: build/my_app_windows_amd64
74-
asset_name: my_app_windows_amd64
75-
asset_content_type: application/octet-stream
76-
77-
- name: Upload Release Assets
78-
uses: actions/upload-release-asset@v1
79-
with:
80-
upload_url: ${{ steps.create_release.outputs.upload_url }}
81-
asset_path: build/my_app_linux_amd64
82-
asset_name: my_app_linux_amd64
83-
asset_content_type: application/octet-stream
24+
- name: Run tests
25+
run: make test
8426

85-
- name: Upload Release Assets
86-
uses: actions/upload-release-asset@v1
27+
- name: Run GoReleaser
28+
uses: goreleaser/goreleaser-action@v5
8729
with:
88-
upload_url: ${{ steps.create_release.outputs.upload_url }}
89-
asset_path: build/my_app_linux_arm64
90-
asset_name: my_app_linux_arm64
91-
asset_content_type: application/octet-stream
30+
distribution: goreleaser
31+
version: latest
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.DS_Store
2-
bin/
2+
dist/

.goreleaser.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
4+
version: 1
5+
6+
before:
7+
hooks:
8+
- go mod tidy
9+
10+
builds:
11+
- main: ./cmd/cng/
12+
env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- linux
16+
- windows
17+
- darwin
18+
19+
archives:
20+
- format: tar.gz
21+
# this name template makes the OS and Arch compatible with the results of `uname`.
22+
name_template: >-
23+
{{ .ProjectName }}_
24+
{{- title .Os }}_
25+
{{- if eq .Arch "amd64" }}x86_64
26+
{{- else if eq .Arch "386" }}i386
27+
{{- else }}{{ .Arch }}{{ end }}
28+
{{- if .Arm }}v{{ .Arm }}{{ end }}
29+
# use zip for windows archives
30+
format_overrides:
31+
- goos: windows
32+
format: zip
33+
34+
changelog:
35+
sort: asc
36+
filters:
37+
exclude:
38+
- "^docs:"
39+
- "^test:"

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ test:
88

99
.PHONY: test-e2e
1010
test-e2e:
11-
@go test -v ./test/...
11+
@gtc -v ./test/...
1212

1313
.PHONY: test-unit
1414
test-unit:
15-
@go test -v ./internal/...
15+
@gtc -v ./internal/...
1616

1717
.PHONY: watch-test
1818
watch-test:
@@ -32,8 +32,8 @@ watch-e2e-test:
3232

3333
.PHONY: build
3434
build:
35-
@CGO_ENABLED=0 go build -a -gcflags=all="-l -B" -ldflags="-s -w" -o bin/cng ./cmd/cng
36-
@echo "🎉 cng built to bin/cng"
35+
@CGO_ENABLED=0 go build -a -gcflags=all="-l -B" -ldflags="-s -w" -o dist/cng ./cmd/cng
36+
@echo "🎉 cng built to dist/cng"
3737

3838
.PHONY: install
3939
install:

README.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
55
## Install
66

7-
### Binary installs
7+
Download a [release](https://github.com/danawoodman/cng/releases) for your platform and add it to your path.
88

9-
**Coming soon(?):** Downloads for macOS, Linux, and Windows, homebrew, apt, etc...
10-
11-
### Install with Golang
9+
Or just install with Golang:
1210

1311
```shell
1412
go install github.com/danawoodman/cng
@@ -18,10 +16,10 @@ go install github.com/danawoodman/cng
1816

1917
```shell
2018
# Run `go run ./cmd/myapp` when any .go or .html files change.
21-
# `-i` runs the command once on load without any event
19+
# `-i` runs the command once initially, without any event
2220
# `-k`` kills running processes between changes
2321
# The command you want to run is followed by the `--` separator:
24-
cng -i -k '**/*.go' 'templates/**/*.html' -- go run ./cmd/myapp
22+
cng -ik '**/*.go' 'templates/**/*.html' -- go run ./cmd/myapp
2523

2624
# Run tests when your source or tests change:
2725
cng 'app/**/*.{ts,tsx}' '**/*.test.ts' -- npm test
@@ -52,13 +50,13 @@ Usage:
5250
cng [flags] [paths] -- [command]
5351
5452
Flags:
55-
-a, --add Execute command for initially added paths
56-
-d, --delay int Delay between process changes in milliseconds
57-
-e, --exclude strings Exclude matching paths
58-
-h, --help Help for cng
59-
-i, --initial Execute command once on load without any event
60-
-k, --kill Kill running processes between changes
61-
-v, --verbose Enable verbose logging
53+
-a, --add execute command for initially added paths
54+
-d, --delay int delay between process changes in milliseconds
55+
-e, --exclude strings exclude matching paths
56+
-h, --help help for cng
57+
-i, --initial execute command once on load without any event
58+
-k, --kill kill running processes between changes
59+
-v, --verbose enable verbose logging
6260
```
6361

6462
## Notes and Limitations

cmd/cng/main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ func init() {
3232
// Don't parse commands after the "--" separator
3333
rootCmd.Flags().SetInterspersed(false)
3434

35-
rootCmd.PersistentFlags().BoolVarP(&add, "add", "a", false, "Execute command for initially added paths")
36-
rootCmd.PersistentFlags().BoolVarP(&initial, "initial", "i", false, "Execute command once on load without any event")
37-
rootCmd.PersistentFlags().StringSliceVarP(&exclude, "exclude", "e", []string{}, "Exclude matching paths")
38-
rootCmd.PersistentFlags().BoolVarP(&kill, "kill", "k", false, "Kill running processes between changes")
39-
rootCmd.PersistentFlags().IntVarP(&delay, "delay", "d", 0, "Delay between process changes in milliseconds")
40-
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
35+
rootCmd.PersistentFlags().BoolVarP(&add, "add", "a", false, "execute command for initially added paths")
36+
rootCmd.PersistentFlags().BoolVarP(&initial, "initial", "i", false, "execute command once on load without any event")
37+
rootCmd.PersistentFlags().StringSliceVarP(&exclude, "exclude", "e", []string{}, "exclude matching paths")
38+
rootCmd.PersistentFlags().BoolVarP(&kill, "kill", "k", false, "kill running processes between changes")
39+
rootCmd.PersistentFlags().IntVarP(&delay, "delay", "d", 0, "delay between process changes in milliseconds")
40+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
4141
// TODO: implement more onchange features:
4242
// rootCmd.PersistentFlags().BoolVar(&noExclude, "no-exclude", false, "Disable default exclusion")
4343
// rootCmd.PersistentFlags().IntVarP(&jobs, "jobs", "j", 1, "Set max concurrent processes")

internal/domain/skip.go internal/skipper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package domain
1+
package internal
22

33
import (
44
"fmt"

internal/domain/skip_test.go internal/skipper_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package domain_test
1+
package internal_test
22

33
import (
44
"path/filepath"
55
"testing"
66

7-
"github.com/danawoodman/cng/internal/domain"
7+
"github.com/danawoodman/cng/internal"
88
"github.com/stretchr/testify/assert"
99
)
1010

11-
func Test(t *testing.T) {
11+
func TestSkipper(t *testing.T) {
1212
tests := []struct {
1313
name string
1414
workDir string
@@ -92,7 +92,7 @@ func Test(t *testing.T) {
9292
for _, e := range test.exclusions {
9393
exclusions = append(exclusions, filepath.Join(test.workDir, e))
9494
}
95-
s := domain.NewSkipper(test.workDir, exclusions)
95+
s := internal.NewSkipper(test.workDir, exclusions)
9696
for path, val := range test.expected {
9797
p := filepath.Join(test.workDir, path)
9898
assert.Equal(t, val, s.ShouldExclude(p), "exclude patterns %v should skip path '%s' but didn't", test.exclusions, path)

internal/watch.go internal/watcher.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import (
1010

1111
"github.com/bmatcuk/doublestar/v4"
1212
"github.com/charmbracelet/log"
13-
"github.com/danawoodman/cng/internal/domain"
1413
"github.com/fsnotify/fsnotify"
1514
)
1615

16+
// todo: inject logging using WithLogger
1717
var logger = log.NewWithOptions(os.Stderr, log.Options{
1818
Prefix: "cng",
1919
})
2020

21-
// todo: inject logging using WithLogger
22-
2321
type WatcherConfig struct {
2422
ExcludePaths []string
2523
Command []string
@@ -35,7 +33,7 @@ type Watcher struct {
3533
cmd *exec.Cmd
3634
lastCmdStart time.Time
3735
log func(msg string, args ...interface{})
38-
skipper domain.Skipper
36+
skipper Skipper
3937
workDir string
4038
}
4139

@@ -53,7 +51,7 @@ func NewWatcher(config WatcherConfig) Watcher {
5351
config: config,
5452
// todo: make this injectable
5553
workDir: workDir,
56-
skipper: domain.NewSkipper(workDir, config.Exclude),
54+
skipper: NewSkipper(workDir, config.Exclude),
5755
log: func(msg string, args ...interface{}) {
5856
if config.Verbose {
5957
logger.Info(msg, args...)
@@ -63,8 +61,6 @@ func NewWatcher(config WatcherConfig) Watcher {
6361
}
6462

6563
func (w Watcher) Start() {
66-
// fmt.Println("WORKING DIRECTORY:", wd)
67-
6864
w.log("Command to run:", "cmd", w.config.Command)
6965
w.log("Watched paths:", "paths", w.config.ExcludePaths)
7066

@@ -77,10 +73,7 @@ func (w Watcher) Start() {
7773
w.log("Adding watched paths:", "paths", w.config.ExcludePaths)
7874
for _, pattern := range w.config.ExcludePaths {
7975
expandedPath := filepath.Join(w.workDir, pattern)
80-
// fmt.Println("EXPANDED PATH:", expandedPath)
81-
8276
rootDir, _ := doublestar.SplitPattern(expandedPath)
83-
// fmt.Println("ROOT DIR:", rootDir)
8477

8578
if err := watcher.Add(rootDir); err != nil {
8679
w.exit("Could not watch root directory:", "dir", rootDir, " error:", err)
@@ -170,11 +163,6 @@ func (w Watcher) Start() {
170163
w.kill()
171164
}
172165

173-
// if event.Op&fsnotify.Create == fsnotify.Create || event.Op&fsnotify.Remove == fsnotify.Remove {
174-
// watcher.Remove(event.Name) // Attempt to remove in case it's deleted
175-
// addFiles() // Re-add files to catch any new/removed files
176-
// }
177-
178166
w.runCmd()
179167

180168
case <-sig:

test/e2e_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ func TestCng(t *testing.T) {
112112
})
113113
}
114114

115-
// List all files in dir:
116-
// files, err := os.ReadDir(dir)
117-
// assert.NoError(t, err)
118-
// for _, file := range files {
119-
// fmt.Println("FILE:", file.Name())
120-
// }
121-
122115
time.Sleep(300 * time.Millisecond)
123116

124117
// Send SIGINT to the process

0 commit comments

Comments
 (0)