Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ commands:
name: Generate dev and prod archives
command: |
./scripts/archive.sh << parameters.artifact_dir >> $BUILD_VERSION
- run:
name: Check expected artifacts exist
command: |
./scripts/archive-test.sh << parameters.artifact_dir >> $BUILD_VERSION
Comment on lines +67 to +70
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 will now fail CI if an expected executable isn't found! IIRC this has caught us off guard before with latest releases so these tests were improved too in this PR.

retrieve-oidc-secrets:
description: "Retrieves secrets from Slack"
parameters:
Expand Down Expand Up @@ -276,7 +280,7 @@ jobs:
- run:
name: Delete non-signed archive
command: |
rm << parameters.artifact_dir >>/slack_*_macOS_64-bit.tar.gz
rm << parameters.artifact_dir >>/slack_*_macOS_*.tar.gz
Comment on lines 280 to +283
Copy link
Member Author

Choose a reason for hiding this comment

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

🪓 An initial removal of this step missed that this step is most useful when codesigning happens before generating archives!

We continue to remove unsigned archives to repackage tarballs with the signed zip:

codesign

- generate-archives:
artifact_dir: << parameters.artifact_dir >>
- run:
Expand Down
130 changes: 69 additions & 61 deletions scripts/archive-test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2022-2025 Salesforce, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,88 +12,96 @@
# 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.

set -e

#
# USAGE:
# ./scripts/archive-test.sh <release version>
#
# EXAMPLES:
# This script now executed inside goreleaser, if you need to run the script alone, make sure you have macOS and Linux original archives in ./dist
# - ./scripts/archive-test.sh 1.5.0
# DESCRIPTION:
# Create the development tar.gz archives used by the `install-dev.sh` script.
# Artifacts are built with GoReleaser and should be packaged into various
# release archives before running this script:
#
# Generates macOS and Linux archives.
# $ make build-snapshot
# $ ./scripts/archive.sh ./dist 3.3.0
# $ ./scripts/archive-test.sh ./dist 3.3.0
#
# After generating the archive, the script will test the archive by
# extracting it and looking for `bin/slack` for macOS binary
# Linux archive is generated directorily from original binary
# DESCRIPTION:
# Confirm the expected tar.gz and zip bundles exist for a packaged version.
#
# Various binaries are extracted and checked for existence and permissions.

DIST_DIR="dist"
DIST_DIR=${1}

main() {
if [ $# -lt 1 ]; then
echo "Release version is required"
if [ $# -lt 2 ]; then
echo "Missing parameters: $0 <path> <version>"
exit 1
fi

VERSION=${1}

echo "Creating macOS archive:"

src_file_path="$DIST_DIR/slack-macos_darwin_amd64/slack_cli_${VERSION}_macos.zip"
echo "-> Source archive: $src_file_path"

targz_dir_path="$DIST_DIR/slack_mac_dev_64-bit"
targz_file_path="$DIST_DIR/slack_mac_dev_64-bit.tar.gz"

echo "-> Creating dist directory: $targz_dir_path"
mkdir -p "$targz_dir_path"

echo "-> Extracting: $targz_dir_path"
unzip "$src_file_path" -d "$targz_dir_path"

echo "-> Moving $targz_dir_path/slack to $targz_dir_path/bin/slack"
mkdir "$targz_dir_path/bin"
mv "$targz_dir_path/slack" "$targz_dir_path/bin/slack"
VERSION=${2}

echo "Checking macOS archives"
check_tar "$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.tar.gz"
check_tar "$DIST_DIR/slack_cli_${VERSION}_macOS_amd64.tar.gz"
check_tar "$DIST_DIR/slack_cli_${VERSION}_macOS_arm64.tar.gz"
check_tar "$DIST_DIR/slack_cli_dev_macOS_64-bit.tar.gz"
check_tar "$DIST_DIR/slack_cli_dev_macOS_amd64.tar.gz"
check_tar "$DIST_DIR/slack_cli_dev_macOS_arm64.tar.gz"
check_tar "$DIST_DIR/slack_cli_latest_macOS_64-bit.tar.gz"
check_tar "$DIST_DIR/slack_cli_latest_macOS_amd64.tar.gz"
check_tar "$DIST_DIR/slack_cli_latest_macOS_arm64.tar.gz"

check_zip "$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.zip"
check_zip "$DIST_DIR/slack_cli_${VERSION}_macOS_amd64.zip"
check_zip "$DIST_DIR/slack_cli_${VERSION}_macOS_arm64.zip"
check_zip "$DIST_DIR/slack_cli_${VERSION}_macos.zip"

echo "Checking Linux archives"
check_tar "$DIST_DIR/slack_cli_${VERSION}_linux_64-bit.tar.gz"
check_tar "$DIST_DIR/slack_cli_dev_linux_64-bit.tar.gz"
check_tar "$DIST_DIR/slack_cli_latest_linux_64-bit.tar.gz"

echo "Checking Windows archives"
check_exe "$DIST_DIR/slack_cli_${VERSION}_windows_64-bit.zip"

echo "Success! Archives exist!"
}

echo "-> Creating tar.gz file: $targz_file_path"
tar -C "$targz_dir_path" -zcvf "$targz_file_path" .
check_exe() {
echo "-> Testing executable exists: $1"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
unzip -q "$1" -d "$tmpdir"

echo "-> Cleaning up: $targz_dir_path"
rm -R "$targz_dir_path"
file "$tmpdir/bin/slack.exe" | grep -q 'PE32' || {
echo "-> Failed to find executable: $1"
exit 1
}
}

echo "-> Testing tar.gz file..."
mkdir "$targz_dir_path"
tar -zxvf "$targz_file_path" -C "$targz_dir_path"
check_tar() {
echo "-> Testing executable exists: $1"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
tar -xzf "$1" -C "$tmpdir"

if [ $(command -v "$targz_dir_path/bin/slack") ]; then
echo "-> Found bin/slack"
rm -R "$targz_dir_path"
else
echo "-> Missing bin/slack"
if ! [[ -x "$tmpdir/bin/slack" ]]; then
echo "-> Failed to find executable: $1"
return 1
fi
}

echo "-> Everything looks good!"
echo "-> macOS archive: $targz_file_path"

echo "Creating Linux archive:"

linux_src_file_path="$DIST_DIR/slack_linux_amd64/"
linux_targz_file_path="$DIST_DIR/slack_linux_dev_64-bit.tar.gz"
check_zip() {
echo "-> Testing executable exists: $1"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
unzip -q "$1" -d "$tmpdir"

if [ $(command -v "$linux_src_file_path/bin/slack") ]; then
echo "-> Found bin/slack"
else
echo "-> Missing bin/slack"
exit
if ! [[ -x "$tmpdir/slack" ]]; then
echo "-> Failed to find executable: $1"
return 1
fi

echo "-> Creating tar.gz file: $targz_file_path"
tar -czvf "$linux_targz_file_path" -C "$linux_src_file_path" .

echo "-> Linux archive: $linux_targz_file_path"
}

main "$@"
163 changes: 72 additions & 91 deletions scripts/archive.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2022-2025 Salesforce, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,115 +12,96 @@
# 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.
set -eo
set -e

# USAGE:
# ./scripts/archive.sh <artifact path> <release version>
#
# EXAMPLES:
# This script now executed inside goreleaser, if you need to run the script alone, make sure you have macOS and Linux original archives in your artificate path
# - ./scripts/archive.sh /artifacts 1.5.0
# Artifacts are built with GoReleaser and must exist before running this
# script:
#
# $ make build-snapshot
# $ ./scripts/archive.sh ./dist 3.3.0
#
# DESCRIPTION:
# Create the development and production tar.gz archives used by the `install.sh` and `install-dev.sh`scripts.
# Create the development and production tar.gz and zip archives. These are
# used in the `install.sh` and `install-dev.sh` scripts.
#
# Generates macOS and Linux archives.

# After generating the archive for macOS, the script will test the archive by
# extracting it and looking for `bin/slack`
# Linux archive is generated directorily from original binary,
# the script will check if `bin/slack` for Linux exits or not first
# Tests for correct packaging is done with the `archive-test.sh` script.

DIST_DIR=${1}

main() {
if [ $# -lt 2 ]; then
echo "Missing parameters"
echo "Missing parameters: $0 <path> <version>"
exit 1
fi

VERSION=${2}

echo "Creating macOS archives:"

mac_src_file_path="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.zip"
echo "-> Source archive: $mac_src_file_path"

mac_targz_dir_path="$DIST_DIR/slack_mac_64-bit"
macos_dev_targz_file_path="$DIST_DIR/slack_cli_dev_macOS_64-bit.tar.gz"
macos_prod_targz_file_path="$DIST_DIR/slack_cli_latest_macOS_64-bit.tar.gz"
macos_prod_targz_file_path_2="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.tar.gz"
macos_prod_zip_file_path="$DIST_DIR/slack_cli_${VERSION}_macos.zip"

echo "-> Creating dist directory: $mac_targz_dir_path"
mkdir -p "$mac_targz_dir_path"

echo "-> Extracting: $mac_targz_dir_path"
unzip "$mac_src_file_path" -d "$mac_targz_dir_path"

echo "-> Moving $mac_targz_dir_path/slack to $mac_targz_dir_path/bin/slack"
mkdir "$mac_targz_dir_path/bin"
mv "$mac_targz_dir_path/slack" "$mac_targz_dir_path/bin/slack"

echo "-> Creating macOS development tar.gz file: $macos_dev_targz_file_path"
tar -C "$mac_targz_dir_path" -zcvf "$macos_dev_targz_file_path" .

echo "-> Creating macOS production tar.gz file: $macos_prod_targz_file_path"
tar -C "$mac_targz_dir_path" -zcvf "$macos_prod_targz_file_path" .
tar -C "$mac_targz_dir_path" -zcvf "$macos_prod_targz_file_path_2" .

echo "-> Creating macOS .zip file with old name for auto-update:
$macos_prod_zip_file_path"
cp -i "$mac_src_file_path" "$macos_prod_zip_file_path"

echo "-> Cleaning up: $mac_targz_dir_path"
rm -R "$mac_targz_dir_path"

echo "-> Testing macOs development tar.gz file..."
mkdir "$mac_targz_dir_path"
tar -zxvf "$macos_dev_targz_file_path" -C "$mac_targz_dir_path"

if [ $(command -v "$mac_targz_dir_path/bin/slack") ]; then
echo "-> Found bin/slack"
rm -R "$mac_targz_dir_path"
else
echo "-> Missing development bin/slack"
fi

echo "-> Testing macOs production tar.gz file..."
mkdir "$mac_targz_dir_path"
tar -zxvf "$macos_prod_targz_file_path" -C "$mac_targz_dir_path"

if [ $(command -v "$mac_targz_dir_path/bin/slack") ]; then
echo "-> Found bin/slack"
rm -R "$mac_targz_dir_path"
else
echo "-> Missing production bin/slack"
fi

echo "-> Everything looks good!"
echo "-> macOS archive: $targz_file_path"

echo "Creating Linux archives:"

linux_src_file_path="$DIST_DIR/slack_cli_${VERSION}_linux_64-bit.tar.gz"
linux_dev_targz_file_path="$DIST_DIR/slack_cli_dev_linux_64-bit.tar.gz"
linux_prod_targz_file_path="$DIST_DIR/slack_cli_latest_linux_64-bit.tar.gz"

if [ -f "$linux_src_file_path" ]; then
echo "-> Found linux binary archive"
else
echo "-> Missing linux binary archive"
exit
fi

echo "-> Creating development Linux tar.gz file: $linux_dev_targz_file_path"
cp "$linux_src_file_path" "$linux_dev_targz_file_path"
echo "-> Linux development archive: $linux_dev_targz_file_path"
echo "Creating macOS archives"

macos_targz_file_path_version_universal="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.tar.gz"
macos_targz_file_path_version_amd64="$DIST_DIR/slack_cli_${VERSION}_macOS_amd64.tar.gz"
macos_targz_file_path_version_arm64="$DIST_DIR/slack_cli_${VERSION}_macOS_arm64.tar.gz"
macos_targz_file_path_dev_universal="$DIST_DIR/slack_cli_dev_macOS_64-bit.tar.gz"
macos_targz_file_path_dev_amd64="$DIST_DIR/slack_cli_dev_macOS_amd64.tar.gz"
macos_targz_file_path_dev_arm64="$DIST_DIR/slack_cli_dev_macOS_arm64.tar.gz"
macos_targz_file_path_latest_universal="$DIST_DIR/slack_cli_latest_macOS_64-bit.tar.gz"
macos_targz_file_path_latest_amd64="$DIST_DIR/slack_cli_latest_macOS_amd64.tar.gz"
macos_targz_file_path_latest_arm64="$DIST_DIR/slack_cli_latest_macOS_arm64.tar.gz"

macos_zip_file_path_universal="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.zip"
macos_zip_file_path_amd64="$DIST_DIR/slack_cli_${VERSION}_macOS_amd64.zip"
macos_zip_file_path_arm64="$DIST_DIR/slack_cli_${VERSION}_macOS_arm64.zip"
macos_zip_file_path_universal_legacy="$DIST_DIR/slack_cli_${VERSION}_macos.zip"

echo "-> Creating macOS versioned tar.gz files"
unzip_tar "$macos_zip_file_path_universal" "$macos_targz_file_path_version_universal"
unzip_tar "$macos_zip_file_path_amd64" "$macos_targz_file_path_version_amd64"
unzip_tar "$macos_zip_file_path_arm64" "$macos_targz_file_path_version_arm64"
ls -l "$DIST_DIR"/*_"$VERSION"_macOS*

echo "-> Creating macOS development tar.gz files"
cp "$macos_targz_file_path_version_universal" "$macos_targz_file_path_dev_universal"
cp "$macos_targz_file_path_version_amd64" "$macos_targz_file_path_dev_amd64"
cp "$macos_targz_file_path_version_arm64" "$macos_targz_file_path_dev_arm64"
ls -l "$DIST_DIR"/*dev_macOS*

echo "-> Creating macOS latest tar.gz files"
cp "$macos_targz_file_path_version_universal" "$macos_targz_file_path_latest_universal"
cp "$macos_targz_file_path_version_amd64" "$macos_targz_file_path_latest_amd64"
cp "$macos_targz_file_path_version_arm64" "$macos_targz_file_path_latest_arm64"
ls -l "$DIST_DIR"/*latest_macOS*

echo "-> Creating macOS legacy .zip file for auto-update"
cp "$macos_zip_file_path_universal" "$macos_zip_file_path_universal_legacy"
ls -l "$DIST_DIR"/*_macos.zip

echo "Creating Linux archives"

linux_targz_file_path_version="$DIST_DIR/slack_cli_${VERSION}_linux_64-bit.tar.gz"
linux_targz_file_path_dev="$DIST_DIR/slack_cli_dev_linux_64-bit.tar.gz"
linux_targz_file_path_latest="$DIST_DIR/slack_cli_latest_linux_64-bit.tar.gz"

echo "-> Creating Linux development tar.gz file"
cp "$linux_targz_file_path_version" "$linux_targz_file_path_dev"
ls -l "$DIST_DIR"/*dev_linux*

echo "-> Creating Linux production tar.gz file"
cp "$linux_targz_file_path_version" "$linux_targz_file_path_latest"
ls -l "$DIST_DIR"/*latest_linux*
}

echo "-> Creating production Linux tar.gz file: $linux_prod_targz_file_path"
cp "$linux_src_file_path" "$linux_prod_targz_file_path"
echo "-> Linux development archive: $linux_prod_targz_file_path"
# Repackage tarballs with the signed zip
unzip_tar() {
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
unzip "$1" -d "$tmpdir"
mkdir "$tmpdir/bin"
mv "$tmpdir/slack" "$tmpdir/bin/slack"
tar -C "$tmpdir" -zcvf "$2" .
}

main "$@"
Loading