From 6cb9dc0b79032cd511dc7754f1852e4fd8ef7b0f Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 02:03:48 +0100 Subject: [PATCH 1/8] updated goreleaser token --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 193974b..a33775e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -30,4 +30,4 @@ jobs: version: ${{ env.GITHUB_REF_NAME }} args: release --rm-dist env: - GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c8b73d9133e81aa6e532459fa44fc27da75a98ba Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 03:19:37 +0100 Subject: [PATCH 2/8] Updated goreleaser config to avoid including version into archive name. --- .goreleaser => .goreleaser.yaml | 3 + cmd/root.go | 3 +- get.sh | 199 +++++--------------------------- 3 files changed, 34 insertions(+), 171 deletions(-) rename .goreleaser => .goreleaser.yaml (88%) diff --git a/.goreleaser b/.goreleaser.yaml similarity index 88% rename from .goreleaser rename to .goreleaser.yaml index ee3a08f..ddd7f0e 100644 --- a/.goreleaser +++ b/.goreleaser.yaml @@ -11,6 +11,9 @@ builds: flags: - -mod=vendor +archives: + - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" + release: prerelease: auto diff --git a/cmd/root.go b/cmd/root.go index 9fb64dd..47561db 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,6 +41,7 @@ var gitCommit string var localFilename string var codeperfUrl string var codeperfApiUrl string +var benchTime string var local bool var longDescription = ` __ ____ _ _________ ____/ /__ ____ ___ _____/ __/ (_)___ @@ -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") @@ -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") } diff --git a/get.sh b/get.sh index 178f60b..735649d 100755 --- a/get.sh +++ b/get.sh @@ -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() { @@ -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 \ No newline at end of file +download +tar -xf "$TAR_FILE" -C "$TMPDIR" +rm $TAR_FILE +mv $TMPDIR/$REPO . +echo "Checking we can call the codeperf tool" +./codeperf --help \ No newline at end of file From c2713a98060f0e52d9c17bd3f38fc6c2cdd1b487 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 03:27:02 +0100 Subject: [PATCH 3/8] Ensure working release for amd/arm and linux/darwin --- .gitignore | 2 ++ .goreleaser.yaml | 2 +- cmd/root.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2e8fe99..e421d03 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ bin pprof-exporter* codeperf* +dist +vendor # Test binary, built with `go test -c` *.test diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ddd7f0e..3e5795c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,7 +18,7 @@ release: prerelease: auto universal_binaries: - - replace: true + - replace: false brews: - diff --git a/cmd/root.go b/cmd/root.go index 47561db..d777bf6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,7 +41,7 @@ var gitCommit string var localFilename string var codeperfUrl string var codeperfApiUrl string -var benchTime string +var benchtime string var local bool var longDescription = ` __ ____ _ _________ ____/ /__ ____ ___ _____/ __/ (_)___ @@ -184,7 +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(&benchtime, "benchtime", "10s", "benchmark time") rootCmd.PersistentFlags().StringVar(&bench, "bench", "", "Benchmark name") //rootCmd.MarkPersistentFlagRequired("bench") } From 6efe34d6e2902f9a8578ba8a6aa601ac4d5b0d98 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 03:32:26 +0100 Subject: [PATCH 4/8] Updated goreleaser config wrt mod=mod --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3e5795c..e6bdd1f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,7 +9,7 @@ builds: env: - CGO_ENABLED=0 flags: - - -mod=vendor + - -mod=mod archives: - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" From 1b81854a032fd93b030440bf53f75543b1d483f9 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 03:33:44 +0100 Subject: [PATCH 5/8] Updated goreleaser config wrt mod=mod --- .goreleaser.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d3580c0..e6bdd1f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -14,9 +14,6 @@ builds: archives: - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" -archives: - - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" - release: prerelease: auto From 74c2fd46628128d28c561c53964874da3ad111cb Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 03:47:51 +0100 Subject: [PATCH 6/8] updated brew tap --- .goreleaser.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e6bdd1f..d55be15 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -25,8 +25,9 @@ brews: name: codeperf homepage: "https://codeperf.io" description: "Export, persist and compare profiling data using https://codeperf.io." +brews: - tap: + repository: owner: codeperfio name: homebrew-codeperf From f01d53e72733d3faf2fa2bd6618ab406c9d4ee9f Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 03:51:35 +0100 Subject: [PATCH 7/8] updated brew tap --- .goreleaser.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d55be15..5f05a31 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -25,7 +25,6 @@ brews: name: codeperf homepage: "https://codeperf.io" description: "Export, persist and compare profiling data using https://codeperf.io." -brews: repository: owner: codeperfio From a3def1c9ee3eb83b845b7f8234d134144ef6ec59 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 29 Apr 2024 04:01:59 +0100 Subject: [PATCH 8/8] using proper github token for brew tap publishing --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index a33775e..4189b50 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -30,4 +30,4 @@ jobs: version: ${{ env.GITHUB_REF_NAME }} args: release --rm-dist env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_PAT }}