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

Generate checksum on build #287

Merged
merged 3 commits into from
Jul 13, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix echo does not break test execution results
- Add bashunit facade to enable custom assertions
- Document how to verify the `sha256sum` of the final executable
- Generate checksum on build
- Enable display execution time on macOS with `SHOW_EXECUTION_TIME`
- Support for displaying the clock without `perl` (for non-macOS)
- Add `-l|--log-junit <log.xml>` option
Expand Down
45 changes: 36 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
#!/bin/bash

mkdir -p bin
source src/check_os.sh

output_file="bin/bashunit"
function generate_bin() {
local output_file=$1
echo '#!/usr/bin/env bash' > bin/temp.sh

echo "Generating bashunit in the 'bin' folder..."
cat src/*.sh >> bin/temp.sh
cat bashunit >> bin/temp.sh
grep -v '^source' bin/temp.sh > "$output_file"
rm bin/temp.sh
chmod u+x "$output_file"
}

function generate_checksum() {
if [[ "$_OS" == "Windows" ]]; then
return
fi

local file=$1
if [[ "$_OS" == "OSX" ]]; then
checksum=$(shasum -a 256 "$file")
elif [[ "$_OS" == "Linux" ]]; then
checksum=$(sha256sum "$file")
fi

echo '#!/usr/bin/env bash' > bin/temp.sh
echo "$checksum" > bin/checksum
echo "$checksum"
}

########################
######### MAIN #########
########################

mkdir -p bin
output_file="bin/bashunit"

echo "Generating bashunit in the 'bin' folder..."
cat src/*.sh >> bin/temp.sh
cat bashunit >> bin/temp.sh
grep -v '^source' bin/temp.sh > "$output_file"
rm bin/temp.sh
chmod u+x "$output_file"
generate_bin "$output_file"
generate_checksum "$output_file"

echo "⚡️Build completed⚡️"