diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..d7cab7b --- /dev/null +++ b/.github/workflows/check.yml @@ -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 diff --git a/doc/tutorial.md b/doc/tutorial.md index 82256fb..ecea694 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -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` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..67e310d --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/tasks.py b/tasks.py index 900553c..ad1f7cd 100644 --- a/tasks.py +++ b/tasks.py @@ -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 @@ -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.""" @@ -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}")