diff --git a/.gitignore b/.gitignore index 2179cf9..ec65ffb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ __pycache__ _build +.bundles/* *.pyc .env +env.sh diff --git a/README.rst b/README.rst index 862c47a..c1c85a9 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ -Adafruit AdaBot +Adafruit Adabot ============ .. image :: https://img.shields.io/discord/327254708534116352.svg @@ -10,15 +10,78 @@ AdaBot is a friendly helper bot that works across the web to make people's lives better. It focuses on those contributing to Adafruit's variety of projects including CircuitPython. -Usage Example -============= +Setup +======= -To run the CircuitPython library validation code: +Here are the instructions for one time setup. Its simpler to start once +everything is installed. + +Debian/Ubuntu Dependencies ++++++++++++++++++++++++++++ .. code-block:: shell - export ADABOT_GITHUB_ACCESS_TOKEN= - python3 -m adabot.circuitpython_libraries + sudo apt-get update # make sure you have the latest packages + sudo apt-get upgrade # make sure already installed packages are latest + sudo apt-get install git python3 python3-venv python3-pip screen + +Rosie CI +++++++++++ + +Once the dependencies are installed, now clone the git repo into your home directory. + +.. code-block:: shell + + git clone https://github.com/adafruit/adabot.git + cd adabot + +First, set up a virtual environment and install the deps. + +.. code-block:: shell + + python3 -m venv .env + source .env/bin/activate + pip install -r requirements.txt + +Secrets! ++++++++++ + +Adabot needs a few secrets to do her work. Never, ever check these into source +control! + +They are stored as environment variables in ``env.sh``. + +So, copy the example ``template-env.sh``, edit it and save it as ``env.sh``. + +.. code-block:: shell + + cp template-env.sh env.sh + nano env.sh + +Do CTRL-X to exit and press Y to save the file before exiting. + +Usage Example +============= + +To run Adabot we'll use screen to manage all of the individual pieces. Luckily, +we have a screenrc file that manages starting everything up. + +.. code-block:: shell + + screen -c adabot.screenrc + +This command will return back to your prompt with something like +``[detached from 10866.pts-0.raspberrypi]``. This means that Rosie is now +running within screen session behind the scenes. You can view output of it by +attaching to the screen with: + +.. code-block:: shell + + screen -r + +Once reattached you can stop everything by CTRL-Cing repeatedly or detach again +with CTRL-A then D. If any errors occur, a sleep command will be run so you can +view the output before screen shuts down. Contributing ============ diff --git a/adabot.screenrc b/adabot.screenrc new file mode 100644 index 0000000..3d9acd8 --- /dev/null +++ b/adabot.screenrc @@ -0,0 +1,17 @@ +# Screen startup file to start multiple commands under multiple screens. +# Start with "screen -c thisfilename" + +screen -t flask 0 bash -c "source .env/bin/activate; source env.sh; export FLASK_APP=rosie-ci.py; flask run || sleep 1000" + +# With a free ngrok account you will get a random subdomain. +# screen -t ngrok 1 ngrok http 5000 + +# Use this command with your own subdomain. +screen -t ngrok 1 bash -c "../ngrok http -subdomain=rosie-ci 5000 || sleep 1000" + +screen -t celery_high 2 bash -c "source .env/bin/activate; source env.sh; celery -A rosie-ci.celery worker -n high -Q high || [ $? -eq 1 ] || sleep 1000" + +screen -t celery_low 3 bash -c "source .env/bin/activate; source env.sh; celery -A rosie-ci.celery worker -n low -Q low || [ $? -eq 1 ] || sleep 1000" + +detach + diff --git a/adabot/circuitpython_bundle.py b/adabot/circuitpython_bundle.py index a2ecb6d..ee08228 100644 --- a/adabot/circuitpython_bundle.py +++ b/adabot/circuitpython_bundle.py @@ -113,7 +113,9 @@ def update_bundle(bundle_path): os.chdir(working_directory) return updates -def commit_updates(update_info): +def commit_updates(bundle_path, update_info): + working_directory = os.path.abspath(os.getcwd()) + os.chdir(bundle_path) message = ["Automated update by Adabot (adafruit/adabot@{})" .format(repo_version())] for url, old_commit, new_commit, summary in update_info: @@ -127,7 +129,7 @@ def commit_updates(update_info): message = "\n\n".join(message) git.add(".") git.commit(message=message) - pass + os.chdir(working_directory) if __name__ == "__main__": directory = ".bundles" @@ -136,4 +138,4 @@ if __name__ == "__main__": #fetch_bundle(bundle, bundle_path) update_info = update_bundle(bundle_path) if update_info: - commit_updates(update_info) + commit_updates(bundle_path, update_info) diff --git a/template-env.sh b/template-env.sh new file mode 100644 index 0000000..ac4efd6 --- /dev/null +++ b/template-env.sh @@ -0,0 +1,2 @@ +export ADABOT_GITHUB_USERNAME= +export ADABOT_GITHUB_ACCESS_TOKEN=