-
Notifications
You must be signed in to change notification settings - Fork 24
build: package for apple intel and apple silicon machines alongside universal binaries as fallback #101
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
build: package for apple intel and apple silicon machines alongside universal binaries as fallback #101
Changes from 6 commits
32205a7
8546c20
190a892
4a69661
30811dd
d84ae05
cb222a2
d624e61
b051dcc
56f6d72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗣️ AFAICT we are not using this file and it is almost identical to the production |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,11 +41,23 @@ builds: | |
| - darwin | ||
| goarch: | ||
| - amd64 | ||
| - arm64 | ||
| hooks: | ||
| post: |- | ||
| sh -c ' | ||
| zip ./dist/slack_cli_{{.Env.BUILD_VERSION}}_macOS_64-bit.zip ./dist/slack-macos_darwin_amd64_v1/bin/slack -j | ||
| zip ./dist/slack_cli_{{ .Env.BUILD_VERSION }}_macOS_{{ .Arch }}.zip ./dist/slack-macos_{{ .Target }}/bin/slack -j | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Here we
|
||
| ' | ||
|
|
||
| universal_binaries: | ||
| - id: slack-macos | ||
| name_template: bin/slack | ||
| replace: false | ||
| hooks: | ||
| post: |- | ||
| sh -c ' | ||
| zip ./dist/slack_cli_{{.Env.BUILD_VERSION}}_macOS_64-bit.zip ./dist/slack-macos_darwin_all/bin/slack -j | ||
| ' | ||
|
Comment on lines
+51
to
+59
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📚 https://goreleaser.com/customization/universalbinaries/ The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must give so much credit to the great folks at @goreleaser 🙏 ✨ |
||
|
|
||
| archives: | ||
| - id: slack | ||
| ids: | ||
|
|
@@ -60,11 +72,11 @@ archives: | |
| name_template: >- | ||
| {{- .ProjectName }}_ | ||
| {{- .Env.BUILD_VERSION }}_ | ||
| {{- if eq .Os "darwin" }}macOS | ||
| {{- else }}{{ .Os }}{{ end }}_ | ||
| {{- if eq .Arch "amd64" }}64-bit | ||
| {{- else if eq .Arch "386" }}32-bit | ||
| {{- else }}{{ .Arch }}{{ end }} | ||
| {{- if eq .Os "darwin" -}} | ||
| macOS_{{ if eq .Arch "all" }}64-bit{{ else }}{{ .Arch }}{{ end }} | ||
| {{- else -}} | ||
| {{ .Os }}_{{ if eq .Arch "amd64" }}64-bit{{ else }}{{ .Arch }}{{ end }} | ||
| {{- end }} | ||
|
|
||
| snapshot: | ||
| version_template: "{{ .Env.BUILD_VERSION }}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,8 +59,8 @@ func (c *CLIDependency) InstallUpdate(ctx context.Context) error { | |
|
|
||
| architecture := runtime.GOARCH | ||
| operatingSys := runtime.GOOS | ||
| c.clients.IO.PrintDebug(ctx, "Architecture: %s \nOS: %s", architecture, operatingSys) | ||
| fileName, err := getUpdateFileName(c.releaseInfo.Version, operatingSys) | ||
| c.clients.IO.PrintDebug(ctx, "Architecture: %s\nOS: %s", architecture, operatingSys) | ||
| fileName, err := getUpdateFileName(c.releaseInfo.Version, operatingSys, architecture) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -245,19 +245,27 @@ func restoreBinary(updatedBinaryFolderPath string, newPathToOldBinary string, or | |
| return nil | ||
| } | ||
|
|
||
| // getUpdateFilename returns name of the archive that contains the upgrade for the given version and OS | ||
| func getUpdateFileName(version, operatingSys string) (filename string, err error) { | ||
| // You can get a list of all possible OS/architecture combinations with `go tool dist list | column -c 75 | column -t` | ||
| // TODO: account for architecture as well. M1 macs would have an arch of arm64 instead of the usual amd64 | ||
| const binaryName = "slack_cli" | ||
| const architecture = "64-bit" | ||
| // getUpdateFilename returns name of the archive that contains the upgrade for | ||
| // the given version and OS. | ||
| // | ||
| // All possible OS/architecture combinations can be listed with the command: | ||
| // | ||
| // go tool dist list | column -c 75 | column -t | ||
| func getUpdateFileName(version, operatingSys, architecture string) (filename string, err error) { | ||
| switch operatingSys { | ||
| case "darwin": | ||
| filename = fmt.Sprintf("%s_%s_macOS_%s.zip", binaryName, version, architecture) | ||
| switch architecture { | ||
| case "amd64": | ||
| filename = fmt.Sprintf("slack_cli_%s_macOS_amd64.zip", version) | ||
| case "arm64": | ||
| filename = fmt.Sprintf("slack_cli_%s_macOS_arm64.zip", version) | ||
| default: | ||
| filename = fmt.Sprintf("slack_cli_%s_macOS_64-bit.zip", version) | ||
| } | ||
|
Comment on lines
+257
to
+264
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: so nice! 👌🏻 |
||
| case "linux": | ||
| filename = fmt.Sprintf("%s_%s_linux_%s.tar.gz", binaryName, version, architecture) | ||
| filename = fmt.Sprintf("slack_cli_%s_linux_64-bit.tar.gz", version) | ||
| case "windows": | ||
| filename = fmt.Sprintf("%s_%s_windows_%s.zip", binaryName, version, architecture) | ||
| filename = fmt.Sprintf("slack_cli_%s_windows_64-bit.zip", version) | ||
| default: | ||
| err = slackerror.New(fmt.Sprintf("auto-updating for the operating system (%s) is unsupported", operatingSys)) | ||
| err = slackerror.Wrapf(err, slackerror.ErrCLIAutoUpdate) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright 2022-2025 Salesforce, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package update | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func Test_CLI_getUpdateFileName(t *testing.T) { | ||
| tests := map[string]struct { | ||
| version string | ||
| operatingSystem string | ||
| architecture string | ||
| expectedFilename string | ||
| expectedErrorF string | ||
| }{ | ||
| "darwin production x86_64": { | ||
| version: "3.4.5", | ||
| operatingSystem: "darwin", | ||
| architecture: "amd64", | ||
| expectedFilename: "slack_cli_3.4.5_macOS_amd64.zip", | ||
| }, | ||
| "darwin development x86_64": { | ||
| version: "3.4.5-6-badaabad", | ||
| operatingSystem: "darwin", | ||
| architecture: "amd64", | ||
| expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_amd64.zip", | ||
| }, | ||
| "darwin production aarch64": { | ||
| version: "3.4.5", | ||
| operatingSystem: "darwin", | ||
| architecture: "arm64", | ||
| expectedFilename: "slack_cli_3.4.5_macOS_arm64.zip", | ||
| }, | ||
| "darwin development aarch64": { | ||
| version: "3.4.5-6-badaabad", | ||
| operatingSystem: "darwin", | ||
| architecture: "arm64", | ||
| expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_arm64.zip", | ||
| }, | ||
| "darwin production universal": { | ||
| version: "3.4.5", | ||
| operatingSystem: "darwin", | ||
| architecture: "fallback", | ||
| expectedFilename: "slack_cli_3.4.5_macOS_64-bit.zip", | ||
| }, | ||
| "darwin development universal": { | ||
| version: "3.4.5-6-badaabad", | ||
| operatingSystem: "darwin", | ||
| architecture: "fallback", | ||
| expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_64-bit.zip", | ||
| }, | ||
| "linux production x86_64": { | ||
| version: "3.4.5", | ||
| operatingSystem: "linux", | ||
| architecture: "amd64", | ||
| expectedFilename: "slack_cli_3.4.5_linux_64-bit.tar.gz", | ||
| }, | ||
| "linux development x86_64": { | ||
| version: "3.4.5-6-badaabad", | ||
| operatingSystem: "linux", | ||
| architecture: "amd64", | ||
| expectedFilename: "slack_cli_3.4.5-6-badaabad_linux_64-bit.tar.gz", | ||
| }, | ||
| "windows production x86_64": { | ||
| version: "3.4.5", | ||
| operatingSystem: "windows", | ||
| architecture: "amd64", | ||
| expectedFilename: "slack_cli_3.4.5_windows_64-bit.zip", | ||
| }, | ||
| "windows development x86_64": { | ||
| version: "3.4.5-6-badaabad", | ||
| operatingSystem: "windows", | ||
| architecture: "amd64", | ||
| expectedFilename: "slack_cli_3.4.5-6-badaabad_windows_64-bit.zip", | ||
| }, | ||
| "unknown production errors": { | ||
| version: "3.4.5", | ||
| operatingSystem: "dragonfly", | ||
| architecture: "amd64", | ||
| expectedErrorF: "auto-updating for the operating system (dragonfly) is unsupported", | ||
| }, | ||
| } | ||
| for name, tt := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| filename, err := getUpdateFileName(tt.version, tt.operatingSystem, tt.architecture) | ||
| if tt.expectedErrorF != "" { | ||
| require.Error(t, err) | ||
| require.ErrorContains(t, err, tt.expectedErrorF) | ||
| } else { | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.expectedFilename, filename) | ||
| } | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,21 @@ install_slack_cli() { | |
| # | ||
|
|
||
| if [ "$(uname)" == "Darwin" ]; then | ||
| if version_lt "$SLACK_CLI_DEV_VERSION" "3.3.0"; then | ||
| slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_64-bit.tar.gz" | ||
| else | ||
| case "$(uname -m)" in | ||
| x86_64) | ||
| slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_amd64.tar.gz" | ||
| ;; | ||
| arm64 | aarch64) | ||
| slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_arm64.tar.gz" | ||
| ;; | ||
| *) | ||
| slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_macOS_64-bit.tar.gz" | ||
| ;; | ||
| esac | ||
| fi | ||
|
Comment on lines
+122
to
+136
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📣 We're guarding against specific installations of versions prior to next release here! This adds some overhead to this script, but I don't think backporting releases can be done without so much effort and potential error otherwise...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, this is a clean way to do it and doesn't add very much overhead. Nice work! |
||
| elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | ||
| slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_DEV_VERSION}_linux_64-bit.tar.gz" | ||
| else | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋🏻 Bye!