Skip to content

Commit 6e14794

Browse files
committed
ci: move mypy and unit tests
moves mypy and unit tests from pre commit to CI workflows
1 parent d665e29 commit 6e14794

File tree

6 files changed

+112
-46
lines changed

6 files changed

+112
-46
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: "Test"
2+
on:
3+
# Workflow dispatch is used for manual triggers
4+
workflow_dispatch:
5+
# Workflow call is used for called from another workflow
6+
workflow_call:
7+
secrets:
8+
CR_SECRET:
9+
description: "Secret to authenticate if using an other container registry than Github"
10+
required: false
11+
12+
env:
13+
IMAGE_REGISTRY: ghcr.io
14+
REGISTRY_USER: $GITHUB_ACTOR
15+
API_IMAGE: ghcr.io/equinor/template-fastapi-react/api
16+
WEB_IMAGE: ghcr.io/equinor/template-fastapi-react/web
17+
18+
jobs:
19+
pre-commit:
20+
runs-on: ubuntu-latest
21+
name: "pre-commit"
22+
steps:
23+
- name: "Setup: checkout repository"
24+
uses: actions/checkout@v4
25+
26+
- name: "Setup: add python"
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.12"
30+
31+
- name: "Run: pre-commit"
32+
uses: pre-commit/action@v3.0.1
33+
with:
34+
extra_args: --all-files
35+
36+
mypy:
37+
runs-on: ubuntu-latest
38+
name: "mypy static type checking"
39+
defaults:
40+
run:
41+
working-directory: ./api
42+
steps:
43+
- name: "Setup: checkout repository"
44+
uses: actions/checkout@v4
45+
46+
- name: "Setup: add python"
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: "3.12"
50+
51+
- name: "Setup: add venv"
52+
run: |
53+
pip install poetry
54+
poetry config virtualenvs.in-project true
55+
poetry install
56+
57+
- name: "Run: mypy"
58+
run: mypy src
59+
60+
typescript-compile:
61+
runs-on: ubuntu-latest
62+
name: "typescript compilation"
63+
defaults:
64+
run:
65+
working-directory: ./web
66+
steps:
67+
- name: "Setup: check out repository"
68+
uses: actions/checkout@v4
69+
with:
70+
sparse-checkout: |
71+
.github
72+
web
73+
74+
- name: "Setup: add node"
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: 20
78+
cache: yarn
79+
cache-dependency-path: web/yarn.lock
80+
81+
- name: "Setup: yarn install"
82+
run: yarn install
83+
84+
- name: "Run: compile"
85+
run: yarn compile

.github/workflows/on-pull-request.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ on:
44
types: [opened, reopened, synchronize]
55

66
jobs:
7+
linting-and-checks:
8+
name: "Linting and checks"
9+
uses: ./.github/workflows/linting-and-checks.yaml
10+
711
tests:
12+
name: "Tests"
813
uses: ./.github/workflows/tests.yaml

.github/workflows/on-push-main-branch.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@ on:
88
- "CHANGELOG.md"
99

1010
jobs:
11+
linting-and-checks:
12+
name: "Linting and checks"
13+
uses: ./.github/workflows/linting-and-checks.yaml
14+
1115
tests:
16+
name: "Tests"
1217
uses: ./.github/workflows/tests.yaml
1318

1419
generate-changelog:
1520
needs: tests
21+
name: "Generate changelog"
1622
uses: ./.github/workflows/generate-changelog.yaml
1723
docs:
1824
needs: generate-changelog
25+
name: "Build and publish docs"
1926
uses: ./.github/workflows/publish-docs.yaml
2027
with:
2128
message: "Warning: This is the development version."
2229

2330
publish-latest:
2431
needs: tests
32+
name: "Publish dev docker images"
2533
uses: ./.github/workflows/publish-image.yaml
2634
with:
2735
image-tags: latest
@@ -35,11 +43,13 @@ jobs:
3543

3644
release-please:
3745
needs: tests
46+
name: "Create or update release PR"
3847
uses: ./.github/workflows/create-release-pr.yaml
3948

4049
publish-staging:
4150
needs: release-please
4251
if: ${{ needs.release-please.outputs.release_created }}
52+
name: "Publish staging docker images"
4353
uses: ./.github/workflows/publish-image.yaml
4454
with:
4555
image-tags: ${{ needs.release-please.outputs.tag_name }}

.github/workflows/tests.yaml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,23 @@ env:
1616
WEB_IMAGE: ghcr.io/equinor/template-fastapi-react/web
1717

1818
jobs:
19-
pre-commit:
19+
api-unit-tests:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v4
2323

24-
- name: Set up python
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version: "3.12"
28-
29-
- name: Install pre-commit
30-
run: pip install pre-commit
24+
- name: Login to image registry
25+
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REGISTRY -u $GITHUB_ACTOR --password-stdin
3126

32-
- name: Set up venv
27+
- name: Build API image
3328
run: |
34-
pip install poetry
35-
poetry config virtualenvs.in-project true
36-
cd api
37-
poetry install
29+
docker pull $API_IMAGE
30+
docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE
3831
39-
- name: Run pre-commit
40-
run: pre-commit run --all-files
32+
- name: Pytest Unit tests
33+
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api pytest --unit
4134

42-
test-api:
35+
api-integration-tests:
4336
runs-on: ubuntu-latest
4437
steps:
4538
- uses: actions/checkout@v4
@@ -59,7 +52,7 @@ jobs:
5952
- name: Pytest Integration tests
6053
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api pytest --integration
6154

62-
test-web:
55+
web-tests:
6356
runs-on: ubuntu-latest
6457
steps:
6558
- uses: actions/checkout@v4
@@ -76,7 +69,7 @@ jobs:
7669
if: ${{ false }} # disable for now as they do not currently work
7770
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm web yarn test
7871

79-
test-docs:
72+
docs-tests:
8073
name: test-docs
8174
runs-on: ubuntu-latest
8275

.pre-commit-config.yaml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,6 @@ repos:
6969
additional_dependencies: ["@biomejs/biome@1.9.4"]
7070
args: ["--config-path", "web"]
7171

72-
- repo: https://github.com/pre-commit/mirrors-mypy
73-
rev: v1.15.0
74-
hooks:
75-
- id: mypy
76-
name: "Lint: python type checking (mypy)"
77-
args: [--config-file=api/pyproject.toml]
78-
exclude: tests/
79-
additional_dependencies:
80-
- types-cachetools
81-
- types-requests
82-
- types-ujson
83-
- types-toml
84-
- types-click
85-
- types-python-jose
86-
- pymongo
87-
- pydantic
88-
- fastapi
89-
90-
# The path to the venv python interpreter differ between linux and windows. An if/else is used to find it on either.
91-
- repo: local
92-
hooks:
93-
- id: pytest
94-
name: "Tests: python unit tests"
95-
entry: sh -c "cd ./api/src/ && poetry run pytest ./tests/"
96-
language: system
97-
pass_filenames: false
98-
always_run: true
99-
10072
- repo: https://github.com/codespell-project/codespell
10173
rev: v2.4.1
10274
hooks:

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"start": "vite",
77
"build": "tsc && vite build",
88
"serve": "vite preview",
9+
"compile": "tsc --noEmit",
910
"generate": "openapi -i http://localhost:5000/openapi.json -o './src/api/generated' -c axios",
1011
"test": "vitest",
1112
"lint": "biome check --write --no-errors-on-unmatched"

0 commit comments

Comments
 (0)