Skip to content

Commit

Permalink
test: web build pluto unit test in CI
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Aug 23, 2024
1 parent 1079ae1 commit e9607b7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 13 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
- name: Check out code
uses: actions/checkout@v4
- name: Install dependencies
run: python3 -m pip install -r requirements
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2
install: true
- name: Test application
run: pluto run
run: |
npm install
python3 -m pip install -r requirements.txt
python3 -m pip install pytest
- name: Build web
run: cd web && npm install && npm run build
- name: Test
run: ./scripts/test2.sh
2 changes: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Reference from:
# https://goreleaser.com/ci/actions/
name: Release
on:
push:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ zz_*
node_modules

# pluto
.pluto/**/*
.pluto/**/*
__pycache__
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM plutolang/pluto
WORKDIR /
COPY . .
RUN python3 -m pip install -r requirements
RUN npm install
RUN cd web && npm run build
RUN python3 -m pip install -U -r ./requirements.txt
CMD ["pluto", "run"]
EXPOSE 9443
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Quick Start

```shell
python -m pip install -r requirements
python3 -m pip install -U -r ./requirements.txt
npm install
npm install -g pluto
make
Expand Down
57 changes: 57 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Start pluto locally
TMP_OUTPUT_FILE=/tmp/pluto_output.log
pluto run >$TMP_OUTPUT_FILE 2>&1 &
PID1=$!

# Wait for Pluto to start the project completely
while :; do
if grep -q "Successfully applied!" $TMP_OUTPUT_FILE; then
echo "The project has been successfully started."
break
else
echo "Waiting for Pluto to start the project..."
sleep 1
fi
done

# Get the project name from package.json
PROJECT_NAME=$(grep '"name":' package.json | awk -F '"' '{print $4}')
echo "Project name: $PROJECT_NAME"

# Set environment variables
PORT=$(lsof -Pan -p $PID1 -i | grep LISTEN | awk '{print $9}' | sed 's/.*://')
export PLUTO_PROJECT_NAME=$PROJECT_NAME
export PLUTO_STACK_NAME=local_run
export PLUTO_PLATFORM_TYPE=Simulator
export PLUTO_SIMULATOR_URL=http://localhost:$PORT

# Run tests
print_separator() {
local message=$1
local message_len=${#message}

local width=$(tput cols)
local separator=$(printf '=%.0s' $(seq 1 $(((width - message_len - 4) / 2))))
local bold=$(tput bold)

printf "\033[34m${bold}${separator}= %s =${separator}\033[0m\n" "$message"
}

# Output Pluto logs, which might contain useful information
tail -f $TMP_OUTPUT_FILE -n 0 &
PID2=$!

# Execute tests in the app directory
print_separator "Executing test files in the app directory"
python3 -m pytest -s -q --no-header app

# Execute tests within the app/main.py file
print_separator "Executing tests within the app/main.py file"
python3 -m pytest -s -q --no-header app/main.py

# Cleanup
kill $PID1
wait $PID1
kill $PID2
1 change: 1 addition & 0 deletions scripts/test2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pluto run

0 comments on commit e9607b7

Please sign in to comment.