Skip to content

Commit 56d8c20

Browse files
authored
build: package for apple intel and apple silicon machines alongside universal binaries as fallback (#101)
1 parent 855440a commit 56d8c20

8 files changed

Lines changed: 177 additions & 99 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ workflows:
609609
<<: *filters-tag-triggered-workflow-job
610610
name: upload-to-s3-for-install-macOS-feature-build
611611
s3-target-path: slack-cli
612-
file-name: "slack_cli_*feature_macOS_64-bit.tar.gz"
612+
file-name: "slack_cli_*feature_macOS_*.tar.gz"
613613
requires:
614614
- create-github-release-and-artifacts
615615
context: slack-cli-release
@@ -657,7 +657,7 @@ workflows:
657657
<<: *filters-tag-triggered-workflow-job
658658
name: upload-to-s3-for-autoupdate-macos
659659
s3-target-path: slack-cli
660-
file-name: "slack_cli_*_macOS_64-bit.zip"
660+
file-name: "slack_cli_*_macOS_*.zip"
661661
requires:
662662
- create-github-release-and-artifacts
663663
context: slack-cli-release
@@ -685,11 +685,3 @@ workflows:
685685
requires:
686686
- create-github-release-and-artifacts
687687
context: slack-cli-release
688-
- s3-upload:
689-
<<: *filters-tag-triggered-workflow-job
690-
name: upload-to-s3-for-hermes
691-
s3-target-path: cli
692-
file-name: "hermes_*"
693-
requires:
694-
- create-github-release-and-artifacts
695-
context: slack-cli-release

.github/MAINTAINERS_GUIDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ The [`goreleaser`][goreleaser] package we use to build release snapshots needs
568568
updates in the following files on occasion:
569569

570570
- `.circleci/config.yml`
571-
- `.goreleaser-dev.yml`
572571
- `.goreleaser.yml`
573572

574573
Testing in our CI setup uses changes to these files when creating test builds.

.goreleaser-dev.yml

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

.goreleaser.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,23 @@ builds:
4141
- darwin
4242
goarch:
4343
- amd64
44+
- arm64
4445
hooks:
4546
post: |-
4647
sh -c '
47-
zip ./dist/slack_cli_{{.Env.BUILD_VERSION}}_macOS_64-bit.zip ./dist/slack-macos_darwin_amd64_v1/bin/slack -j
48+
zip ./dist/slack_cli_{{ .Env.BUILD_VERSION }}_macOS_{{ .Arch }}.zip ./dist/slack-macos_{{ .Target }}/bin/slack -j
4849
'
50+
51+
universal_binaries:
52+
- id: slack-macos
53+
name_template: bin/slack
54+
replace: false
55+
hooks:
56+
post: |-
57+
sh -c '
58+
zip ./dist/slack_cli_{{.Env.BUILD_VERSION}}_macOS_64-bit.zip ./dist/slack-macos_darwin_all/bin/slack -j
59+
'
60+
4961
archives:
5062
- id: slack
5163
ids:
@@ -60,11 +72,11 @@ archives:
6072
name_template: >-
6173
{{- .ProjectName }}_
6274
{{- .Env.BUILD_VERSION }}_
63-
{{- if eq .Os "darwin" }}macOS
64-
{{- else }}{{ .Os }}{{ end }}_
65-
{{- if eq .Arch "amd64" }}64-bit
66-
{{- else if eq .Arch "386" }}32-bit
67-
{{- else }}{{ .Arch }}{{ end }}
75+
{{- if eq .Os "darwin" -}}
76+
macOS_{{ if eq .Arch "all" }}64-bit{{ else }}{{ .Arch }}{{ end }}
77+
{{- else -}}
78+
{{ .Os }}_{{ if eq .Arch "amd64" }}64-bit{{ else }}{{ .Arch }}{{ end }}
79+
{{- end }}
6880
6981
snapshot:
7082
version_template: "{{ .Env.BUILD_VERSION }}"

internal/update/cli_autoupdate.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func (c *CLIDependency) InstallUpdate(ctx context.Context) error {
5959

6060
architecture := runtime.GOARCH
6161
operatingSys := runtime.GOOS
62-
c.clients.IO.PrintDebug(ctx, "Architecture: %s \nOS: %s", architecture, operatingSys)
63-
fileName, err := getUpdateFileName(c.releaseInfo.Version, operatingSys)
62+
c.clients.IO.PrintDebug(ctx, "Architecture: %s\nOS: %s", architecture, operatingSys)
63+
fileName, err := getUpdateFileName(c.releaseInfo.Version, operatingSys, architecture)
6464
if err != nil {
6565
return err
6666
}
@@ -245,19 +245,27 @@ func restoreBinary(updatedBinaryFolderPath string, newPathToOldBinary string, or
245245
return nil
246246
}
247247

248-
// getUpdateFilename returns name of the archive that contains the upgrade for the given version and OS
249-
func getUpdateFileName(version, operatingSys string) (filename string, err error) {
250-
// You can get a list of all possible OS/architecture combinations with `go tool dist list | column -c 75 | column -t`
251-
// TODO: account for architecture as well. M1 macs would have an arch of arm64 instead of the usual amd64
252-
const binaryName = "slack_cli"
253-
const architecture = "64-bit"
248+
// getUpdateFilename returns name of the archive that contains the upgrade for
249+
// the given version and OS.
250+
//
251+
// All possible OS/architecture combinations can be listed with the command:
252+
//
253+
// go tool dist list | column -c 75 | column -t
254+
func getUpdateFileName(version, operatingSys, architecture string) (filename string, err error) {
254255
switch operatingSys {
255256
case "darwin":
256-
filename = fmt.Sprintf("%s_%s_macOS_%s.zip", binaryName, version, architecture)
257+
switch architecture {
258+
case "amd64":
259+
filename = fmt.Sprintf("slack_cli_%s_macOS_amd64.zip", version)
260+
case "arm64":
261+
filename = fmt.Sprintf("slack_cli_%s_macOS_arm64.zip", version)
262+
default:
263+
filename = fmt.Sprintf("slack_cli_%s_macOS_64-bit.zip", version)
264+
}
257265
case "linux":
258-
filename = fmt.Sprintf("%s_%s_linux_%s.tar.gz", binaryName, version, architecture)
266+
filename = fmt.Sprintf("slack_cli_%s_linux_64-bit.tar.gz", version)
259267
case "windows":
260-
filename = fmt.Sprintf("%s_%s_windows_%s.zip", binaryName, version, architecture)
268+
filename = fmt.Sprintf("slack_cli_%s_windows_64-bit.zip", version)
261269
default:
262270
err = slackerror.New(fmt.Sprintf("auto-updating for the operating system (%s) is unsupported", operatingSys))
263271
err = slackerror.Wrapf(err, slackerror.ErrCLIAutoUpdate)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2022-2025 Salesforce, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package update
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/require"
21+
)
22+
23+
func Test_CLI_getUpdateFileName(t *testing.T) {
24+
tests := map[string]struct {
25+
version string
26+
operatingSystem string
27+
architecture string
28+
expectedFilename string
29+
expectedErrorF string
30+
}{
31+
"darwin production x86_64": {
32+
version: "3.4.5",
33+
operatingSystem: "darwin",
34+
architecture: "amd64",
35+
expectedFilename: "slack_cli_3.4.5_macOS_amd64.zip",
36+
},
37+
"darwin development x86_64": {
38+
version: "3.4.5-6-badaabad",
39+
operatingSystem: "darwin",
40+
architecture: "amd64",
41+
expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_amd64.zip",
42+
},
43+
"darwin production aarch64": {
44+
version: "3.4.5",
45+
operatingSystem: "darwin",
46+
architecture: "arm64",
47+
expectedFilename: "slack_cli_3.4.5_macOS_arm64.zip",
48+
},
49+
"darwin development aarch64": {
50+
version: "3.4.5-6-badaabad",
51+
operatingSystem: "darwin",
52+
architecture: "arm64",
53+
expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_arm64.zip",
54+
},
55+
"darwin production universal": {
56+
version: "3.4.5",
57+
operatingSystem: "darwin",
58+
architecture: "fallback",
59+
expectedFilename: "slack_cli_3.4.5_macOS_64-bit.zip",
60+
},
61+
"darwin development universal": {
62+
version: "3.4.5-6-badaabad",
63+
operatingSystem: "darwin",
64+
architecture: "fallback",
65+
expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_64-bit.zip",
66+
},
67+
"linux production x86_64": {
68+
version: "3.4.5",
69+
operatingSystem: "linux",
70+
architecture: "amd64",
71+
expectedFilename: "slack_cli_3.4.5_linux_64-bit.tar.gz",
72+
},
73+
"linux development x86_64": {
74+
version: "3.4.5-6-badaabad",
75+
operatingSystem: "linux",
76+
architecture: "amd64",
77+
expectedFilename: "slack_cli_3.4.5-6-badaabad_linux_64-bit.tar.gz",
78+
},
79+
"windows production x86_64": {
80+
version: "3.4.5",
81+
operatingSystem: "windows",
82+
architecture: "amd64",
83+
expectedFilename: "slack_cli_3.4.5_windows_64-bit.zip",
84+
},
85+
"windows development x86_64": {
86+
version: "3.4.5-6-badaabad",
87+
operatingSystem: "windows",
88+
architecture: "amd64",
89+
expectedFilename: "slack_cli_3.4.5-6-badaabad_windows_64-bit.zip",
90+
},
91+
"unknown production errors": {
92+
version: "3.4.5",
93+
operatingSystem: "dragonfly",
94+
architecture: "amd64",
95+
expectedErrorF: "auto-updating for the operating system (dragonfly) is unsupported",
96+
},
97+
}
98+
for name, tt := range tests {
99+
t.Run(name, func(t *testing.T) {
100+
filename, err := getUpdateFileName(tt.version, tt.operatingSystem, tt.architecture)
101+
if tt.expectedErrorF != "" {
102+
require.Error(t, err)
103+
require.ErrorContains(t, err, tt.expectedErrorF)
104+
} else {
105+
require.NoError(t, err)
106+
require.Equal(t, tt.expectedFilename, filename)
107+
}
108+
})
109+
}
110+
}

scripts/install-dev.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,21 @@ install_slack_cli() {
119119
#
120120

121121
if [ "$(uname)" == "Darwin" ]; then
122+
if version_lt "$SLACK_CLI_DEV_VERSION" "3.3.0"; then
122123
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_64-bit.tar.gz"
124+
else
125+
case "$(uname -m)" in
126+
x86_64)
127+
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_amd64.tar.gz"
128+
;;
129+
arm64 | aarch64)
130+
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_arm64.tar.gz"
131+
;;
132+
*)
133+
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_64-bit.tar.gz"
134+
;;
135+
esac
136+
fi
123137
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
124138
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_linux_64-bit.tar.gz"
125139
else

scripts/install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,21 @@ install_slack_cli() {
121121
#
122122

123123
if [ "$(uname)" == "Darwin" ]; then
124+
if version_lt "$SLACK_CLI_VERSION" "3.3.0"; then
124125
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_64-bit.tar.gz"
126+
else
127+
case "$(uname -m)" in
128+
x86_64)
129+
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_amd64.tar.gz"
130+
;;
131+
arm64 | aarch64)
132+
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_arm64.tar.gz"
133+
;;
134+
*)
135+
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_64-bit.tar.gz"
136+
;;
137+
esac
138+
fi
125139
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
126140
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_linux_64-bit.tar.gz"
127141
else

0 commit comments

Comments
 (0)