Skip to content

Commit

Permalink
feat: using proper vue.js framework
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Mar 9, 2023
1 parent 1cabfe6 commit 9badfe8
Show file tree
Hide file tree
Showing 49 changed files with 7,737 additions and 1,321 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Buld a release

on:
pull_request:
types: [closed]
branches:
- master

jobs:
build-macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get version
id: get-version
run: |
echo "tag=v$(cat version.txt)" >> $GITHUB_OUTPUT
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: |
pip install pyinstaller websockets bleak
cd ui ; npm install ; cd ..
- name: Build application
run: |
cd ui ; npm run build ; cd ..
pyinstaller api/ws_serve.py
pyinstaller --add-data ui/dist:ui ui/serve.py
- name: Package application
id: package-app
run: |
zipname=$(basename ${GITHUB_REPOSITORY})-MacOS-${{ steps.get-version.outputs.tag }}.zip
cd dist && zip -r $zipname ws_serve/ serve/
cd ..
zip -u dist/$zipname start.sh
mv dist/$zipname ./
echo "dist_path=$zipname" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact-macos
path: ${{ steps.package-app.outputs.dist_path }}

# build-win:
# runs-on: windows-latest
# build-linux:
# runs-on: ubuntu-latest
create-release:
needs:
# - build-linux
# - build-win
- build-macos
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get version
id: get-version
run: |
echo "tag=v$(cat version.txt)" >> $GITHUB_OUTPUT
- name: Update changelog
id: update-changelog
run: |
API_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits"
COMMITS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$API_URL" | jq -r 'map(select(.commit.message | startswith("chore:") | not)) | .[] | "* \(.commit.message) [\(.sha[:7])](\(.html_url))"')
echo "# Changelog" > changelog.tmp
echo "" >> changelog.tmp
echo "## v$(cat version.txt)" >> changelog.tmp
echo "" >> changelog.tmp
echo "$COMMITS" >> changelog.tmp
echo "$COMMITS" > release_msg.tmp
tail -n +2 CHANGELOG.md >> changelog.tmp
mv changelog.tmp CHANGELOG.md
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add CHANGELOG.md
git commit -m "chore: update changelog"
git push
echo "release_text_path=$(realpath release_msg.tmp)" >> $GITHUB_OUTPUT
# - name: Download ubuntu artifact
# uses: actions/download-artifact@v3
# with:
# name: build-artifact-ubuntu
# path: .
- name: Download macos artifact
uses: actions/download-artifact@v3
with:
name: build-artifact-macos
path: .
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get-version.outputs.tag }}
body_path: ${{ steps.update-changelog.outputs.release_text_path }}
files: |
./*.zip
61 changes: 61 additions & 0 deletions .github/workflows/increment-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Increment Version

on:
push:
branches:
- dev

jobs:
increment-version:
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'chore:')"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Increment version
id: increment-version
run: |
raw_commits=$(cat <<EOFF
${{ toJSON(github.event.commits) }}
EOFF)
commits=$(echo "$raw_commits" | jq ".[].message" | tr -d '"')
IFS='.' read -r major minor patch <<< "$(cat version.txt)"
readarray -t commit_messages <<< "$commits"
is_incremented=0
for COMMIT_MESSAGE in "${commit_messages[@]}"; do
if [[ "$COMMIT_MESSAGE" == "fix:"* ]]; then
is_incremented=1
patch=$((patch + 1))
elif [[ "$COMMIT_MESSAGE" == "feat:"* ]]; then
is_incremented=1
minor=$((minor + 1))
patch=0
elif [[ "$COMMIT_MESSAGE" == "fix!"* ]] || [[ "$COMMIT_MESSAGE" == "feat!"* ]]; then
is_incremented=1
major=$((major + 1))
minor=0
patch=0
fi
done
echo "$major.$minor.$patch" > version.txt
echo "tag=v$major.$minor.$patch" >> $GITHUB_OUTPUT
echo "is_incremented=$is_incremented" >> $GITHUB_OUTPUT
- name: Commit version changes
if: ${{ steps.increment-version.outputs.is_incremented != 0 }}
run: |
echo "checking version"
cat version.txt
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add version.txt
git commit -m "chore: bump version to $(cat version.txt)"
git tag ${{ steps.increment-version.outputs.tag }}
- name: Push changes
if: ${{ steps.increment-version.outputs.is_incremented != 0 }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
15 changes: 0 additions & 15 deletions .github/workflows/release-please.yml

This file was deleted.

23 changes: 11 additions & 12 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ Why focus on soldering when you can play with the settings instead? With this ap
- [X] Temperature automatically adjusts based on °C or °F setting.
- [X] Hide Minimum Voltage (per cell) when source is not battery.

## Requirements
## Requirements to run development version
### backend:
- python 3 (tested with 3.10)
- pipenv
- [node+npm](https://nodejs.org/en/download/)
### UI:
- any browser (IE is not a browser)

Expand All @@ -62,18 +63,18 @@ Why focus on soldering when you can play with the settings instead? With this ap

```shell
git clone https://github.com/builder555/PineSAM
cd PineSAM/backend
pipenv install
chmod +x start.sh
chmod +x setup-dev.sh
chmod +x run-dev.sh
./setup.sh
```

### Run
```shell
# from inside the PineSAM/backend directory:
./start.sh
./run-dev.sh
# press CTRL+C in the terminal window to stop
```

On a Mac http://localhost:8080/settings.html will open in your browser automatically. On linux you need to do it manually (for now).
On a Mac http://localhost:8080 will open in your browser automatically. On some linux distros you may need to do it manually.

For Debian 12 instructions, see [this post](https://github.com/builder555/PineSAM/discussions/47#discussion-4884758).

Expand All @@ -94,7 +95,8 @@ If you already have python installed, you can skip to step 2.
2. Change directory, `cd` to the location of the PineSAM folder that was unzipped above.
```shell
# from inside the PineSAM\backend directory:
.\start.bat
.\setup-dev.bat
.\run-dev.bat
```


Expand All @@ -103,7 +105,7 @@ If you already have python installed, you can skip to step 2.
You can access the settings remotely (i.e, run from a phone) once the app is running on the main PC/laptop. All devices need to be on the same network.

* Find the [local IP address](https://lifehacker.com/how-to-find-your-local-and-external-ip-address-5833108) of the device running the app.
* open http://\<ip-address\>:8080/settings.html on the second device on the same network (i.e. phone).
* open http://\<ip-address\>:8080/ on the second device on the same network (i.e. phone).
* this works to run PineSAM on an iPhone or Android if you don't want to install python on the phone.
* Pinecil needs to be within BLE range of the computer running the PineSAM app; the 2nd device/phone just needs to be within Wifi/network range of the main computer.

Expand All @@ -118,11 +120,8 @@ You can access the settings remotely (i.e, run from a phone) once the app is run

## Testing

Make sure you have `pipenv` installed.

```shell
# run inside 'backend' directory:
pipenv install --dev
pipenv run test
```

Expand Down
3 changes: 2 additions & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ websockets = "*"
pytest = "*"
pytest-watch = "*"
pytest-asyncio = "*"
pyinstaller = "*"

[requires]
python_version = "3"

[scripts]
"server" = "python main_server.py"
"test" = "pytest"
"test" = "pytest"
12 changes: 0 additions & 12 deletions backend/start.sh

This file was deleted.

19 changes: 19 additions & 0 deletions run-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
if ! command -v pipenv &> /dev/null
then
alias pipenv=$(python3 -m site --user-base)/bin/pipenv
fi
cd backend
LOG_LEVEL=info pipenv run server &
pid1=$!

cd ../ui
npm run dev &
pid2=$!
cd ..

sleep 2
open http://localhost:8080/

trap "kill $pid1 $pid2" EXIT
wait $pid1 $pid2
28 changes: 28 additions & 0 deletions setup-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
cd backend
# ensure python is version 3
if ! command -v python3 &> /dev/null
then
echo "python3 could not be found"
cd ..
exit
fi
python3 -m pip install --user pipenv
if ! command -v pipenv &> /dev/null
then
alias pipenv=$(python3 -m site --user-base)/bin/pipenv
fi
# install dependencies
pipenv install --dev

cd ../ui
# ensure npm is installed
if ! command -v npm &> /dev/null
then
echo "npm could not be found"
cd ..
exit
fi
rm -rf node_modules
# install dependencies
npm install -D
29 changes: 29 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
cd "$(dirname "$0")"
# ensure ws_serve and serve are built
if [ ! -f ./ws_serve/ws_serve ] || [ ! -f ./serve/serve ]; then
echo "This file is used to run a built version of the project."
echo "Please run setup-dev.sh and use run-dev.sh to run the project"
exit
fi

if [ "$(uname)" == "Darwin" ]; then
# for MacOS, remove the quarantine attributes
# this is needed because the mac will not execute binaries that are downloaded from the internet
# see https://developer.apple.com/library/archive/technotes/tn2459/_index.html
if xattr -p com.apple.quarantine ./ws_serve/ws_serve >/dev/null 2>&1; then
find ./ -type file | xargs xattr -rd com.apple.quarantine
fi
fi

./ws_serve/ws_serve &
pid1=$!

./serve/serve &
pid2=$!

sleep 5
open http://localhost:8080/

trap "kill $pid1 $pid2" EXIT
wait $pid1 $pid2
14 changes: 14 additions & 0 deletions ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}
Loading

0 comments on commit 9badfe8

Please sign in to comment.