Skip to content

Commit

Permalink
chore: update installation scripts on binary release (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejVukosav authored Jan 29, 2025
1 parent 18146d2 commit 0c960fe
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,68 @@ jobs:
git push origin "${target_branch}"
gh pr create -f || true
installation-script-update:
if: needs.prepare.outputs.is_release_candidate == 'true' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: [prepare, build, release]
steps:
- name: Get release matrix outputs
id: release-matrix-outputs
uses: cloudposse/github-action-matrix-outputs-read@v1
with:
matrix-step-name: release

- name: Create GitHub App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}

- name: Configure Git
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh auth setup-git
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Process each binary and create PRs
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
for binary in $(echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r '.[]'); do
release_required=$(echo '${{ steps.release-matrix-outputs.outputs.result }}' | jq -r --arg key "${binary}" '.releaseRequired[$key]')
version=$(echo '${{ steps.release-matrix-outputs.outputs.result }}' | jq -r --arg key "${binary}" '.version[$key]')
if [ "${release_required}" == "true" ]; then
echo "Updating installation script for ${binary}, version: ${version}"
target_branch="chore/bump-${binary}-installation-script-to-v${version}"
git fetch origin "${target_branch}" || true
git checkout "${target_branch}" || git checkout -b "${target_branch}"
./scripts/generate-installation-script.sh "${binary}" "${version}"
git add scripts/
git commit -m "chore: bump ${binary} installation script to v${version}" || true
git push origin "${target_branch}"
gh pr create \
--title "chore: bump ${binary} installation script to v${version}" \
--body "This PR updates the installation script for **${binary}** to version **${version}**." \
--head "${target_branch}" \
--base master \
-f || true
else
echo "No update required for ${binary}"
fi
done
90 changes: 90 additions & 0 deletions scripts/generate-installation-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

# Check for binary name and version as inputs
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <binary_name> <version>"
exit 1
fi

BINARY_NAME="$1"
VERSION="$2"
OUTPUT_SCRIPT="./scripts/install-${BINARY_NAME}.sh"

# Generate installation script
cat <<EOF > "$OUTPUT_SCRIPT"
#!/bin/bash
# Autogenerated. Do not modify.
# This script was generated by generate_install_script.sh.
BINARY_NAME="${BINARY_NAME}"
VERSION="${VERSION}"
REPO="calimero-network/core"
INSTALL_DIR="\$HOME/.local/bin"
# Detect OS and Architecture
OS=\$(uname | tr '[:upper:]' '[:lower:]')
ARCH=\$(uname -m)
case "\$ARCH" in
"x86_64") ARCH="x86_64" ;;
"arm64" | "aarch64") ARCH="aarch64" ;;
*)
echo "Unsupported architecture: \$ARCH."
exit 1
;;
esac
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
TARBALL_NAME="\${BINARY_NAME}_\${ARCH}-\${PLATFORM}.tar.gz"
DOWNLOAD_URL="https://github.com/\$REPO/releases/download/\${BINARY_NAME}-\$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 binary
echo "Extracting \$TARBALL_NAME..."
tar -xzf "\$TARBALL_NAME"
chmod +x "\$BINARY_NAME"
# Move binary to user-local bin directory
mv "\$BINARY_NAME" "\$INSTALL_DIR/\$BINARY_NAME"
rm "\$TARBALL_NAME"
# Add \$HOME/.local/bin to PATH if not already present
if ! echo "\$PATH" | grep -q "\$INSTALL_DIR"; then
SHELL_CONFIG_FILE="\$HOME/.bashrc"
case "\$SHELL" in
*/zsh) SHELL_CONFIG_FILE="\$HOME/.zshrc" ;;
*/fish) SHELL_CONFIG_FILE="\$HOME/.config/fish/config.fish" ;;
*/csh|*/tcsh) SHELL_CONFIG_FILE="\$HOME/.cshrc" ;;
esac
echo 'export PATH="\$HOME/.local/bin:\$PATH"' >> "\$SHELL_CONFIG_FILE"
echo "Added \$HOME/.local/bin to PATH in \$SHELL_CONFIG_FILE. Please reload your shell or run: source \$SHELL_CONFIG_FILE"
fi
# Final message
echo "\$BINARY_NAME installed successfully in \$INSTALL_DIR."
echo "To verify the installation, make sure \$INSTALL_DIR is in your PATH."
echo "Run the following command to update your current shell session if needed:"
echo "source <your-shell-config-file>"
echo "Then run '\$BINARY_NAME --version' to confirm the installation."
EOF

# Make the generated script executable
chmod +x "$OUTPUT_SCRIPT"
echo "Installation script generated: $OUTPUT_SCRIPT"

0 comments on commit 0c960fe

Please sign in to comment.