Skip to content
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

Enhance build script with command checks, version validation, and err… #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
58 changes: 52 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
#!/bin/bash

echo "Building the sample program..."
go build -o sample sample.go
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

if [ $? -eq 0 ]; then
echo "Build successful."
else
echo "Build failed."
# Function to check the version of a command
check_version() {
local cmd=$1
local required_version=$2
local version=$($cmd --version | head -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
if [[ $(echo -e "$version\n$required_version" | sort -V | head -n1) != "$required_version" ]]; then
echo "Error: $cmd version $required_version or higher is required. Found version $version." >&2
exit 1
fi
}

# Check for required environment variables
: "${ENV_VAR:?Need to set ENV_VAR}"

# Check for required dependencies
REQUIRED_CMDS=("gcc" "make" "curl")
for cmd in "${REQUIRED_CMDS[@]}"; do
if ! command_exists "$cmd"; then
echo "Error: $cmd is not installed." >&2
exit 1
fi
done

# Check versions
check_version "gcc" "9.3.0"

# Build steps
echo "Starting build process..."

# Example build step
if ! gcc -o my_program my_program.c; then
echo "Build failed." >&2
exit 1
fi

# Run tests
echo "Running tests..."
if ! ./run_tests.sh; then
echo "Tests failed." >&2
exit 1
fi

# Package the application
echo "Packaging application..."
if ! tar -czf my_program.tar.gz my_program; then
echo "Packaging failed." >&2
exit 1
fi

echo "Build process completed successfully."
42 changes: 42 additions & 0 deletions command_output.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Command: shopt -s histappend
Output:

Exit Code: 0
----
Command: pwd
Output:
/Users/macbook/Desktop/verification-layer-tester
Exit Code: 0
----
Command: npm run dev
Output:
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in: /Users/macbook/.npm/_logs/2025-02-09T13_40_55_372Z-debug-0.log
Exit Code: 1
----
Command: npm install
Output:

up to date, audited 401 packages in 2s

74 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities
Exit Code: 0
----
Command: npm run dev
Output:
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in: /Users/macbook/.npm/_logs/2025-02-09T13_41_11_291Z-debug-0.log
Exit Code: 1
----
Binary file modified sample
Binary file not shown.
Binary file modified verification-layer-tester
Binary file not shown.