diff --git a/.circleci/config.yml b/.circleci/config.yml index b5b558f3..a4025b67 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -609,7 +609,7 @@ workflows: <<: *filters-tag-triggered-workflow-job name: upload-to-s3-for-install-macOS-feature-build s3-target-path: slack-cli - file-name: "slack_cli_*feature_macOS_64-bit.tar.gz" + file-name: "slack_cli_*feature_macOS_*.tar.gz" requires: - create-github-release-and-artifacts context: slack-cli-release @@ -657,7 +657,7 @@ workflows: <<: *filters-tag-triggered-workflow-job name: upload-to-s3-for-autoupdate-macos s3-target-path: slack-cli - file-name: "slack_cli_*_macOS_64-bit.zip" + file-name: "slack_cli_*_macOS_*.zip" requires: - create-github-release-and-artifacts context: slack-cli-release @@ -685,11 +685,3 @@ workflows: requires: - create-github-release-and-artifacts context: slack-cli-release - - s3-upload: - <<: *filters-tag-triggered-workflow-job - name: upload-to-s3-for-hermes - s3-target-path: cli - file-name: "hermes_*" - requires: - - create-github-release-and-artifacts - context: slack-cli-release diff --git a/.github/MAINTAINERS_GUIDE.md b/.github/MAINTAINERS_GUIDE.md index ab237839..6d165e2a 100644 --- a/.github/MAINTAINERS_GUIDE.md +++ b/.github/MAINTAINERS_GUIDE.md @@ -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` - `.goreleaser.yml` Testing in our CI setup uses changes to these files when creating test builds. diff --git a/.goreleaser-dev.yml b/.goreleaser-dev.yml deleted file mode 100644 index 1c45eae8..00000000 --- a/.goreleaser-dev.yml +++ /dev/null @@ -1,71 +0,0 @@ -# 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. - -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -version: 2 -project_name: slack_cli - -before: - hooks: - - go mod tidy -v - -builds: - - binary: bin/slack - id: slack - ldflags: - - "{{.Env.LDFLAGS}}" - env: - - CGO_ENABLED=0 - goos: - - linux - - windows - goarch: - - amd64 - - - binary: bin/slack - id: slack-macos - ldflags: - - "{{.Env.LDFLAGS}}" - goos: - - darwin - goarch: - - amd64 - hooks: - post: |- - sh -c ' - zip ./dist/slack_cli_{{.Env.BUILD_VERSION}}_macOS_64-bit.zip ./dist/slack-macos_darwin_amd64_v1/bin/slack -j - ' -archives: - - id: slack - builds: - - slack - - slack-macos - format_overrides: - - goos: windows - formats: - - zip - 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 }} - -snapshot: - version_template: "{{ .Env.BUILD_VERSION }}" - -release: - disable: true diff --git a/.goreleaser.yml b/.goreleaser.yml index a3c9ba98..9baea138 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 ' + +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 + ' + 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 }}" diff --git a/internal/update/cli_autoupdate.go b/internal/update/cli_autoupdate.go index cfeb24b7..162f5f87 100644 --- a/internal/update/cli_autoupdate.go +++ b/internal/update/cli_autoupdate.go @@ -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) + } 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) diff --git a/internal/update/cli_autoupdate_test.go b/internal/update/cli_autoupdate_test.go new file mode 100644 index 00000000..5efa5fa6 --- /dev/null +++ b/internal/update/cli_autoupdate_test.go @@ -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) + } + }) + } +} diff --git a/scripts/install-dev.sh b/scripts/install-dev.sh index 77684f68..e15e6e0b 100755 --- a/scripts/install-dev.sh +++ b/scripts/install-dev.sh @@ -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 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 diff --git a/scripts/install.sh b/scripts/install.sh index a5cd27d5..fdd0511f 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -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