Skip to content

Commit 3eb6fb7

Browse files
authored
feat: Automate releases with goreleaser (#404)
1 parent e1205a0 commit 3eb6fb7

File tree

18 files changed

+126
-115
lines changed

18 files changed

+126
-115
lines changed

.github/workflows/coder.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ jobs:
323323
with:
324324
node-version: "14"
325325

326+
- uses: goreleaser/goreleaser-action@v2
327+
with:
328+
install-only: true
329+
326330
- uses: actions/cache@v2
327331
with:
328332
# Go mod cache, Linux build cache, Mac build cache, Windows build cache

.github/workflows/release.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
goreleaser:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
fetch-depth: 0
13+
- uses: actions/setup-go@v2
14+
with:
15+
go-version: "^1.17"
16+
17+
- name: Run GoReleaser
18+
uses: goreleaser/goreleaser-action@v2.9.1
19+
with:
20+
version: latest
21+
args: release --rm-dist
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ site/yarn-error.log
2525
coverage/
2626

2727
# Build
28-
bin/
28+
dist/
2929
site/out/

.goreleaser.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
archives:
2+
- builds:
3+
- coder
4+
files:
5+
- README.md
6+
7+
before:
8+
hooks:
9+
- go mod tidy
10+
- rm -f site/out/bin/coder*
11+
12+
builds:
13+
- id: coder-slim
14+
dir: cmd/coder
15+
flags: [-tags=slim]
16+
ldflags: ["-s -w"]
17+
env: [CGO_ENABLED=0]
18+
goos: [darwin, linux, windows]
19+
goarch: [amd64, arm64]
20+
hooks:
21+
# The "trimprefix" appends ".exe" on Windows.
22+
post: |
23+
cp {{.Path}} site/out/bin/coder_{{ .Os }}_{{ .Arch }}{{ trimprefix .Name "coder" }}
24+
25+
- id: coder
26+
dir: cmd/coder
27+
ldflags: ["-s -w"]
28+
env: [CGO_ENABLED=0]
29+
goos: [darwin, linux, windows]
30+
goarch: [amd64, arm64]
31+
32+
nfpms:
33+
- vendor: Coder
34+
homepage: https://coder.com
35+
maintainer: Coder <support@coder.com>
36+
description: |
37+
Provision development environments with infrastructure with code
38+
formats:
39+
- apk
40+
- deb
41+
- rpm
42+
suggests:
43+
- postgresql
44+
builds:
45+
- coder
46+
47+
release:
48+
ids: [coder]

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@
3535
"drpcmux",
3636
"drpcserver",
3737
"fatih",
38+
"goarch",
3839
"goleak",
3940
"gossh",
4041
"hashicorp",
4142
"httpmw",
4243
"idtoken",
44+
"incpatch",
4345
"isatty",
4446
"Jobf",
4547
"kirsle",
48+
"ldflags",
4649
"manifoldco",
4750
"mattn",
4851
"mitchellh",
4952
"moby",
53+
"nfpms",
5054
"nhooyr",
5155
"nolint",
5256
"nosec",
@@ -66,6 +70,7 @@
6670
"tcpip",
6771
"tfexec",
6872
"tfstate",
73+
"trimprefix",
6974
"unconvert",
7075
"webrtc",
7176
"xerrors",

Makefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ INSTALL_DIR=$(shell go env GOPATH)/bin
22
GOOS=$(shell go env GOOS)
33
GOARCH=$(shell go env GOARCH)
44

5-
bin/coder:
6-
mkdir -p bin
7-
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o bin/coder-$(GOOS)-$(GOARCH) cmd/coder/main.go
8-
.PHONY: bin/coder
5+
bin:
6+
goreleaser build --single-target --snapshot --rm-dist
7+
.PHONY: bin
98

10-
bin/coderd:
11-
mkdir -p bin
12-
go build -o bin/coderd cmd/coderd/main.go
13-
.PHONY: bin/coderd
14-
15-
build: site/out bin/coder bin/coderd
9+
build: site/out bin
1610
.PHONY: build
1711

1812
# Runs migrations to output a dump of the database.
@@ -55,9 +49,9 @@ fmt: fmt/prettier fmt/sql
5549
gen: database/generate peerbroker/proto provisionersdk/proto provisionerd/proto
5650
.PHONY: gen
5751

58-
install:
52+
install: bin
5953
@echo "--- Copying from bin to $(INSTALL_DIR)"
60-
cp -r ./bin $(INSTALL_DIR)
54+
cp -r ./dist/coder_$(GOOS)_$(GOARCH) $(INSTALL_DIR)
6155
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
6256
.PHONY: install
6357

@@ -92,4 +86,10 @@ site/out:
9286
./scripts/yarn_install.sh
9387
cd site && yarn build
9488
cd site && yarn export
89+
# Restores GITKEEP files!
90+
git checkout HEAD site/out
9591
.PHONY: site/out
92+
93+
snapshot:
94+
goreleaser release --snapshot --rm-dist
95+
.PHONY: snapshot

coderd/cmd/root.go renamed to cli/daemon.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package cli
22

33
import (
44
"context"
@@ -25,12 +25,12 @@ import (
2525
"github.com/coder/coder/provisionersdk/proto"
2626
)
2727

28-
func Root() *cobra.Command {
28+
func daemon() *cobra.Command {
2929
var (
3030
address string
3131
)
3232
root := &cobra.Command{
33-
Use: "coderd",
33+
Use: "daemon",
3434
RunE: func(cmd *cobra.Command, args []string) error {
3535
logger := slog.Make(sloghuman.Sink(os.Stderr))
3636
accessURL := &url.URL{
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
package cmd_test
1+
package cli_test
22

33
import (
44
"context"
55
"testing"
66

77
"github.com/stretchr/testify/require"
88

9-
"github.com/coder/coder/coderd/cmd"
9+
"github.com/coder/coder/cli/clitest"
1010
)
1111

12-
func TestRoot(t *testing.T) {
12+
func TestDaemon(t *testing.T) {
1313
t.Parallel()
1414
ctx, cancelFunc := context.WithCancel(context.Background())
1515
go cancelFunc()
16-
err := cmd.Root().ExecuteContext(ctx)
16+
root, _ := clitest.New(t, "daemon")
17+
err := root.ExecuteContext(ctx)
1718
require.ErrorIs(t, err, context.Canceled)
1819
}

cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func Root() *cobra.Command {
6464
`Additional help topics:`, header.Sprint("Additional help:"),
6565
).Replace(cmd.UsageTemplate()))
6666

67+
cmd.AddCommand(daemon())
6768
cmd.AddCommand(login())
6869
cmd.AddCommand(projects())
6970
cmd.AddCommand(workspaces())

cmd/coderd/main.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)