Skip to content

Commit

Permalink
feat(config, build): refactor config; build executables
Browse files Browse the repository at this point in the history
* feat(config): Make changes to config to use pydantic settings

* chore: Refactor all uses of config to use the config object from the config module

* refactor(config): Remove unused code, fix typos and add comments for clearer information

* refactor: Add more comments and change variable names

* fix(record): Fix progress bar

* feature(config): Re-read config value only if it changes

* update README

---------

Co-authored-by: Richard Abrich <[email protected]>
  • Loading branch information
KIRA009 and abrichr authored May 1, 2024
1 parent 54c2b16 commit ee506f0
Show file tree
Hide file tree
Showing 103 changed files with 2,397 additions and 1,050 deletions.
2 changes: 0 additions & 2 deletions .env.example

This file was deleted.

103 changes: 96 additions & 7 deletions .github/workflows/release-and-publish.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,127 @@
name: Semantic Release and PyPI Publish
name: Release and PyPI Publish

on:
push:
branches:
- main

jobs:
build-macos-executables:
name: Build macOS app
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install poetry
poetry install
brew install nvm
poetry run install-dashboard
brew install [email protected]
- name: Build executables
run: |
poetry run python -m openadapt.build
cd dist
zip -r ../OpenAdapt.app.zip OpenAdapt.app
cd ..
- name: Upload executables
uses: actions/upload-artifact@v4
with:
name: OpenAdapt.app
path: OpenAdapt.app.zip

build-windows-executables:
name: Build Windows app
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 21
- name: Install dependencies
run: |
pip install poetry
poetry install
cd openadapt/app/dashboard
npm install
cd ../../../
- name: Build executables
run: |
poetry run python -m openadapt.build
cd dist
7z a -tzip ../OpenAdapt.zip OpenAdapt
cd ..
- name: Upload executables
uses: actions/upload-artifact@v4
with:
name: OpenAdapt
path: OpenAdapt.zip

release:
runs-on: ubuntu-latest
needs: [build-macos-executables, build-windows-executables]
concurrency: release
permissions:
id-token: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.ADMIN_TOKEN }} # Use the new token for authentication
- name: Download macOS executable
uses: actions/download-artifact@v4
with:
name: OpenAdapt.app
path: dist/
- name: Download Windows executable
uses: actions/download-artifact@v4
with:
name: OpenAdapt
path: dist/
- name: Python Semantic Release
id: semantic_release
uses: relekang/python-semantic-release@master
with:
github_token: ${{ secrets.ADMIN_TOKEN }} # Use the new token for authentication
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "OpenAdapt Bot"
git_committer_email: "[email protected]"

- name: Install the latest version of the project
run: |
git pull
pip install poetry
poetry install
- name: Upload release assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./build_scripts/upload_release_artifacts.sh
publish:
name: Publish to PyPI
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Publish to PyPI
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Envirionment
.env
config.local.json

# Python
__pycache__
Expand Down Expand Up @@ -33,3 +34,6 @@ src

*.pyc
*.pt

dist/
build/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ cd OpenAdapt
pip3 install poetry
poetry install
poetry shell
alembic upgrade head
poetry run install-dashbaord
cd openadapt && alembic upgrade head && cd ..
pytest
```

Expand Down Expand Up @@ -365,6 +365,8 @@ In summary (from https://stackoverflow.com/a/69673312):

### Generate migration (after editing a model)

From inside the `openadapt` directory (containing `alembic.ini`):

```
alembic revision --autogenerate -m "<msg>"
```
Expand Down
36 changes: 0 additions & 36 deletions alembic/versions/104d4a614d95_add_performancestat.py

This file was deleted.

35 changes: 0 additions & 35 deletions alembic/versions/607d1380b5ae_add_memorystat.py

This file was deleted.

This file was deleted.

38 changes: 0 additions & 38 deletions alembic/versions/ec337f277666_datetime_timestamp.py

This file was deleted.

12 changes: 12 additions & 0 deletions build_scripts/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Get the version of the package."""

import importlib.metadata


def get_version() -> str:
"""Get the version of the package."""
return importlib.metadata.version("openadapt")


if __name__ == "__main__":
print(get_version())
12 changes: 12 additions & 0 deletions build_scripts/macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# This script is used to run the OpenAdapt app on macOS from a terminal, because otherwise there are times
# when the app doesn't record events properly, and is extremely slow when updating events to the database.
# This bash script replaces the location of the actual executable file, which is copied to a different location
# when the app is built. This script is used to run the app from the terminal, and is not used in the actual app.

BASH_LOCATION=$(dirname $0)

osascript -e 'tell app "Terminal"
do script "cd '$BASH_LOCATION' && ./OpenAdapt.app; exit;"
end tell'
5 changes: 5 additions & 0 deletions build_scripts/upload_release_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION="v$(poetry run python -m build_scripts.get_version)"
mv dist/OpenAdapt.zip dist/OpenAdapt-$VERSION.zip
mv dist/OpenAdapt.app.zip dist/OpenAdapt-$VERSION.app.zip
echo "Uploading release artifacts for version $VERSION"
gh release upload $VERSION dist/OpenAdapt-$VERSION.zip dist/OpenAdapt-$VERSION.app.zip
Loading

0 comments on commit ee506f0

Please sign in to comment.