Skip to content

Commit 4320d16

Browse files
committed
wip: Migrate From Hub
1 parent 419c423 commit 4320d16

36 files changed

Lines changed: 3260 additions & 2 deletions

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Set update schedule for GitHub Actions
2+
3+
version: 2
4+
updates:
5+
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
# Check for updates to GitHub Actions every weekday
10+
interval: "daily"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Recursion Tests
5+
on:
6+
push:
7+
branches: [ master ]
8+
pull_request:
9+
branches: [ master ]
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python 3.9
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.9
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install flake8 pytest
26+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
- name: Lint with flake8
28+
run: |
29+
# stop the build if there are Python syntax errors or undefined names
30+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
31+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
32+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
33+
- name: Test with pytest
34+
run: |
35+
pytest

.github/workflows/ShellCheck.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Script Check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Run Shellcheck
19+
uses: azohra/shell-linter@latest
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test Installer
2+
3+
on: [push]
4+
5+
jobs:
6+
install:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python 3.8
13+
uses: actions/setup-python@v1
14+
with:
15+
python-version: 3.8
16+
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install python-crontab
21+
22+
- name: Run Installer
23+
run: |
24+
sudo python installer.py

.github/workflows/cd-release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Continious Deployment - Production
2+
3+
name: Release - Version & Deploy
4+
on:
5+
push:
6+
branches: [ release ]
7+
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Release Webhook
17+
uses: distributhor/workflow-webhook@v1
18+
env:
19+
webhook_url: "https://recursion.space/webhooks/github/"
20+
webhook_secret: "Y0uR5ecr3t"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Performs the task of merging from master to the dev-release branch.
2+
# Pings the server to pull an update once the dev-release branch has been merged.
3+
4+
name: Dev Merge & Deploy
5+
on:
6+
push:
7+
branches: [ master ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
13+
merge:
14+
runs-on: ubuntu-latest
15+
name: Merge To dev-release
16+
steps:
17+
- uses: actions/checkout@master
18+
19+
- name: Wait on check
20+
uses: fountainhead/action-wait-for-check@v1.0.0
21+
id: wait-for-build
22+
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
checkName: build
26+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
27+
28+
- name: Create Pull Request
29+
30+
if: steps.wait-for-build.outputs.conclusion == 'success'
31+
uses: repo-sync/pull-request@v2
32+
with:
33+
destination_branch: "dev-release"
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
36+
37+
- name: Merge master -> dev-release
38+
39+
if: steps.wait-for-build.outputs.conclusion == 'success'
40+
uses: devmasx/merge-branch@1.4.0
41+
with:
42+
type: now
43+
target_branch: dev-release
44+
github_token: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Webhook
47+
if: steps.wait-for-build.outputs.conclusion == 'success'
48+
uses: distributhor/workflow-webhook@v1
49+
env:
50+
webhook_url: "https://dev.recursion.space/webhooks/github/"
51+
webhook_secret: "Y0uR5ecr3t"

.github/workflows/pylint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Code Quality
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python 3.8
13+
uses: actions/setup-python@v1
14+
with:
15+
python-version: 3.8
16+
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install pylint
21+
pip install pylint-exit
22+
if [ -f requirements.txt ]; then pip3 install -r requirements.txt; fi
23+
24+
- name: Analysing the code with pylint
25+
run: |
26+
pylint `ls -r|grep .py$|xargs` --disable=import-error,E1101 || pylint-exit --error-fail --warn-fail --convention-fail $?
27+
pylint 0_1_0 `ls -r|grep .py$|xargs` --disable=import-error,E1101 || pylint-exit --error-fail --warn-fail --convention-fail $?
28+
29+
pylint tests `ls -r|grep .py$|xargs` --disable=import-error,E1101 || pylint-exit --error-fail --warn-fail --convention-fail $?

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,24 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# ---------------------------------- Custom ---------------------------------- #
132+
.bash_history
133+
.bashrc
134+
.cache/
135+
.cloud-locale-test.skip
136+
.gitconfig
137+
.mysql_history
138+
.npm/
139+
.profile
140+
.selected_editor
141+
.ssh/
142+
.vscode/
143+
HUB_Boot.sh.save
144+
.python_history
145+
.gnupg
146+
147+
# ------------------------------- Python tests ------------------------------- #
148+
.coverage
149+
150+
__pycache__/

0_1_0/HUB_Launcher.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env python3
2+
"""
3+
- Initiates the LED visuals
4+
5+
- Installs new requirements as part of an update
6+
(if needed, might want to have a seprate process for this)
7+
8+
- Checks for connection to server,
9+
- If no connection is found then LED indication is set.
10+
- Pulls configuration files from server.
11+
- Launches main program
12+
"""
13+
import sys
14+
import json
15+
import threading
16+
import subprocess
17+
18+
# ---------------------------------------------------------------------------- #
19+
# Check Requirements #
20+
# ---------------------------------------------------------------------------- #
21+
try:
22+
import config
23+
except ImportError :
24+
subprocess.call(['sudo', 'pip3', 'install', 'config'])
25+
26+
27+
28+
from modules import rec_lan, rec_log
29+
from modules.rec_log import exception_log
30+
31+
from settings import LED_STAT
32+
import settings
33+
34+
if settings.Pi:
35+
try:
36+
from modules import rec_xbee
37+
except ModuleNotFoundError as err:
38+
exception_log.error("%s", err)
39+
40+
try:
41+
from modules import rec_gpio
42+
except ModuleNotFoundError as err:
43+
exception_log.error("%s", err)
44+
45+
46+
# ---------------------------------------------------------------------------- #
47+
# Program Start Visual #
48+
# ---------------------------------------------------------------------------- #
49+
if settings.Pi:
50+
led_stat_thread = threading.Thread(target = rec_gpio.led_stat_thread)
51+
led_stat_thread.start()
52+
53+
rec_gpio.state(LED_STAT, 1, 0)
54+
55+
56+
# ---------------------------------------------------------------------------- #
57+
# Check Network Connection #
58+
# ---------------------------------------------------------------------------- #
59+
try:
60+
rec_lan.monitor_network() #Monitors the network connection while the program is running.
61+
62+
except RuntimeError as err:
63+
exception_log.error("FATAL - Start Network Monitoring - Error: %s", err)
64+
65+
finally:
66+
exception_log.debug("Launcher - Exiting Check Network Connection")
67+
68+
# ---------------------------------------------------------------------------- #
69+
# Update version in system.json #
70+
# ---------------------------------------------------------------------------- #
71+
#Only updates if called by bash script and environmental variable was passed in.
72+
if len(sys.argv) > 1:
73+
with open("system.json", "r+", encoding="utf-8") as file:
74+
data = json.load(file)
75+
data.update( {"CurrentVersion":sys.argv[1]} )
76+
file.seek(0)
77+
json.dump(data, file)
78+
file.truncate()
79+
80+
81+
# ---------------------------------------------------------------------------- #
82+
# Logs Settings For Debugging #
83+
# ---------------------------------------------------------------------------- #
84+
try:
85+
public, local = rec_lan.get_ip()
86+
rec_log.snapshot(public, local)
87+
88+
except RuntimeError as err:
89+
exception_log.error("FAITIAL - Generate Snapshot - Error: %s", err)
90+
91+
finally:
92+
exception_log.debug("Launcher - Exiting Settings for Debugging")
93+
94+
# ---------------------------------------------------------------------------- #
95+
# XBee Configuration #
96+
# ---------------------------------------------------------------------------- #
97+
if settings.Pi:
98+
with open('system.json', 'r', encoding="utf-8") as file:
99+
system_data = json.load(file)
100+
101+
if system_data.get('XBEE_OP', False) is False:
102+
try:
103+
rec_xbee.xbee_info()
104+
except UnboundLocalError as err:
105+
exception_log.error("Unable to capture XBee info - Error: %s", err)
106+
107+
# ---------------------------------------------------------------------------- #
108+
# Main HUB Program #
109+
# ---------------------------------------------------------------------------- #
110+
try:
111+
import hub
112+
113+
except RuntimeError as err:
114+
exception_log.error("Could not start hub.py with error: %s", err)
115+
116+
# Performs Seppuku to triger bash script and perform update pull (student).
117+
subprocess.call(['pkill', '-f', 'hub.py'])
118+
119+
# Performs Seppuku to triger bash script and perform update pull
120+
# (can't kill the master before the student).
121+
subprocess.call(['pkill', '-f', 'HUB_Launcher.py'])

0_1_0/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'''Required to import for tests.'''

0 commit comments

Comments
 (0)