Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 0 additions & 1 deletion .github/MAINTAINERS_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ The [`goreleaser`][goreleaser] package we use to build release snapshots needs
updates in the following files on occasion:

- `.circleci/config.yml`
- `.goreleaser-dev.yml`
Copy link
Member

Choose a reason for hiding this comment

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

👋🏻 Bye!

- `.goreleaser.yml`

Testing in our CI setup uses changes to these files when creating test builds.
Expand Down
71 changes: 0 additions & 71 deletions .goreleaser-dev.yml
Copy link
Member Author

Choose a reason for hiding this comment

The 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 .goreleaser.yml - the one difference is an included LICENSE in production.

This file was deleted.

24 changes: 18 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 Here we zip the architecture specific files:

  • ./dist/slack_cli_3.4.5_macOS_amd64.zip
  • ./dist/slack_cli_3.4.5_macOS_arm64.zip

'

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
Copy link
Member Author

Choose a reason for hiding this comment

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

📚 https://goreleaser.com/customization/universalbinaries/

The name_template is used to match packaging paths in tarballs later!

Copy link
Member

Choose a reason for hiding this comment

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

universal_binaries support is such a great discovery! Thank you @zimeg and GoReleaser!

Copy link
Member Author

Choose a reason for hiding this comment

The 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:
Expand All @@ -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 }}"
Expand Down
30 changes: 19 additions & 11 deletions internal/update/cli_autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand Down
110 changes: 110 additions & 0 deletions internal/update/cli_autoupdate_test.go
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)
}
})
}
}
14 changes: 14 additions & 0 deletions scripts/install-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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...

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
14 changes: 14 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,21 @@ install_slack_cli() {
#

if [ "$(uname)" == "Darwin" ]; then
if version_lt "$SLACK_CLI_VERSION" "3.3.0"; then
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_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_VERSION}_macOS_amd64.tar.gz"
;;
arm64 | aarch64)
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_arm64.tar.gz"
;;
*)
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_macOS_64-bit.tar.gz"
;;
esac
fi
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
slack_cli_url="https://downloads.slack-edge.com/slack-cli/slack_cli_${SLACK_CLI_VERSION}_linux_64-bit.tar.gz"
else
Expand Down
Loading