Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3eb6fb7

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

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/[email protected]
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 <[email protected]>
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.

develop.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@ function create_initial_user() {
2424
# Run yarn install, to make sure node_modules are ready to go
2525
"$PROJECT_ROOT/scripts/yarn_install.sh"
2626

27-
# Do initial build - a dev build for coderd.
28-
# It's OK that we don't build the front-end before - because the front-end
29-
# assets are handled by the `yarn dev` devserver.
30-
make bin/coderd
31-
3227
# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly
3328
# to kill both at the same time. For more details, see:
3429
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
3530
(
3631
trap 'kill 0' SIGINT
3732
create_initial_user &
3833
CODERV2_HOST=http://127.0.0.1:3000 yarn --cwd=./site dev &
39-
./bin/coderd
34+
go run cmd/coder/main.go daemon
4035
)

go.mod

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ require (
3535
github.com/hashicorp/terraform-config-inspect v0.0.0-20211115214459-90acf1ca460f
3636
github.com/hashicorp/terraform-exec v0.15.0
3737
github.com/hashicorp/terraform-json v0.13.0
38-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
3938
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87
4039
github.com/justinas/nosurf v1.1.1
4140
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
@@ -96,34 +95,18 @@ require (
9695
github.com/google/go-cmp v0.5.7 // indirect
9796
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
9897
github.com/hashicorp/errwrap v1.1.0 // indirect
99-
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
100-
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
101-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
102-
github.com/hashicorp/go-hclog v1.0.0 // indirect
10398
github.com/hashicorp/go-multierror v1.1.1 // indirect
104-
github.com/hashicorp/go-plugin v1.4.1 // indirect
105-
github.com/hashicorp/go-uuid v1.0.2 // indirect
106-
github.com/hashicorp/hc-install v0.3.1 // indirect
10799
github.com/hashicorp/hcl v1.0.0 // indirect
108100
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
109-
github.com/hashicorp/logutils v1.0.0 // indirect
110-
github.com/hashicorp/terraform-plugin-go v0.5.0 // indirect
111-
github.com/hashicorp/terraform-plugin-log v0.2.0 // indirect
112-
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect
113-
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
114101
github.com/imdario/mergo v0.3.12 // indirect
115102
github.com/inconshreveable/mousetrap v1.0.0 // indirect
116103
github.com/juju/ansiterm v0.0.0-20210929141451-8b71cc96ebdc // indirect
117104
github.com/klauspost/compress v1.14.3 // indirect
118105
github.com/leodido/go-urn v1.2.1 // indirect
119106
github.com/lunixbochs/vtclean v1.0.0 // indirect
120107
github.com/mattn/go-colorable v0.1.12 // indirect
121-
github.com/mitchellh/copystructure v1.2.0 // indirect
122-
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
123108
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
124-
github.com/mitchellh/reflectwalk v1.0.2 // indirect
125109
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
126-
github.com/oklog/run v1.0.0 // indirect
127110
github.com/opencontainers/go-digest v1.0.0 // indirect
128111
github.com/opencontainers/image-spec v1.0.2 // indirect
129112
github.com/opencontainers/runc v1.1.0 // indirect
@@ -144,7 +127,6 @@ require (
144127
github.com/pmezard/go-difflib v1.0.0 // indirect
145128
github.com/sirupsen/logrus v1.8.1 // indirect
146129
github.com/spf13/pflag v1.0.5 // indirect
147-
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
148130
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
149131
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
150132
github.com/xeipuuv/gojsonschema v1.2.0 // indirect

0 commit comments

Comments
 (0)