From 279d2dd5746d14107b2e4468de6a51f68d4dd999 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 11:36:35 +0700 Subject: [PATCH 1/8] feat: add install script --- .github/workflows/test_install.yml | 33 ++++++++++++++++ scripts/install.sh | 61 ++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .github/workflows/test_install.yml create mode 100755 scripts/install.sh diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml new file mode 100644 index 000000000..55ecc50d2 --- /dev/null +++ b/.github/workflows/test_install.yml @@ -0,0 +1,33 @@ +name: Test Install Script + +on: + push: + branches: + - xilosada/test-install-script + pull_request: + branches: + - xilosada/test-install-script + +jobs: + test-install: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + arch: [x86_64, aarch64] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + # Run the installation script + - name: Test installation script + run: | + curl -s https://raw.githubusercontent.com/calimero-network/core/xilosada\/test-install-script/scripts/install.sh | bash + + # Validate the binary installation + - name: Validate installation + run: | + which meroctl + meroctl --version diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 000000000..70bdec5f8 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +# Define version and repository +VERSION="v0.1.1" +REPO="calimero-network/core" +BINARY_NAME="meroctl" + +# Detect OS +OS=$(uname | tr '[:upper:]' '[:lower:]') + +# Detect Architecture +ARCH=$(uname -m) +case "$ARCH" in + "x86_64") ARCH="x86_64" ;; + "arm64" | "aarch64") ARCH="aarch64" ;; + *) + echo "Unsupported architecture: $ARCH." + exit 1 + ;; +esac + +# Determine platform +if [ "$OS" == "darwin" ]; then + PLATFORM="apple-darwin" +elif [ "$OS" == "linux" ]; then + PLATFORM="unknown-linux-gnu" +else + echo "Unsupported operating system: $OS." + exit 1 +fi + +# Construct download URL and tarball name +TARBALL_NAME="${BINARY_NAME}_${ARCH}-${PLATFORM}.tar.gz" +DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$TARBALL_NAME" + +# Download binary tarball +echo "Downloading $TARBALL_NAME from $DOWNLOAD_URL..." +curl -L -o "$TARBALL_NAME" "$DOWNLOAD_URL" + +# Extract tarball +echo "Extracting $TARBALL_NAME..." +tar -xzf "$TARBALL_NAME" + +# Make binary executable +chmod +x "$BINARY_NAME" + +# Move to /usr/local/bin (or another PATH directory) +INSTALL_DIR="/usr/local/bin" +if [ ! -w "$INSTALL_DIR" ]; then + echo "You need sudo permissions to install to $INSTALL_DIR" + sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" +else + mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" +fi + +# Clean up tarball +rm "$TARBALL_NAME" + +echo "$BINARY_NAME installed successfully! Run '$BINARY_NAME' to get started." From 789ec63af15501b16f454065a142aaa0f37cae30 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 13:41:26 +0700 Subject: [PATCH 2/8] test: replace branch --- .../{test_install.yml => cross-platform-install-test.yml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{test_install.yml => cross-platform-install-test.yml} (81%) diff --git a/.github/workflows/test_install.yml b/.github/workflows/cross-platform-install-test.yml similarity index 81% rename from .github/workflows/test_install.yml rename to .github/workflows/cross-platform-install-test.yml index 55ecc50d2..8f95f974f 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/cross-platform-install-test.yml @@ -3,10 +3,10 @@ name: Test Install Script on: push: branches: - - xilosada/test-install-script + - master pull_request: branches: - - xilosada/test-install-script + - master jobs: test-install: @@ -24,7 +24,7 @@ jobs: # Run the installation script - name: Test installation script run: | - curl -s https://raw.githubusercontent.com/calimero-network/core/xilosada\/test-install-script/scripts/install.sh | bash + curl -s https://raw.githubusercontent.com/calimero-network/core/master/scripts/install.sh | bash # Validate the binary installation - name: Validate installation From 9e84ef7942edcf3b3c847aa170abd5f413cf1c44 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 13:57:35 +0700 Subject: [PATCH 3/8] fix: install meroctl in a local folder --- scripts/install.sh | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 70bdec5f8..dfdce2834 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,17 +1,14 @@ #!/bin/bash -set -e - -# Define version and repository +BINARY_NAME="meroctl" VERSION="v0.1.1" REPO="calimero-network/core" -BINARY_NAME="meroctl" +INSTALL_DIR="$HOME/.local/bin" -# Detect OS +# Detect OS and Architecture OS=$(uname | tr '[:upper:]' '[:lower:]') - -# Detect Architecture ARCH=$(uname -m) + case "$ARCH" in "x86_64") ARCH="x86_64" ;; "arm64" | "aarch64") ARCH="aarch64" ;; @@ -21,7 +18,6 @@ case "$ARCH" in ;; esac -# Determine platform if [ "$OS" == "darwin" ]; then PLATFORM="apple-darwin" elif [ "$OS" == "linux" ]; then @@ -31,31 +27,30 @@ else exit 1 fi -# Construct download URL and tarball name +# Construct download URL TARBALL_NAME="${BINARY_NAME}_${ARCH}-${PLATFORM}.tar.gz" DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$TARBALL_NAME" +# Ensure installation directory exists +mkdir -p "$INSTALL_DIR" + # Download binary tarball echo "Downloading $TARBALL_NAME from $DOWNLOAD_URL..." curl -L -o "$TARBALL_NAME" "$DOWNLOAD_URL" -# Extract tarball +# Extract binary echo "Extracting $TARBALL_NAME..." tar -xzf "$TARBALL_NAME" - -# Make binary executable chmod +x "$BINARY_NAME" -# Move to /usr/local/bin (or another PATH directory) -INSTALL_DIR="/usr/local/bin" -if [ ! -w "$INSTALL_DIR" ]; then - echo "You need sudo permissions to install to $INSTALL_DIR" - sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" -else - mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" -fi - -# Clean up tarball +# Move binary to user-local bin directory +mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" rm "$TARBALL_NAME" -echo "$BINARY_NAME installed successfully! Run '$BINARY_NAME' to get started." +# Add $HOME/.local/bin to PATH if not already present +if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then + echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc" + echo "Added $HOME/.local/bin to PATH. Reload your shell or run: source ~/.bashrc" +fi + +echo "$BINARY_NAME installed successfully in $INSTALL_DIR. Run '$BINARY_NAME --version' to verify." From e067d0318ffb86c4425e0c27f9da69d8bf99e884 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 14:10:19 +0700 Subject: [PATCH 4/8] test: restore working branch --- .github/workflows/cross-platform-install-test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cross-platform-install-test.yml b/.github/workflows/cross-platform-install-test.yml index 8f95f974f..996fd26d7 100644 --- a/.github/workflows/cross-platform-install-test.yml +++ b/.github/workflows/cross-platform-install-test.yml @@ -4,10 +4,13 @@ on: push: branches: - master + - xilosada/test-gh-actions + pull_request: branches: - master - + - xilosada/test-gh-actions + jobs: test-install: strategy: @@ -24,7 +27,7 @@ jobs: # Run the installation script - name: Test installation script run: | - curl -s https://raw.githubusercontent.com/calimero-network/core/master/scripts/install.sh | bash + curl -s https://raw.githubusercontent.com/calimero-network/core/${GITHUB_REF_NAME}/scripts/install.sh | bash # Validate the binary installation - name: Validate installation From 9ce2dad46277c7468840052ae92517b7184ed9e9 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 14:13:11 +0700 Subject: [PATCH 5/8] test: envar --- .github/workflows/cross-platform-install-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cross-platform-install-test.yml b/.github/workflows/cross-platform-install-test.yml index 996fd26d7..6f06dbe22 100644 --- a/.github/workflows/cross-platform-install-test.yml +++ b/.github/workflows/cross-platform-install-test.yml @@ -10,7 +10,7 @@ on: branches: - master - xilosada/test-gh-actions - + jobs: test-install: strategy: @@ -27,7 +27,7 @@ jobs: # Run the installation script - name: Test installation script run: | - curl -s https://raw.githubusercontent.com/calimero-network/core/${GITHUB_REF_NAME}/scripts/install.sh | bash + curl -s https://raw.githubusercontent.com/calimero-network/core/$BRANCH_NAME/scripts/install.sh | bash # Validate the binary installation - name: Validate installation From d21e1878958dbf6702c9873fc14764c1756820e6 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 14:20:48 +0700 Subject: [PATCH 6/8] test: envar 2 --- .github/workflows/cross-platform-install-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cross-platform-install-test.yml b/.github/workflows/cross-platform-install-test.yml index 6f06dbe22..78dcc7d40 100644 --- a/.github/workflows/cross-platform-install-test.yml +++ b/.github/workflows/cross-platform-install-test.yml @@ -27,7 +27,7 @@ jobs: # Run the installation script - name: Test installation script run: | - curl -s https://raw.githubusercontent.com/calimero-network/core/$BRANCH_NAME/scripts/install.sh | bash + curl -s https://raw.githubusercontent.com/calimero-network/core/${{ github.ref_name }}/scripts/install.sh | bash # Validate the binary installation - name: Validate installation From 9273fdffabd29e59a6198acc955d3e1890ac4694 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 14:23:59 +0700 Subject: [PATCH 7/8] test: envar 3 --- .github/workflows/cross-platform-install-test.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cross-platform-install-test.yml b/.github/workflows/cross-platform-install-test.yml index 78dcc7d40..8218bd9c4 100644 --- a/.github/workflows/cross-platform-install-test.yml +++ b/.github/workflows/cross-platform-install-test.yml @@ -24,10 +24,20 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 + # Determine Branch Name + - name: Set Branch Name + id: branch-name + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV + else + echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV + fi + # Run the installation script - name: Test installation script run: | - curl -s https://raw.githubusercontent.com/calimero-network/core/${{ github.ref_name }}/scripts/install.sh | bash + curl -s https://raw.githubusercontent.com/calimero-network/core/${{ env.BRANCH_NAME }}/scripts/install.sh | bash # Validate the binary installation - name: Validate installation From a8c5bc42f386c0df6b5567d90641fb5fad8665c4 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 14:26:08 +0700 Subject: [PATCH 8/8] fix: prepare for review --- .github/workflows/cross-platform-install-test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/cross-platform-install-test.yml b/.github/workflows/cross-platform-install-test.yml index 8218bd9c4..2c630eaf9 100644 --- a/.github/workflows/cross-platform-install-test.yml +++ b/.github/workflows/cross-platform-install-test.yml @@ -4,12 +4,10 @@ on: push: branches: - master - - xilosada/test-gh-actions pull_request: branches: - master - - xilosada/test-gh-actions jobs: test-install: