Skip to content

Commit b12e789

Browse files
feat!: Faster goreleaser (#107)
1 parent 54c7ed5 commit b12e789

File tree

3 files changed

+195
-27
lines changed

3 files changed

+195
-27
lines changed

.circleci/test-deploy.yml

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,79 @@ release-filters: &release-filters
1313
tags:
1414
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
1515

16+
executors:
17+
alpine:
18+
resource_class: medium
19+
docker:
20+
- image: alpine:latest
21+
go:
22+
resource_class: medium
23+
docker:
24+
- image: cimg/go:1.23
25+
go_arm:
26+
resource_class: arm.medium
27+
docker:
28+
- image: cimg/go:1.23
29+
mac:
30+
resource_class: m2pro.medium
31+
macos:
32+
xcode: "16.2.0"
33+
ubuntu_machine:
34+
resource_class: medium
35+
machine:
36+
image: ubuntu-2204:current
37+
ubuntu_machine_arm:
38+
resource_class: arm.medium
39+
machine:
40+
image: ubuntu-2204:current
41+
win2022_bash:
42+
resource_class: windows.medium
43+
machine:
44+
image: windows-server-2022-gui:2024.12.1
45+
shell: bash.exe
46+
win2022_cmd:
47+
resource_class: windows.medium
48+
machine:
49+
image: windows-server-2022-gui:2024.12.1
50+
shell: cmd.exe
51+
win2022_powershell:
52+
resource_class: windows.medium
53+
machine:
54+
image: windows-server-2022-gui:2024.12.1
55+
shell: powershell.exe
56+
57+
commands:
58+
alpine_install_curl:
59+
steps:
60+
- run:
61+
name: Alpine install curl
62+
command: apk add --no-cache curl
63+
1664
jobs:
1765
int-test-goreleaser-install:
18-
executor:
19-
name: go/default
20-
tag: "1.23"
66+
executor: << parameters.executor >>
67+
parameters:
68+
executor:
69+
type: executor
2170
steps:
2271
- go/install-goreleaser
72+
- run:
73+
name: Goreleaser version (testing path)
74+
command: goreleaser --version
75+
int-test-goreleaser-install-alpine:
76+
executor: alpine
77+
steps:
78+
- alpine_install_curl
79+
- go/install-goreleaser:
80+
shell: sh
81+
int-test-goreleaser-install-pinned-version:
82+
executor: ubuntu_machine
83+
steps:
84+
- go/install-goreleaser:
85+
version: v1.26.2
86+
- run:
87+
name: Goreleaser version check
88+
command: goreleaser --version | grep "1.26.2"
2389
int-test-goreleaser-release:
2490
executor:
2591
name: go/default
@@ -71,18 +137,16 @@ jobs:
71137
name: "Check if the correct python version is accessible & installed"
72138
command: python --version | grep -q "^Python 3.11"
73139
int-test-alpine:
74-
docker:
75-
- image: alpine:latest
140+
executor: alpine
76141
steps:
77-
- run: apk add curl
142+
- alpine_install_curl
78143
- go/install:
79144
version: 1.17.2
80145
- run:
81146
name: "Check if the correct go version is accessible & installed"
82147
command: go version | grep -q "1.17.2"
83148
int-test-macos-executor:
84-
macos:
85-
xcode: "14.1.0"
149+
executor: mac
86150
steps:
87151
- run:
88152
name: "Check out sample project."
@@ -96,8 +160,7 @@ jobs:
96160
- go/mod-download
97161
- run: go version && go build ./...
98162
int-test-vm-linux:
99-
machine:
100-
image: ubuntu-2004:current
163+
executor: ubuntu_machine
101164
steps:
102165
- run:
103166
name: "Check out sample project."
@@ -112,9 +175,7 @@ jobs:
112175
- go/mod-download
113176
- run: go version && go build ./...
114177
int-test-vm-arm64:
115-
machine:
116-
image: ubuntu-2204:current
117-
resource_class: arm.medium
178+
executor: ubuntu_machine_arm
118179
steps:
119180
- run:
120181
name: "Check out sample project."
@@ -130,8 +191,7 @@ jobs:
130191
- run: go version && go build ./...
131192
# test to make sure the dirty cache issue doesn't crop back up
132193
int-test-dirty-cache:
133-
machine:
134-
image: ubuntu-2004:current
194+
executor: ubuntu_machine
135195
steps:
136196
- run:
137197
name: "Check out sample project."
@@ -148,6 +208,9 @@ jobs:
148208
version: 1.16.4
149209
- run: go version && go build ./...
150210
go-test-default:
211+
executor:
212+
name: go/default
213+
tag: "1.23"
151214
docker:
152215
- image: cimg/go:1.23.3
153216
steps:
@@ -165,8 +228,9 @@ jobs:
165228
- store_test_results:
166229
path: /home/circleci/project/tests
167230
int-test-gotestsum-2-test:
168-
docker:
169-
- image: cimg/go:1.23.3
231+
executor:
232+
name: go/default
233+
tag: "1.23"
170234
steps:
171235
- checkout
172236
- go/gotestsum:
@@ -188,6 +252,15 @@ workflows:
188252
jobs:
189253
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
190254
- int-test-goreleaser-install:
255+
name: int-test-goreleaser-install-<< matrix.executor >>
256+
filters: *filters
257+
matrix:
258+
alias: int-test-goreleaser-install
259+
parameters:
260+
executor: [go, go_arm, mac, ubuntu_machine, ubuntu_machine_arm, win2022_bash, win2022_cmd, win2022_powershell]
261+
- int-test-goreleaser-install-alpine:
262+
filters: *filters
263+
- int-test-goreleaser-install-pinned-version:
191264
filters: *filters
192265
- int-test-goreleaser-release:
193266
pre-steps:
@@ -238,6 +311,8 @@ workflows:
238311
- int-test-dirty-cache
239312
- int-test-vm-arm64
240313
- int-test-goreleaser-install
314+
- int-test-goreleaser-install-alpine
315+
- int-test-goreleaser-install-pinned-version
241316
- int-test-goreleaser-release
242317
context: orb-publisher
243318
filters: *release-filters
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
description: |
2-
GoReleaser is a release automation tool for managing Go projects.
3-
Install GoReleaser in your build. Golang must be installed.
1+
---
2+
description: >
3+
Install goreleaser
44
55
parameters:
6+
shell:
7+
type: string
8+
default: "bash"
9+
description: >
10+
The shell to use for running the script, windows should be bash but alpine may be sh.
611
version:
7-
description: The GoReleaser version to install. Defaults to latest
812
type: string
9-
default: "latest"
13+
default: ""
14+
description: >
15+
The version of goreleaser to install. If not specified, the latest version will be installed.
1016
1117
steps:
1218
- run:
13-
name: "Installing GoReleaser"
19+
name: Install goreleaser
1420
environment:
1521
GO_STR_VERSION: << parameters.version >>
1622
command: << include(scripts/install-goreleaser.sh) >>
17-
23+
shell: << parameters.shell >>

src/scripts/install-goreleaser.sh

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,93 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
GO_STR_VERSION="$(echo "${GO_STR_VERSION}"| circleci env subst)"
3+
set -euo pipefail
4+
5+
function get_os() {
6+
local os
7+
os=$(uname -o)
8+
case "$os" in
9+
GNU/Linux) echo "Linux" ;;
10+
Linux) echo "Linux" ;;
11+
Msys) echo "Windows" ;;
12+
Darwin) echo "Darwin" ;;
13+
*) echo "Unsupported OS: $os" ; exit 1;;
14+
esac
15+
}
16+
17+
function get_architecture() {
18+
local arch
19+
arch=$(uname -m)
20+
case "$arch" in
21+
aarch64) echo "arm64" ;;
22+
arm64) echo "arm64" ;;
23+
x86_64) echo "x86_64" ;;
24+
*) echo "Unsupported architecture: $arch" ; exit 1;;
25+
esac
26+
}
27+
28+
download_goreleaser() {
29+
echo "Downloading goreleaser for ${architecture}..."
30+
if ! which curl &>/dev/null; then
31+
echo "curl is not installed. Please install curl and try again."
32+
exit 1
33+
fi
34+
if [ -z "${GO_STR_VERSION:-}" ]; then
35+
# Taken from https://goreleaser.com/install/#bash-script
36+
GO_STR_VERSION="$(curl -sf https://goreleaser.com/static/latest)"
37+
fi
38+
URL="https://github.com/goreleaser/goreleaser/releases/download/${GO_STR_VERSION}/goreleaser_${os}_${architecture}.${file_extension}"
39+
echo "Downloading goreleaser from ${URL}"
40+
if ! curl --location "${URL}" --output "${TMP_FILE}" &>/dev/null; then
41+
echo "Failed to download goreleaser"
42+
exit 1
43+
fi
44+
}
45+
46+
extract_goreleaser_win() {
47+
echo "Running on Windows, using unzip to extract..."
48+
mkdir --parent "${HOME}/go/bin"
49+
if ! unzip -n /tmp/goreleaser.zip -d "${HOME}/go/bin" goreleaser.exe; then
50+
echo "Failed to extract goreleaser"
51+
exit 1
52+
fi
53+
}
54+
55+
extract_goreleaser_nix() {
56+
echo "Running on Linux, Attempting to extract to /usr/local/bin..."
57+
if ! tar -xvzf "${TMP_FILE}" -C /usr/local/bin goreleaser ; then
58+
echo "Failed to extract goreleaser to /usr/local/bin with normal privileges, trying with sudo..."
59+
if ! sudo tar -xvzf "${TMP_FILE}" -C /usr/local/bin goreleaser; then
60+
echo "Failed to extract goreleaser"
61+
exit 1
62+
fi
63+
fi
64+
}
65+
66+
extract_goreleaser() {
67+
architecture="$(get_architecture)"
68+
os="$(get_os)"
69+
if [[ "${os}" == "Windows" ]]; then
70+
extract_goreleaser_win
71+
else
72+
extract_goreleaser_nix
73+
fi
74+
}
75+
76+
if ! which goreleaser &>/dev/null; then
77+
echo "Installing goreleaser..."
78+
architecture="$(get_architecture)"
79+
os="$(get_os)"
80+
if [[ "${os}" == "Windows" ]]; then
81+
file_extension="zip"
82+
else
83+
file_extension="tar.gz"
84+
fi
85+
TMP_FILE="/tmp/goreleaser.${file_extension}"
86+
download_goreleaser
87+
extract_goreleaser
88+
else
89+
echo "goreleaser is already installed. Exiting..."
90+
exit 0
91+
fi
492

5-
go install github.com/goreleaser/goreleaser/v2@"${GO_STR_VERSION}"
693
goreleaser --version

0 commit comments

Comments
 (0)