Add initial Action (#40)

* Add initial Github action.
This commit is contained in:
Dave Gallant
2020-10-26 00:35:19 -04:00
committed by GitHub
parent 2c9f0df088
commit 7b59bf8163
12 changed files with 373 additions and 422 deletions

View File

@@ -8,11 +8,11 @@
This tool looks for regular expressions from [RedFlagDeals.com forums](https://forums.redflagdeals.com/hot-deals-f9/) and will send emails based on matches.
## requirements
## Prerequisites
- a free [SendGrid API key](https://sendgrid.com/pricing/)
## use
## Usage
```shell
USAGE:
@@ -27,28 +27,47 @@ OPTIONS:
-d, --dbpath <dbpath> Specify path to where the embedded database is stored [default: ./deals_db]
```
### docker
## Github action
```shell
# Run the docker image using an example config:
docker run -e RUST_LOG=INFO davegallant/rfd-notify -c /examples/config.toml
An action can be setup to scan for deals, send a notification and store previously found deals in the repo.
### Example
This action can be run on a cron and can store the embedded database by commiting the files to git.
It also requires the corresponding [encrypted secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets) setup.
```yaml
# .github/workflows/main.yml
on:
schedule:
- cron: '*/5 * * * *'
jobs:
rfd_notify:
runs-on: ubuntu-latest
name: rfd-notify
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- name: Run rfd-notify
uses: davegallant/rfd-notify@v0.2.0
env:
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
SENDGRID_MAIL_FROM: notify@rfd-notify.org
SENDGRID_MAIL_TO: ${{ secrets.SENDGRID_MAIL_TO }}
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add deals_db/
git commit -m "Add changes" -a || true
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
branch: ${{ github.ref }}
```
Provide a custom configuration. An example can found in [config.toml](./examples/config.toml)
```shell
# Provide a custom-config.toml that is in the current directory
# ensuring the correct user is mapped to the working directory
docker run -u "$(id -u):$(id -g)" -w=/tmp -e RUST_LOG=INFO -v "$PWD":/tmp davegallant/rfd-notify -c /tmp/custom-config.toml
```
## cross compile
I had motivations to run this on a Raspberry Pi Zero (without needing docker on the pi):
```shell
alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:arm-musleabihf'
rust-musl-builder cargo build --release
```
The above can be substituted for [other architectures](https://github.com/messense/rust-musl-cross#prebuilt-images).