Skip to content

Commit

Permalink
Use GoReleaser to generate binaries and make releases (#3)
Browse files Browse the repository at this point in the history
* Use GoReleaser to generate binaries and make releases

* .golangci.yml: ignore "gochecknoglobals" linter for internal/version/

* .golangci.yml: ignore "gochecknoinits" linter for internal/version/
  • Loading branch information
edigaryev authored Jun 28, 2024
1 parent 49456c5 commit 775d4d8
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
container:
image: golang:latest

docker_builder:
name: Test
install_golang_script:
Expand All @@ -8,3 +11,41 @@ docker_builder:
- go test -v ./...
env:
HOME: /root

task:
name: Release (Dry Run)
only_if: $CIRRUS_TAG == ''
env:
MACOS_SIGN_P12: ENCRYPTED[!183482723ca1a95f9c4439f7a79c9d3b115472bb18c739ed1586e12d3914ccf94ade8169eeda7332fc204f8be9c27d9f!]
MACOS_SIGN_PASSWORD: ENCRYPTED[!417423346c567f12007f42d084bff1cfee30ee14f7e8258550157679a269c70d541c9f19224224ab0293b10f2c6d4c5e!]
MACOS_NOTARY_ISSUER_ID: ENCRYPTED[!74076906e9fa36bca3c1da1637b0759b58bb009eb1a707446896eefad3767e8dba1d0f87e71106b98cde98ac4b037a2a!]
MACOS_NOTARY_KEY_ID: ENCRYPTED[!af9e5da1010a6b04e548ef494acc77a6e0ce176549de98f81c5b5cdd72856de09f77e51cf0849e3c4b7a2d2c22f25ca8!]
MACOS_NOTARY_KEY: ENCRYPTED[!c70c53f3e6c163931c7cdf9d90aff8934ef21d5dd1090158688e00b94e97c68257d9cf4ae1df873e6ae0d949866aee72!]
GITHUB_TOKEN: ENCRYPTED[!98ace8259c6024da912c14d5a3c5c6aac186890a8d4819fad78f3e0c41a4e0cd3a2537dd6e91493952fb056fa434be7c!]
FURY_TOKEN: ENCRYPTED[!97fe4497d9aca60a3d64904883b81e21f19706c6aedda625c97f62f67ec46b8efa74c55699956158bbf0a23726e7d9f6!]
GORELEASER_KEY: ENCRYPTED[!9b80b6ef684ceaf40edd4c7af93014ee156c8aba7e6e5795f41c482729887b5c31f36b651491d790f1f668670888d9fd!]
install_script:
- echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list
- apt-get update
- apt-get -y install goreleaser-pro
release_script: goreleaser release --skip=publish --snapshot --clean --verbose
binaries_artifacts:
path: "dist/chacha_*/chacha*"

task:
name: Release
only_if: $CIRRUS_TAG != ''
env:
MACOS_SIGN_P12: ENCRYPTED[!183482723ca1a95f9c4439f7a79c9d3b115472bb18c739ed1586e12d3914ccf94ade8169eeda7332fc204f8be9c27d9f!]
MACOS_SIGN_PASSWORD: ENCRYPTED[!417423346c567f12007f42d084bff1cfee30ee14f7e8258550157679a269c70d541c9f19224224ab0293b10f2c6d4c5e!]
MACOS_NOTARY_ISSUER_ID: ENCRYPTED[!74076906e9fa36bca3c1da1637b0759b58bb009eb1a707446896eefad3767e8dba1d0f87e71106b98cde98ac4b037a2a!]
MACOS_NOTARY_KEY_ID: ENCRYPTED[!af9e5da1010a6b04e548ef494acc77a6e0ce176549de98f81c5b5cdd72856de09f77e51cf0849e3c4b7a2d2c22f25ca8!]
MACOS_NOTARY_KEY: ENCRYPTED[!c70c53f3e6c163931c7cdf9d90aff8934ef21d5dd1090158688e00b94e97c68257d9cf4ae1df873e6ae0d949866aee72!]
GITHUB_TOKEN: ENCRYPTED[!98ace8259c6024da912c14d5a3c5c6aac186890a8d4819fad78f3e0c41a4e0cd3a2537dd6e91493952fb056fa434be7c!]
FURY_TOKEN: ENCRYPTED[!97fe4497d9aca60a3d64904883b81e21f19706c6aedda625c97f62f67ec46b8efa74c55699956158bbf0a23726e7d9f6!]
GORELEASER_KEY: ENCRYPTED[!9b80b6ef684ceaf40edd4c7af93014ee156c8aba7e6e5795f41c482729887b5c31f36b651491d790f1f668670888d9fd!]
install_script:
- echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list
- apt-get update
- apt-get -y install goreleaser-pro
release_script: goreleaser
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ issues:
linters:
# It's OK to use global variables for github.com/spf13/cobra commands
- gochecknoglobals
- path: internal/version/
linters:
# It's OK to use global variables for automatically settings versions through GoReleaser
- gochecknoglobals
# It's OK to use an init() function to automatically calculate the FullVersion, which needs
# to be a variable
- gochecknoinits
- path: internal/server/server_test.go
linters:
- noctx
65 changes: 65 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
project_name: chacha

before:
hooks:
- go mod download

builds:
- main: cmd/main.go
ldflags: >
-X github.com/cirruslabs/chacha/internal/version.Version={{.Version}}
-X github.com/cirruslabs/chacha/internal/version.Commit={{.ShortCommit}}
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64

archives:
- id: binary
format: binary
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
- id: regular
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"

release:
prerelease: auto

brews:
- name: chacha
ids:
- regular
repository:
owner: cirruslabs
name: homebrew-cli
license: FSL-1.1-Apache-2.0
caveats: See the Github repository for more information

nfpms:
- package_name: chacha
vendor: Cirrus Labs, Inc.
homepage: https://github.com/cirruslabs/chacha
maintainer: support@cirruslabs.org
description: Caching proxy for Cirrus Runners
license: FSL-1.1-Apache-2.0
section: misc
formats:
- deb
- rpm

furies:
- account: cirruslabs

notarize:
macos:
- enabled: '{{ isEnvSet "MACOS_SIGN_P12" }}'
sign:
certificate: "{{.Env.MACOS_SIGN_P12}}"
password: "{{.Env.MACOS_SIGN_PASSWORD}}"
notarize:
issuer_id: "{{.Env.MACOS_NOTARY_ISSUER_ID}}"
key_id: "{{.Env.MACOS_NOTARY_KEY_ID}}"
key: "{{.Env.MACOS_NOTARY_KEY}}"
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/go-jose/go-jose/v4 v4.0.2
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.7.0
github.com/labstack/echo/v4 v4.12.0
github.com/oauth2-proxy/mockoidc v0.0.0-20240214162133-caebfff84d25
github.com/puzpuzpuz/xsync/v3 v3.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
2 changes: 2 additions & 0 deletions internal/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"github.com/cirruslabs/chacha/internal/command/run"
"github.com/cirruslabs/chacha/internal/logginglevel"
"github.com/cirruslabs/chacha/internal/version"
"github.com/spf13/cobra"
"go.uber.org/zap/zapcore"
)
Expand All @@ -13,6 +14,7 @@ func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "chacha",
Short: "Caching proxy server for Cirrus Runners infrastructure",
Version: version.FullVersion,
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
Expand Down
32 changes: 32 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package version

import (
"fmt"
goversion "github.com/hashicorp/go-version"
"runtime/debug"
)

var (
Version = "unknown"
Commit = "unknown"
FullVersion = ""
)

func init() {
if Version == "unknown" {
info, ok := debug.ReadBuildInfo()
if ok {
// We parse the version here for two reasons:
// * to weed out the "(devel)" version and fallback to "unknown" instead
// (see https://github.com/golang/go/issues/29228 for details on when this might happen)
// * to remove the "v" prefix from the BuildInfo's version (e.g. "v0.7.0") and thus be consistent
// with the binary builds, where the version string would be "0.7.0" instead
semver, err := goversion.NewSemver(info.Main.Version)
if err == nil {
Version = semver.String()
}
}
}

FullVersion = fmt.Sprintf("%s-%s", Version, Commit)
}

0 comments on commit 775d4d8

Please sign in to comment.