Skip to content

Commit

Permalink
Merge pull request #1 from w0rmr1d3r/project-setup
Browse files Browse the repository at this point in the history
Project setup
  • Loading branch information
w0rmr1d3r committed Apr 15, 2024
2 parents 559d769 + 62d47e7 commit a96ad8e
Show file tree
Hide file tree
Showing 17 changed files with 450 additions and 17 deletions.
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
assignees:
- "w0rmr1d3r"
reviewers:
- "w0rmr1d3r"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
assignees:
- "w0rmr1d3r"
reviewers:
- "w0rmr1d3r"
10 changes: 10 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
categories:
- title: 'Dependencies'
labels:
- 'dependencies'
template: |
# Changes
$CHANGES
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ['3.9']

name: CI ${{ matrix.python-version }}

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dev dependencies
run: make install-dev

- name: Run test
run: make test
78 changes: 78 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
# Won't analyze on PRs since it takes a long time to complete.
# But will keep when pushing to master and scheduled
# pull_request:
# The branches below must be a subset of the branches above
# branches: [ "master" ]
schedule:
- cron: '00 8 1 * *' # 8am UTC the first day of the month

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
21 changes: 21 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3

- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
33 changes: 33 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PyPI release

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: make install

- name: Install build dependencies
run: pip install build

- name: Build project
run: python3 -m build

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
# pull_request event is required only for autolabeler
# pull_request:
# Only following types are handled by the action, but one can default to all as well
# types: [opened, reopened, synchronize]
# pull_request_target event is required for autolabeler to support PRs from forks
# pull_request_target:
# types: [opened, reopened, synchronize]

permissions:
contents: read

jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prune tests
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SOURCES = raspimonitor tests

install:
pip install -r requirements.txt

install-dev:
pip install -r requirements-dev.txt

format:
ruff format $(SOURCES)
ruff check --fix $(SOURCES)

lint:
ruff check $(SOURCES)

unit:
pytest -svvv tests

test: lint unit

freeze:
CUSTOM_COMPILE_COMMAND="make freeze" pip-compile --no-emit-index-url -v -o requirements.txt pyproject.toml
CUSTOM_COMPILE_COMMAND="make freeze-dev" pip-compile --extra "dev" --no-emit-index-url -v -o requirements-dev.txt pyproject.toml

freeze-upgrade:
CUSTOM_COMPILE_COMMAND="make freeze" pip-compile --upgrade --no-emit-index-url -v -o requirements.txt pyproject.toml
CUSTOM_COMPILE_COMMAND="make freeze-dev" pip-compile --extra "dev" --upgrade --no-emit-index-url -v -o requirements-dev.txt pyproject.toml

.PHONY: install install-dev format lint unit test freeze freeze-upgrade
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# raspimonitor

Monitoring and alerting for your RaspberryPi
Monitoring and alerting to your Discord server for your RaspberryPi

## Installation

### From git
You will need to set up a Discord server and webhook, see
how [here](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks).
After that, proceed to install the package in your raspberry:

```bash
git clone https://github.com/w0rmr1d3r/raspimonitor.git
cd raspimonitor
pip3 install -r requirements.txt
pip3 install raspimonitor
```

## Usage

### As Python script
### Direct usage

```bash
# python3 raspimonitor.py YOURHOOKHERE THRESHOLD_TEMP_IN_CELSIUS
# raspimonitor YOURHOOKHERE THRESHOLD_TEMP_IN_CELSIUS
# Example
python3 raspimonitor.py http://your.web.hook.here 45
raspimonitor http://your.web.hook.here 45
# Example temp as float:
python3 raspimonitor.py http://your.web.hook.here 45.6
raspimonitor http://your.web.hook.here 45.6
```

### As cron job
### As a cron job

Add your cron job as a script from above.
Add your cron job as a script from above:

```bash
# 1. Open cron file
crontab -e
# 2. Add a cron
# Example - run every minute:
* * * * * python3 /path/to/raspimonitor.py http://your.web.hook.here 45
* * * * * raspimonitor http://your.web.hook.here 45
# Example - run every 5 minutes
*/5 * * * * python3 /path/to/raspimonitor.py http://your.web.hook.here 45
*/5 * * * * raspimonitor http://your.web.hook.here 45
# 3. Reload cron service
sudo service cron reload
```
Expand All @@ -44,7 +44,7 @@ Ref. https://superuser.com/questions/232144/how-to-stop-a-currently-running-cron

## Contributing

Pull requests are welcome.
Pull requests and issues are welcome.

## License

Expand Down
Loading

0 comments on commit a96ad8e

Please sign in to comment.