setting up GitHub actions
automate your literature recommendation automation tool
Okay, hopefully you're interested in using refy by now, but you don't really want to have to manually run it in python once or twice a week. If the point of refy is to automate papers recommendation, automate refy too!
I assume that you're fairly familiar with GitHub here and know how to create and edit GitHub repositories. If not, please get in touch and I'll try to help with more details.
The easiest way is to use GitHub Actions to have refy update a GitHub repository for you. If you're repository's published to a GitHub Pages website, refy can even update your website for you! If everything works correctly, you'll have a GH action running periodically and updating your repository with the latest freshest preprints.
Currently the best way I've found to do this is is to let the GH action update my website. Maybe someone has a way to have actions email content to users instead, that'd be great. Get in touch if you know how to improve this workflow!
These are the steps to setup refy on GH Actions:
  1. 1.
    In your GH repository, save a library.bib file with your papers metadata and create a folder called scripts
  2. 2.
    In your scripts folder, create run_refy.py The content of run_refy.py should be:
1
import refy
2
from loguru import logger
3
from pathlib import Path
4
import sys
5
6
# setup logging
7
logger.remove()
8
logger.add(sys.stdout, level='DEBUG')
9
logger.add('log.log')
10
11
# create a HTML file with recomended papers
12
logger.info('Creating refy.html')
13
refy.Recomender(
14
'library.bib', # path to your .bib file
15
n_days=7, # fetch preprints from the last N days
16
N=50, # number of recomended papers
17
show_html = False,
18
html_path='./refy.html',
19
)
20
Copied!
when your GH action runs, it will execute run_refy.py and this will create a refy.html file with your recommendations.
3. Create a new GitHub Actions workflow. From your repository's page, select Actions
from there, on the top left click onNew Workflow and in the next page select Simple Workflow (click on 'setup this workflow'). This will take you to a new page where you can edit your action's yaml workflow file. Delete all precompiled content and replace it with:
1
name: refy
2
3
on:
4
push:
5
schedule:
6
- cron: "0 6 * * 1,3,5" # Every Mon, Wed, Fri at at 6 AM UTC
7
8
jobs:
9
build:
10
runs-on: ubuntu-latest
11
12
steps:
13
- uses: actions/[email protected]
14
15
- name: checkout repo content
16
uses: actions/[email protected] # checkout the repository content to github runner.
17
18
- name: setup python
19
uses: actions/setup-[email protected]
20
with:
21
python-version: 3.8 #install the python needed
22
23
- name: Install dependencies
24
run: |
25
python -m pip install --upgrade pip
26
pip install git+https://github.com/FedeClaudi/refy.git
27
28
- name: execute py script # run the run.py to get the latest data
29
run: |
30
python scripts/run_refy.py
31
32
- name: Commit refy.html
33
run: |
34
git config --global user.name 'auto-update'
35
git config --global user.email '[email protected]'
36
git add "."
37
git commit -am "updating refs"
38
git push
Copied!
Make sure to replace YOURUSERNAME at row 35 with your GitHub username.
You can read more about the workflow file syntax on the documentation, but this is the essence of what's happening.
1
on:
2
push:
3
schedule:
4
- cron: "0 6 * * 1,3,5" # Every Mon, Wed, Fri at at 6 AM UTC
5
Copied!
this bit specifies when your GitHub action should run. Currently it runs on push, i.e. when you push a commit to your repository and on schedule. GH actions allows you to use cron syntax to schedule jobs that should run periodically. You can use this to have your action run as frequently as you'd like, I have it such that it updates my website three times a week.
Having the action running on push can be useful. If you have other applications that push content to the same repository, these can trigger a website update for you. I use paperpile as reference manager, and it has an option to automatically push a library.bib file to a GitHub repository every time I add papers to my collection. So whenever I add new papers, the .bib file in my repository is update and this triggers new papers recommendation
😍
Next, this:
1
- name: setup python
2
uses: actions/setup-[email protected]
3
with:
4
python-version: 3.8 #install the python needed
5
6
- name: Install dependencies
7
run: |
8
python -m pip install --upgrade pip
9
pip install git+https://github.com/FedeClaudi/refy.git
10
Copied!
setups a python environment on the action's virtual machine and it fetches the latest refy code from its GH repository.
Then, the python script we created above is ran by:
1
- name: execute py script # run the run.py to get the latest data
2
run: |
3
python scripts/run_refy.py
Copied!
as we saw, this updates a refy.html file in your repository, so the next step is to commit this new version to your repository:
1
- name: Commit refy.html
2
run: |
3
git config --global user.name 'auto-update'
4
git config --global user.email '[email protected]'
5
git add "."
6
git commit -am "updating refs"
7
git push
Copied!
job done, enjoy the new reads
🎉
Copy link