Skip to content

Commit

Permalink
Merge pull request #18 from williln/gha-test-ci
Browse files Browse the repository at this point in the history
Add TIL about testing in a github action, generate new readmes
  • Loading branch information
williln authored Jul 24, 2024
2 parents 07ca6a8 + c1b2b8e commit 9d78a5c
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions django/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [How to confirm that login is required in your Django view](how_to_test_view_auth.md)
- [How to log in a test user in a `pytest` unit test](test_protected_page.md)
- [How to test a file upload with `pytest` and `SimpleUploadedFile`](testing_file_upload_pytest.md)
- [Run SQL statements as part of your migrations with `migrations.RunSQL`](run_sql.md)
- [Testing Django signals, and disabling signals in tests (Django 2.2)](testing_django_signals.md)
- [Using Django Aggregation](aggregation.md)
- [Using Enums in a Django Model ChoiceField (Django 2.2)](enums_as_choices.md)
Expand Down
1 change: 1 addition & 0 deletions github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
- [Making one job in a workflow depend on another job](gh-actions-set-job-dependency.md)
- [Parsing JSON output from a GitHub Issue template in a GitHub Action](gh-actions-parse-json.md)
- [Running an action conditionally](gh-action-run-job-conditionally.md)
- [Running your tests with `pytest` in your PR via a GitHub Action](gh-action-test-ci.md)
- [Setting output for a step in a job, so a different job can use it](gh-action-set-output.md)
- [Temporarily disabling a GitHub action without touching the workflow file](gh_actions_temporary_disable.md)
61 changes: 61 additions & 0 deletions github/gh-action-test-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Running your tests with `pytest` in your PR via a GitHub Action

tags: ci, pytest, github-actions

## Links

- [Building and testing Python - GitHub Docs](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python)

## Process

I decided to follow the [Using a Python starter workflow](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#using-a-python-starter-workflow) process, at least initially. I've done this before, but I can't remember how and it's been a while. It seems best to return to the docs and see how we do things _now_.

Their automated builder spit out a workflow that I made a few changes to:

- I deleted their linting step because I have a pre-commit hook for that
- I updated their `setup-python` version from 3 to 5.

```yaml
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

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: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
```
On every PR and push to `main`, this workflow:

- Installs Python 3.12
- Installs `pytest`
- Installs the `requirements.txt`
- Runs `pytest`

It worked right there in the PR that I made it in!
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ build-internal-readmes:
python3 scripts/build_subdir_toc.py meilisearch
python3 scripts/build_subdir_toc.py microsoft-dynamics
python3 scripts/build_subdir_toc.py misc
python3 scripts/build_subdir_toc.py mkdocs
python3 scripts/build_subdir_toc.py postgres
python3 scripts/build_subdir_toc.py pre-commit
python3 scripts/build_subdir_toc.py pytest
python3 scripts/build_subdir_toc.py python
python3 scripts/build_subdir_toc.py r
python3 scripts/build_subdir_toc.py slack
python3 scripts/build_subdir_toc.py stripe
python3 scripts/build_subdir_toc.py terraform
python3 scripts/build_subdir_toc.py wagtail
3 changes: 3 additions & 0 deletions mkdocs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# mkdocs

- [Including your project's README on your MkDocs index page](include_readme_in_index.md)
3 changes: 3 additions & 0 deletions postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# postgres

- [Collecting statistics about your database with `ANALYZE`](analyze.md)
3 changes: 3 additions & 0 deletions pre-commit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pre-commit

- [Setting up `pre-commit` in a new project](setup.md)
3 changes: 2 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
- [Generating a clickable table-of-contents for each directory in my TILs](generate_toc_for_subdirectory.md)
- [How to sort a Python dictionary by key or value](sort_dictionary.md)
- [How to sort a Python dictionary by multiple values](sort_dict_multiple_keys.md)
- [Using `Decimal.quantize`](decimal_quantize.md)
- [Using `Decimal.quantize`](decimal_quantize.md)
- [Using `pip-tools` and `pip-compile` for Python dependency management](pip_tools.md)
4 changes: 3 additions & 1 deletion stripe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

- [Creating a PaymentIntent, but not capturing it, and allowing more to be charged later](uncaptured_payment_intents_and_overcapture.md)
- [Generating a `PaymentIntent` and saving it to a Django model](payment_intents.md)
- [Receiving Stripe webhooks via `dj-stripe` in local dev](using_dj_stripe_webhooks_locally.md)
- [Setting up a webhook in local development (Django project)](webhook_local_dev.md)
- [Using off-session payments and `setup_future_usage`](off_session_payments.md)
- [Using off-session payments and `setup_future_usage`](off_session_payments.md)
- [`dj-stripe` contains models for all the Stripe objects and can sync them for you](setup-dj-stripe.md)
3 changes: 3 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# terraform

- [About Terraform and .tfvars files](tfvars-files.md)

0 comments on commit 9d78a5c

Please sign in to comment.