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

Skip to content

feat: Automate releases with goreleaser #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2022
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
4 changes: 4 additions & 0 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ jobs:
with:
node-version: "14"

- uses: goreleaser/goreleaser-action@v2
with:
install-only: true

- uses: actions/cache@v2
with:
# Go mod cache, Linux build cache, Mac build cache, Windows build cache
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: release
on:
push:
tags:
- "v*"
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: "^1.17"

- name: Run GoReleaser
uses: goreleaser/[email protected]
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ site/yarn-error.log
coverage/

# Build
bin/
dist/
site/out/
48 changes: 48 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
archives:
- builds:
- coder
files:
- README.md

before:
hooks:
- go mod tidy
- rm -f site/out/bin/coder*

builds:
- id: coder-slim
dir: cmd/coder
flags: [-tags=slim]
ldflags: ["-s -w"]
env: [CGO_ENABLED=0]
goos: [darwin, linux, windows]
goarch: [amd64, arm64]
hooks:
# The "trimprefix" appends ".exe" on Windows.
post: |
cp {{.Path}} site/out/bin/coder_{{ .Os }}_{{ .Arch }}{{ trimprefix .Name "coder" }}
Comment on lines +21 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neato 👍


- id: coder
dir: cmd/coder
ldflags: ["-s -w"]
env: [CGO_ENABLED=0]
goos: [darwin, linux, windows]
goarch: [amd64, arm64]

nfpms:
- vendor: Coder
homepage: https://coder.com
maintainer: Coder <[email protected]>
description: |
Provision development environments with infrastructure with code
formats:
- apk
- deb
- rpm
suggests:
- postgresql
builds:
- coder

release:
ids: [coder]
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@
"drpcmux",
"drpcserver",
"fatih",
"goarch",
"goleak",
"gossh",
"hashicorp",
"httpmw",
"idtoken",
"incpatch",
"isatty",
"Jobf",
"kirsle",
"ldflags",
"manifoldco",
"mattn",
"mitchellh",
"moby",
"nfpms",
"nhooyr",
"nolint",
"nosec",
Expand All @@ -66,6 +70,7 @@
"tcpip",
"tfexec",
"tfstate",
"trimprefix",
"unconvert",
"webrtc",
"xerrors",
Expand Down
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ INSTALL_DIR=$(shell go env GOPATH)/bin
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)

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

bin/coderd:
mkdir -p bin
go build -o bin/coderd cmd/coderd/main.go
.PHONY: bin/coderd

build: site/out bin/coder bin/coderd
build: site/out bin
.PHONY: build

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

install:
install: bin
@echo "--- Copying from bin to $(INSTALL_DIR)"
cp -r ./bin $(INSTALL_DIR)
cp -r ./dist/coder_$(GOOS)_$(GOARCH) $(INSTALL_DIR)
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
.PHONY: install

Expand Down Expand Up @@ -92,4 +86,10 @@ site/out:
./scripts/yarn_install.sh
cd site && yarn build
cd site && yarn export
# Restores GITKEEP files!
git checkout HEAD site/out
.PHONY: site/out

snapshot:
goreleaser release --snapshot --rm-dist
.PHONY: snapshot
6 changes: 3 additions & 3 deletions coderd/cmd/root.go → cli/daemon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package cli

import (
"context"
Expand All @@ -25,12 +25,12 @@ import (
"github.com/coder/coder/provisionersdk/proto"
)

func Root() *cobra.Command {
func daemon() *cobra.Command {
var (
address string
)
root := &cobra.Command{
Use: "coderd",
Use: "daemon",
RunE: func(cmd *cobra.Command, args []string) error {
logger := slog.Make(sloghuman.Sink(os.Stderr))
accessURL := &url.URL{
Expand Down
9 changes: 5 additions & 4 deletions coderd/cmd/root_test.go → cli/daemon_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package cmd_test
package cli_test

import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/cmd"
"github.com/coder/coder/cli/clitest"
)

func TestRoot(t *testing.T) {
func TestDaemon(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
go cancelFunc()
err := cmd.Root().ExecuteContext(ctx)
root, _ := clitest.New(t, "daemon")
err := root.ExecuteContext(ctx)
require.ErrorIs(t, err, context.Canceled)
}
1 change: 1 addition & 0 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Root() *cobra.Command {
`Additional help topics:`, header.Sprint("Additional help:"),
).Replace(cmd.UsageTemplate()))

cmd.AddCommand(daemon())
cmd.AddCommand(login())
cmd.AddCommand(projects())
cmd.AddCommand(workspaces())
Expand Down
16 changes: 0 additions & 16 deletions cmd/coderd/main.go

This file was deleted.

7 changes: 1 addition & 6 deletions develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ function create_initial_user() {
# Run yarn install, to make sure node_modules are ready to go
"$PROJECT_ROOT/scripts/yarn_install.sh"

# Do initial build - a dev build for coderd.
# It's OK that we don't build the front-end before - because the front-end
# assets are handled by the `yarn dev` devserver.
make bin/coderd

# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly
# to kill both at the same time. For more details, see:
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
(
trap 'kill 0' SIGINT
create_initial_user &
CODERV2_HOST=http://127.0.0.1:3000 yarn --cwd=./site dev &
./bin/coderd
go run cmd/coder/main.go daemon
)
18 changes: 0 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ require (
github.com/hashicorp/terraform-config-inspect v0.0.0-20211115214459-90acf1ca460f
github.com/hashicorp/terraform-exec v0.15.0
github.com/hashicorp/terraform-json v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87
github.com/justinas/nosurf v1.1.1
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
Expand Down Expand Up @@ -96,34 +95,18 @@ require (
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.1 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/hc-install v0.3.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.5.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.2.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/juju/ansiterm v0.0.0-20210929141451-8b71cc96ebdc // indirect
github.com/klauspost/compress v1.14.3 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.1.0 // indirect
Expand All @@ -144,7 +127,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
Expand Down
Loading