Skip to content

Commit

Permalink
chore: pactus downloader script (#516)
Browse files Browse the repository at this point in the history
* chore: pactus downloader script

* chore: added -trimpath flag
  • Loading branch information
themantre authored Jun 18, 2023
1 parent 0918e5d commit 2141555
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 12 deletions.
160 changes: 160 additions & 0 deletions .github/releasers/pactus_downloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/sh

# Function to check if a command is available
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Download function
download_file() {
file_name=$1
url=$2
echo "Downloading ${file_name}..."
if ! curl --fail --proto '=https' --tlsv1.2 -sSL -o "${file_name}" "${url}"; then
echo "Failed to download ${file_name}. Check the URL or your internet connection."
exit 1
fi
}


# Check if sha256sum is installed
if ! command_exists sha256sum; then
echo "sha256sum is not installed. Please install sha256sum and try again."
exit 1
fi

# Detect the operating system and CPU type
OS=$(uname -s)
ARCH=$(uname -m)
EXT=".tar.gz"

case $OS in
######################
Android)
OS="android"
case $ARCH in
aarch64 | arm64)
ARCH="arm64"
;;
*)
echo "Unrecognized CPU type: $ARCH"
exit 1
;;
esac
;;

######################
Linux)
OS="linux"
case $ARCH in
x86_64)
ARCH="amd64"
;;
arm64)
ARCH="arm64"
;;
*)
echo "Unrecognized CPU type: $ARCH"
exit 1
;;
esac
;;

######################
FreeBSD)
OS="freebsd"
case $ARCH in
amd64)
ARCH="amd64"
;;
*)
echo "Unrecognized CPU type: $ARCH"
exit 1
;;
esac
;;

######################
Darwin)
OS="darwin"
case $ARCH in
x86_64)
ARCH="amd64"
;;
arm64)
ARCH="arm64"
;;
*)
echo "Unrecognized CPU type: $ARCH"
exit 1
;;
esac
;;

######################
MINGW* | MSYS* | CYGWIN*)
if ! command_exists unzip; then
echo "unzip is not installed. Please install unzip and try again."
exit 1
fi
OS="windows"
EXT=".zip"
case $ARCH in
i686 | i386)
ARCH="386"
;;
x86_64)
ARCH="amd64"
;;
*)
echo "Unrecognized CPU type: $ARCH"
exit 1
;;
esac
;;

*)
echo "Unrecognized OS type: $OS"
exit 1
;;
esac

# Version number
VERSION="__VERSION__"

# Set the server URL where the binary and checksum files are hosted
SERVER_URL="https://github.com/pactus-project/pactus/releases/download/v${VERSION}"

# Set the filename of the binary and checksum
CHECKSUM_FILE="SHA256SUMS"

# Set the filename of the binary and checksum
FILE_NAME="pactus-cli_${VERSION}_${OS}_${ARCH}${EXT}"

# Destination directory that is the current directory
DEST_DIR=$(pwd)

# Create a temporary directory for downloads
DOWN_DIR=$(mktemp -d)

cd ${DOWN_DIR}

# Download the files using the download_file function
download_file "${FILE_NAME}" "${SERVER_URL}/${FILE_NAME}"
download_file "${CHECKSUM_FILE}" "${SERVER_URL}/${CHECKSUM_FILE}"

# Verify the checksum
sha256sum --ignore-missing -c "${CHECKSUM_FILE}"
if [ $? -ne 0 ]; then
echo "Checksum verification failed for ${FILE_NAME}!"
exit 1
fi

# Extracting
if [ "${OS}" = "windows" ]; then
unzip -n "${FILE_NAME}" -d "${DEST_DIR}"
else
tar -xzf "${FILE_NAME}" -C "${DEST_DIR}"
fi

echo "Installation completed."
4 changes: 2 additions & 2 deletions .github/releasers/releaser_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ for OS_ARCH in \
EXE=".exe"
fi

GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-s -w" -o ${BUILD_DIR}/${PACKAGE_NAME}/pactus-daemon${EXE} ./cmd/daemon
GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-s -w" -o ${BUILD_DIR}/${PACKAGE_NAME}/pactus-wallet${EXE} ./cmd/wallet
GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/${PACKAGE_NAME}/pactus-daemon${EXE} ./cmd/daemon
GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/${PACKAGE_NAME}/pactus-wallet${EXE} ./cmd/wallet

cd ${BUILD_DIR}
if [ $OS = "windows" ]; then
Expand Down
6 changes: 3 additions & 3 deletions .github/releasers/releaser_gui_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mkdir ${PACKAGE_DIR}
echo "Building the binaries"

cd ${ROOT_DIR}
go build -ldflags "-s -w" -o ${BUILD_DIR}/pactus-daemon ./cmd/daemon
go build -ldflags "-s -w" -o ${BUILD_DIR}/pactus-wallet ./cmd/wallet
go build -ldflags "-s -w" -tags gtk -o ${BUILD_DIR}/pactus-gui ./cmd/gtk
go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/pactus-daemon ./cmd/daemon
go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/pactus-wallet ./cmd/wallet
go build -ldflags "-s -w" -trimpath -tags gtk -o ${BUILD_DIR}/pactus-gui ./cmd/gtk

# Moving binaries to package directory
echo "Moving binaries"
Expand Down
6 changes: 3 additions & 3 deletions .github/releasers/releaser_gui_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mkdir ${PACKAGE_DIR}
echo "Building the binaries"

cd ${ROOT_DIR}
go build -ldflags "-s -w" -o ${BUILD_DIR}/pactus-daemon ./cmd/daemon
go build -ldflags "-s -w" -o ${BUILD_DIR}/pactus-wallet ./cmd/wallet
go build -ldflags "-s -w" -tags gtk -o ${BUILD_DIR}/pactus-gui ./cmd/gtk
go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/pactus-daemon ./cmd/daemon
go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/pactus-wallet ./cmd/wallet
go build -ldflags "-s -w" -trimpath -tags gtk -o ${BUILD_DIR}/pactus-gui ./cmd/gtk


echo "Installing gtk-mac-bundler"
Expand Down
6 changes: 3 additions & 3 deletions .github/releasers/releaser_gui_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ echo "Building the binaries"
# This fixes a bug in pkgconfig: invalid flag in pkg-config --libs: -Wl,-luuid
sed -i -e 's/-Wl,-luuid/-luuid/g' /mingw64/lib/pkgconfig/gdk-3.0.pc

go build -ldflags "-s -w" -o ${BUILD_DIR}/pactus-daemon.exe ./cmd/daemon
go build -ldflags "-s -w" -o ${BUILD_DIR}/pactus-wallet.exe ./cmd/wallet
go build -ldflags "-s -w -H windowsgui" -tags gtk -o ${BUILD_DIR}/pactus-gui.exe ./cmd/gtk
go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/pactus-daemon.exe ./cmd/daemon
go build -ldflags "-s -w" -trimpath -o ${BUILD_DIR}/pactus-wallet.exe ./cmd/wallet
go build -ldflags "-s -w -H windowsgui" -trimpath -tags gtk -o ${BUILD_DIR}/pactus-gui.exe ./cmd/gtk

# Copying the neccesary libraries
echo "Creating GUI directory"
Expand Down
98 changes: 97 additions & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ jobs:
########################################
build-cli:
runs-on: ubuntu-latest

# Defining outputs for jobs
# https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
checksums: ${{ steps.calc_checksums.outputs.checksums }}

steps:
- uses: actions/checkout@v3

Expand All @@ -25,6 +31,17 @@ jobs:
- name: Create release files
run: bash ./.github/releasers/releaser_cli.sh

# Multiline strings in GitHub actions
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
- name: Calculate sha256sum
id: calc_checksums
run: |
set -e
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "checksums<<$EOF" >> "$GITHUB_OUTPUT"
echo "$(sha256sum pactus-*.zip pactus-*tar.gz)" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Publish
uses: softprops/action-gh-release@v1
with:
Expand All @@ -37,6 +54,10 @@ jobs:
########################################
build-gui-linux:
runs-on: ubuntu-latest

outputs:
checksums: ${{ steps.calc_checksums.outputs.checksums }}

steps:
- uses: actions/checkout@v3

Expand All @@ -53,6 +74,15 @@ jobs:
- name: Create release files
run: bash ./.github/releasers/releaser_gui_linux.sh

- name: Calculate sha256sum
id: calc_checksums
run: |
set -e
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "checksums<<$EOF" >> "$GITHUB_OUTPUT"
echo "$(sha256sum pactus-*tar.gz)" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Publish
uses: softprops/action-gh-release@v1
with:
Expand All @@ -63,11 +93,15 @@ jobs:
########################################
build-gui-macos:
runs-on: macos-latest

outputs:
checksums: ${{ steps.calc_checksums.outputs.checksums }}

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: brew install gtk+3 librsvg create-dmg
run: brew install gtk+3 librsvg create-dmg coreutils

- name: Install Go
uses: actions/setup-go@v3
Expand All @@ -77,6 +111,15 @@ jobs:
- name: Create release files
run: bash ./.github/releasers/releaser_gui_macos.sh

- name: Calculate sha256sum
id: calc_checksums
run: |
set -e
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "checksums<<$EOF" >> "$GITHUB_OUTPUT"
echo "$(sha256sum pactus-*.dmg pactus-*tar.gz)" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Publish
uses: softprops/action-gh-release@v1
with:
Expand All @@ -89,9 +132,14 @@ jobs:
########################################
build-gui-windows:
runs-on: windows-latest

outputs:
checksums: ${{ steps.calc_checksums.outputs.checksums }}

defaults:
run:
shell: msys2 {0}

steps:
- uses: actions/checkout@v3

Expand All @@ -113,6 +161,15 @@ jobs:
- name: Create release files
run: bash ./.github/releasers/releaser_gui_windows.sh

- name: Calculate sha256sum
id: calc_checksums
run: |
set -e
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "checksums<<$EOF" >> "$GITHUB_OUTPUT"
echo "$(sha256sum pactus-*.zip pactus-*installer.exe)" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Publish
uses: softprops/action-gh-release@v1
with:
Expand All @@ -121,3 +178,42 @@ jobs:
pactus-*installer.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

########################################
checksums:
needs: [build-cli, build-gui-linux, build-gui-macos, build-gui-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create SHA256SUMS file
run: |
echo "${{ needs.build-cli.outputs.checksums }}" >> SHA256SUMS
echo "${{ needs.build-gui-linux.outputs.checksums }}" >> SHA256SUMS
echo "${{ needs.build-gui-macos.outputs.checksums }}" >> SHA256SUMS
echo "${{ needs.build-gui-windows.outputs.checksums }}" >> SHA256SUMS
- name: Publish
uses: softprops/action-gh-release@v1
with:
files: SHA256SUMS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

########################################
downloader:
needs: [checksums]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Create Downloader file
run: |
VERSION="$(echo `git -C . describe --abbrev=0 --tags` | sed 's/^.//')" # "v1.2.3" -> "1.2.3"
echo ${VERSION}
sed -i "s/__VERSION__/${VERSION}/g" .github/releasers/pactus_downloader.sh
- name: Publish
uses: softprops/action-gh-release@v1
with:
files: .github/releasers/pactus_downloader.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 2141555

Please sign in to comment.