Skip to content

Ensure working release for amd/arm and linux/darwin #9

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

Merged
merged 4 commits into from
Apr 29, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
bin
pprof-exporter*
codeperf*
dist
vendor

# Test binary, built with `go test -c`
*.test
Expand Down
5 changes: 4 additions & 1 deletion .goreleaser → .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ builds:
flags:
- -mod=vendor

archives:
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"

release:
prerelease: auto

universal_binaries:
- replace: true
- replace: false

brews:
-
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var gitCommit string
var localFilename string
var codeperfUrl string
var codeperfApiUrl string
var benchtime string
var local bool
var longDescription = ` __ ____ _
_________ ____/ /__ ____ ___ _____/ __/ (_)___
Expand Down Expand Up @@ -71,7 +72,6 @@ func testLogic(cmd *cobra.Command, args []string) {
// TODO: Check pprof is available on path
const shell = "/bin/bash"
benchmarks, _ := GetBenchmarks(".")
benchtime := "1s"
var err error = nil

goPath, err := exec.LookPath("go")
Expand Down Expand Up @@ -184,6 +184,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&localFilename, "local-filename", "profile.json", "Local file to export the json to. Only used when the --local flag is set")
rootCmd.PersistentFlags().StringVar(&codeperfUrl, "codeperf-url", "https://codeperf.io", "codeperf URL")
rootCmd.PersistentFlags().StringVar(&codeperfApiUrl, "codeperf-api-url", "https://api.codeperf.io", "codeperf API URL")
rootCmd.PersistentFlags().StringVar(&benchtime, "benchtime", "10s", "benchmark time")
rootCmd.PersistentFlags().StringVar(&bench, "bench", "", "Benchmark name")
//rootCmd.MarkPersistentFlagRequired("bench")
}
Expand Down
199 changes: 29 additions & 170 deletions get.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
#!/bin/bash

# Copyright OpenFaaS Author(s) 2019
#########################
# Repo specific content #
#########################
set -e

export VERIFY_CHECKSUM=0
export ALIAS=""
export OWNER=codeperfio
export REPO=codeperf
export SUCCESS_CMD="$REPO version"
export BINLOCATION="/usr/local/bin"

###############################
# Content common across repos #
###############################

version=$(curl -sI https://github.com/$OWNER/$REPO/releases/latest | grep -i "location:" | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
if [ ! $version ]; then
echo "Failed while attempting to install $REPO. Please manually install:"
echo ""
echo "1. Open your web browser and go to https://github.com/$OWNER/$REPO/releases"
echo "2. Download the latest release for your platform. Call it '$REPO'."
echo "3. chmod +x ./$REPO"
echo "4. mv ./$REPO $BINLOCATION"
if [ -n "$ALIAS_NAME" ]; then
echo "5. ln -sf $BINLOCATION/$REPO /usr/local/bin/$ALIAS_NAME"
fi
exit 1
fi
TAR_FILE="/tmp/$REPO.tar.gz"
RELEASES_URL="https://github.com/$OWNER/$REPO/releases"
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"

hasCli() {

Expand All @@ -39,153 +18,33 @@ hasCli() {
fi
}

checkHash(){

sha_cmd="sha256sum"

if [ ! -x "$(command -v $sha_cmd)" ]; then
sha_cmd="shasum -a 256"
fi

if [ -x "$(command -v $sha_cmd)" ]; then

targetFileDir=${targetFile%/*}

(cd $targetFileDir && curl -sSL $url.sha256|$sha_cmd -c >/dev/null)

if [ "$?" != "0" ]; then
rm $targetFile
echo "Binary checksum didn't match. Exiting"
exit 1
fi
fi
}

getPackage() {
uname=$(uname)
userid=$(id -u)

suffix=""
case $uname in
"Darwin")
suffix="-darwin"
;;
"MINGW"*)
suffix=".exe"
BINLOCATION="$HOME/bin"
mkdir -p $BINLOCATION

;;
"Linux")
arch=$(uname -m)
echo $arch
case $arch in
"aarch64")
suffix="-arm64"
;;
esac
case $arch in
"armv6l" | "armv7l")
suffix="-armhf"
;;
esac
;;
esac

targetFile="/tmp/$REPO"

if [ "$userid" != "0" ]; then
targetFile="$(pwd)/$REPO"
fi

if [ -e "$targetFile" ]; then
rm "$targetFile"
fi

url=https://github.com/$OWNER/$REPO/releases/download/$version/$REPO$suffix
echo "Downloading package $url as $targetFile"

curl -sSL $url --output "$targetFile"

if [ "$?" = "0" ]; then

if [ "$VERIFY_CHECKSUM" = "1" ]; then
checkHash
fi

chmod +x "$targetFile"

echo "Download complete."

if [ ! -w "$BINLOCATION" ]; then

echo
echo "============================================================"
echo " The script was run as a user who is unable to write"
echo " to $BINLOCATION. To complete the installation the"
echo " following commands may need to be run manually."
echo "============================================================"
echo
echo " sudo cp $REPO $BINLOCATION/$REPO"

if [ -n "$ALIAS_NAME" ]; then
echo " sudo ln -sf $BINLOCATION/$REPO $BINLOCATION/$ALIAS_NAME"
fi

echo

else

echo
echo "Running with sufficient permissions to attempt to move $REPO to $BINLOCATION"

if [ ! -w "$BINLOCATION/$REPO" ] && [ -f "$BINLOCATION/$REPO" ]; then

echo
echo "================================================================"
echo " $BINLOCATION/$REPO already exists and is not writeable"
echo " by the current user. Please adjust the binary ownership"
echo " or run sh/bash with sudo."
echo "================================================================"
echo
exit 1

fi

mv $targetFile $BINLOCATION/$REPO

if [ "$?" = "0" ]; then
echo "New version of $REPO installed to $BINLOCATION"
fi

if [ -e "$targetFile" ]; then
rm "$targetFile"
fi

if [ -n "$ALIAS_NAME" ]; then
if [ ! -L $BINLOCATION/$ALIAS_NAME ]; then
ln -s $BINLOCATION/$REPO $BINLOCATION/$ALIAS_NAME
echo "Creating alias '$ALIAS_NAME' for '$REPO'."
fi
fi

${SUCCESS_CMD}
fi
fi
last_version() {
curl -sL -o /dev/null -w %{url_effective} "$RELEASES_URL/latest" |
rev |
cut -f1 -d'/'|
rev
}

thanks() {
echo " __ ____ _ "
echo " _________ ____/ /__ ____ ___ _____/ __/ (_)___ "
echo " / ___/ __ \/ __ / _ \/ __ \/ _ \/ ___/ /_ / / __ \ "
echo "/ /__/ /_/ / /_/ / __/ /_/ / __/ / / __/ _ / / /_/ / "
echo "\___/\____/\__,_/\___/ .___/\___/_/ /_/ (_) /_/\____/"
echo " /_/"
echo
echo "Export and persist Go profiling data locally, or into https://codeperf.io for FREE"
echo
download() {
echo "getting latest release from $RELEASES_URL/latest..."
echo "detected latest version=$(last_version)"
test -z "$VERSION" && VERSION="$(last_version)"
test -z "$VERSION" && {
echo "Unable to get codeperf version." >&2
exit 1
}
rm -f "$TAR_FILE"
RELEASE_ARTIFACT="$RELEASES_URL/download/$VERSION/${REPO}_$(uname -s)_$(uname -m).tar.gz"
echo "getting $RELEASE_ARTIFACT into $TAR_FILE"
curl -s -L -o "$TAR_FILE" \
$RELEASE_ARTIFACT

}

hasCli
getPackage
thanks
download
tar -xf "$TAR_FILE" -C "$TMPDIR"
rm $TAR_FILE
mv $TMPDIR/$REPO .
echo "Checking we can call the codeperf tool"
./codeperf --help
Loading