Skip to content

Commit

Permalink
chore: fix run_tests.sh; refactor Bash scripts (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomiguelino authored Jan 24, 2025
1 parent 186a860 commit c93f6ec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
21 changes: 21 additions & 0 deletions bin/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Validate that PLATFORM is either 'chrome' or 'firefox'
validate_platform() {
local platform=$1
if [[ ! $platform =~ ^(chrome|firefox)$ ]]; then
echo "Invalid platform: $platform"
echo "Platform should be either chrome or firefox"
exit 1
fi
}

# Generate manifest.json from platform-specific template
generate_manifest() {
local platform=$1
local version=${2:-0.0.0}

cat "src/manifest-$platform.json" \
| jq --arg version "$version" '.version = $version' \
> src/manifest.json
}
11 changes: 3 additions & 8 deletions bin/package_extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ IFS=$'\n\t'
VERSION=${VERSION:-0.0.0}
PLATFORM=${PLATFORM:-chrome}

if [[ ! $PLATFORM =~ ^(chrome|firefox)$ ]]; then
echo "Invalid platform: $PLATFORM"
echo "Platform should be either chrome or firefox"
exit 1
fi
source "$(dirname "$0")/common.sh"

cat src/manifest-$PLATFORM.json \
| jq --arg version "$VERSION" '.version = $version' \
> src/manifest.json
validate_platform "$PLATFORM"
generate_manifest "$PLATFORM" "$VERSION"

docker compose build
docker run \
Expand Down
9 changes: 9 additions & 0 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

set -euo pipefail

VERSION=${VERSION:-0.0.0}
PLATFORM=${PLATFORM:-chrome}

source "$(dirname "$0")/common.sh"

validate_platform "$PLATFORM"
generate_manifest "$PLATFORM" "$VERSION"

docker compose build

docker run \
--rm -ti \
-v $(pwd):/app:delegated \
Expand Down
11 changes: 3 additions & 8 deletions bin/start_development_mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ IFS=$'\n\t'
VERSION=${VERSION:-0.0.0}
PLATFORM=${PLATFORM:-chrome}

if [[ ! $PLATFORM =~ ^(chrome|firefox)$ ]]; then
echo "Invalid platform: $PLATFORM"
echo "Platform should be either chrome or firefox"
exit 1
fi
source "$(dirname "$0")/common.sh"

cat src/manifest-$PLATFORM.json \
| jq --arg version "$VERSION" '.version = $version' \
> src/manifest.json
validate_platform "$PLATFORM"
generate_manifest "$PLATFORM" "$VERSION"

docker compose down -v
docker compose up --build

0 comments on commit c93f6ec

Please sign in to comment.