Skip to content

Commit

Permalink
Set up GitHub Actions to run code checks
Browse files Browse the repository at this point in the history
  • Loading branch information
liammulh committed Apr 25, 2024
1 parent 60ec91a commit c213573
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run affils code checks
on: [push, pull_request]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install front end and back end dependencies
run: |
npm install
pip install -r requirements.txt
- name: Run all code checks
run: invoke check
9 changes: 9 additions & 0 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@
- Look at the `tasks.py` script in the root of the `stanford-hci` repo. This
script contains all the command line tasks available to you for this repo.
- List the commands available to you on the command line: `inv --list`
- Create a `pre-commit` hook in `.git/hooks/pre-commit`. Add the following
content:
```
#!/usr/bin/env bash
inv check
inv reqs
```
- Make sure the `pre-commit` hook is executable:
`chmod +x .git/hooks/pre-commit`
31 changes: 31 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Do not edit directly. This file is generated.

astroid==3.1.0
black==24.4.1
blinker==1.7.0
click==8.1.7
coverage==7.5.0
dill==0.3.8
Flask==3.0.3
iniconfig==2.0.0
invoke==2.2.0
isort==5.13.2
itsdangerous==2.2.0
Jinja2==3.1.3
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mccabe==0.7.0
mdformat==0.7.17
mdurl==0.1.2
mypy==1.10.0
mypy-extensions==1.0.0
packaging==24.0
pathspec==0.12.1
platformdirs==4.2.1
pluggy==1.5.0
pylint==3.1.0
pytest==8.1.1
python-dotenv==1.0.1
tomlkit==0.12.4
typing_extensions==4.11.0
Werkzeug==3.0.2
21 changes: 20 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def lint(c):
"""Lint front end and back end code."""
c.run("npm run lint")
c.run("pylint src/api")
c.run("pylint tasks.py")


@task
Expand Down Expand Up @@ -61,7 +62,7 @@ def mdfmt(c):


@task(pre=[fmt, lint, types, test, mdfmt])
def check(c):
def check(c): # pylint: disable=unused-argument
"""Run all front end and back end code checks."""


Expand All @@ -75,3 +76,21 @@ def frontend(c):
def backend(c):
"""Run the back end for development."""
c.run(f"flask --app {os.environ.get('HCI_BACK_END_ENTRYPOINT')} run")


@task
def reqs(c):
"""Generate requirements.txt file.
The GitHub Actions workflow runners don't seem to play nicely with
Pipenv. We generate a requirements.txt file and use it to install
dependencies in GitHub Actions.
"""
add_warning = (
"echo '# Do not edit directly. This file is generated.\n' > requirements.txt"
)
# The PIPENV_VERBOSITY variable suppresses a warning issued Pipenv
# if you use the run command when you've already activated the
# virtual environment.
add_reqs = "PIPENV_VERBOSITY=-1 pipenv run pip freeze >> requirements.txt"
c.run(f"{add_warning} && {add_reqs}")

0 comments on commit c213573

Please sign in to comment.