Skip to content

Commit 601a065

Browse files
authored
Basic CI Checks (#3)
## Why is this change necessary? CI is good ## How does this change address the issue? Adds basic precommit hooks and CI workflow for eslint and typescript checking ## What side effects does this change have? None ## How is this change tested? Downstream repo ## Other Added some boilerplate Nuxt files that are needed for type checking to work well
1 parent a18cfe7 commit 601a065

File tree

19 files changed

+243
-19
lines changed

19 files changed

+243
-19
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: v0.0.10
2+
_commit: v0.0.12
33
_src_path: gh:LabAutomationAndScreening/copier-base-template.git
44
description: A web app that is hosted within a local intranet. Nuxt frontend, python
55
backend, docker-compose

.devcontainer/install-ci-tooling.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# can pass in the full major.minor.patch version of python as an optional argument
33
set -ex
44

5+
6+
npm -v
7+
npm install -g [email protected]
8+
pnpm -v
9+
510
curl -LsSf https://astral.sh/uv/0.6.6/install.sh | sh
611
uv --version
712
# TODO: add uv autocompletion to the shell https://docs.astral.sh/uv/getting-started/installation/#shell-autocompletion

.github/actions/install_deps_uv/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ runs:
5656

5757
- name: OIDC Auth for CodeArtifact
5858
if: ${{ inputs.code-artifact-auth-role-name != 'no-code-artifact' }}
59-
uses: aws-actions/configure-aws-credentials@v4.0.2
59+
uses: aws-actions/configure-aws-credentials@v4.1.0
6060
with:
6161
role-to-assume: arn:aws:iam::${{ inputs.code-artifact-auth-role-account-id }}:role/${{ inputs.code-artifact-auth-role-name }}
6262
aws-region: ${{ inputs.code-artifact-auth-region }}

.github/workflows/ci.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ jobs:
2323
- "ubuntu-24.04"
2424
python-version:
2525
- 3.12.7
26+
node-version:
27+
- 22.14.0
2628
name: Pre-commit for Py${{ matrix.python-version }} on ${{ matrix.os }}
2729
runs-on: ${{ matrix.os }}
2830
steps:
2931
- name: Checkout code
3032
uses: actions/[email protected]
3133

34+
- name: Setup node
35+
uses: actions/[email protected]
36+
with:
37+
node-version: ${{ matrix.node-version }}
38+
3239
- name: Install latest versions of python packages
3340
uses: ./.github/actions/install_deps_uv
3441
with:
@@ -42,7 +49,7 @@ jobs:
4249
timeout-minutes: 30 # this is the amount of time this action will wait to attempt to acquire the mutex lock before failing, e.g. if other jobs are queued up in front of it
4350

4451
- name: Cache Pre-commit hooks
45-
uses: actions/[email protected].0
52+
uses: actions/[email protected].2
4653
env:
4754
cache-name: cache-pre-commit-hooks
4855
with:
@@ -129,7 +136,7 @@ jobs:
129136
timeout-minutes: 30 # this is the amount of time this action will wait to attempt to acquire the mutex lock before failing, e.g. if other jobs are queued up in front of it
130137

131138
- name: Cache Pre-commit hooks
132-
uses: actions/[email protected].0
139+
uses: actions/[email protected].2
133140
env:
134141
cache-name: cache-pre-commit-hooks
135142
with:

extensions/context.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ContextUpdater(ContextHook):
1111
@override
1212
def hook(self, context: dict[Any, Any]) -> dict[Any, Any]:
1313
context["uv_version"] = "0.6.6"
14+
context["pnpm_version"] = "10.6.3"
1415
context["pre_commit_version"] = "4.1.0"
1516
context["pyright_version"] = "1.1.396"
1617
context["pytest_version"] = "8.3.4"
@@ -19,22 +20,23 @@ def hook(self, context: dict[Any, Any]) -> dict[Any, Any]:
1920
context["copier_version"] = "9.5.0"
2021
context["copier_templates_extension_version"] = "0.3.0"
2122
context["sphinx_version"] = "8.1.3"
22-
context["pulumi_version"] = "3.155.0"
23-
context["pulumi_aws_version"] = "6.67.0"
24-
context["pulumi_aws_native_version"] = "1.25.0"
25-
context["pulumi_command_version"] = "1.0.1"
23+
context["pulumi_version"] = "3.156.0"
24+
context["pulumi_aws_version"] = "6.72.0"
25+
context["pulumi_aws_native_version"] = "1.26.0"
26+
context["pulumi_command_version"] = "1.0.2"
2627
context["pulumi_github"] = ""
2728
context["boto3_version"] = "1.37.11"
28-
context["ephemeral_pulumi_deploy_version"] = "0.0.2"
29+
context["ephemeral_pulumi_deploy_version"] = "0.0.4"
2930
context["pydantic_version"] = "2.10.6"
3031
context["pyinstaller_version"] = "6.12.0"
3132
context["setuptools_version"] = "76.0.0"
3233

3334
context["gha_checkout"] = "v4.2.2"
3435
context["gha_setup_python"] = "v5.4.0"
35-
context["gha_cache"] = "v4.2.0"
36-
context["gha_upload_artifact"] = "v4.4.3"
37-
context["gha_configure_aws_credentials"] = "v4.0.2"
36+
context["gha_cache"] = "v4.2.2"
37+
context["gha_upload_artifact"] = "v4.6.1"
38+
context["gha_configure_aws_credentials"] = "v4.1.0"
39+
context["gha_setup_node"] = "v4.3.0"
3840
context["gha_mutex"] = "1ebad517141198e08d47cf72f3c0975316620a65 # v1.0.0-alpha.10"
3941
context["gha_linux_runner"] = "ubuntu-24.04"
4042
context["gha_windows_runner"] = "windows-2022"

template/.devcontainer/install-ci-tooling.sh.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# can pass in the full major.minor.patch version of python as an optional argument
33
set -ex
44

5+
{% endraw %}{% if template_uses_javascript is defined and template_uses_javascript is sameas(true) %}{% raw %}
6+
npm -v
7+
npm install -g pnpm@{% endraw %}{{ pnpm_version }}{% raw %}
8+
pnpm -v{% endraw %}{% endif %}{% raw %}
9+
510
curl -LsSf https://astral.sh/uv/{% endraw %}{{ uv_version }}{% raw %}/install.sh | sh
611
uv --version
712
# TODO: add uv autocompletion to the shell https://docs.astral.sh/uv/getting-started/installation/#shell-autocompletion

template/.devcontainer/manual-setup-deps.sh.jinja

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export UV_PYTHON="$python_version"
3030
export UV_PYTHON_PREFERENCE=only-system
3131

3232
SCRIPT_DIR="$(dirname "$0")"
33-
PROJECT_ROOT_DIR="$(realpath "$SCRIPT_DIR/../backend")"
34-
33+
PROJECT_ROOT_DIR="$(realpath "$SCRIPT_DIR/..")"
34+
PYTHON_PROJECT_DIR="$PROJECT_ROOT_DIR/backend"
3535
# If optionally_lock is set, decide whether to skip locking based on the presence of uv.lock
3636
if [ "$optionally_lock" = "true" ]; then
37-
if [ ! -f "$PROJECT_ROOT_DIR/uv.lock" ]; then
37+
if [ ! -f "$PYTHON_PROJECT_DIR/uv.lock" ]; then
3838
skip_lock=true
3939
else
4040
skip_lock=false
@@ -46,8 +46,11 @@ fi
4646

4747
# Ensure that the lock file is in a good state
4848
if [ "$skip_lock" = "false" ]; then
49-
uv lock --check --directory "$PROJECT_ROOT_DIR"
49+
uv lock --check --directory "$PYTHON_PROJECT_DIR"
5050
fi
5151

52-
uv sync $( [ "$skip_lock" = "false" ] && echo "--frozen" ) --directory "$PROJECT_ROOT_DIR"
53-
uv pip list --directory "$PROJECT_ROOT_DIR"{% endraw %}
52+
uv sync $( [ "$skip_lock" = "false" ] && echo "--frozen" ) --directory "$PYTHON_PROJECT_DIR"
53+
uv pip list --directory "$PYTHON_PROJECT_DIR"
54+
55+
NPM_PROJECT_DIR="$PROJECT_ROOT_DIR/frontend"
56+
pnpm install --dir="$NPM_PROJECT_DIR"{% endraw %}

template/.github/actions/install_deps_uv/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ runs:
5656

5757
- name: OIDC Auth for CodeArtifact
5858
if: ${{ inputs.code-artifact-auth-role-name != 'no-code-artifact' }}
59-
uses: aws-actions/configure-aws-credentials@v4.0.2
59+
uses: aws-actions/configure-aws-credentials@v4.1.0
6060
with:
6161
role-to-assume: arn:aws:iam::${{ inputs.code-artifact-auth-role-account-id }}:role/${{ inputs.code-artifact-auth-role-name }}
6262
aws-region: ${{ inputs.code-artifact-auth-region }}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{% raw %}name: CI
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'gh-readonly-queue/**' # don't run (again) when on these special branches created during merge groups; the `on: merge_group` already triggers it.
7+
merge_group:
8+
9+
env:
10+
PYTHONUNBUFFERED: True
11+
PRE_COMMIT_HOME: ${{ github.workspace }}/.precommit_cache
12+
13+
permissions:
14+
id-token: write
15+
contents: write # needed for mutex
16+
17+
jobs:
18+
lint:
19+
name: Pre-commit
20+
runs-on: {% endraw %}{{ gha_linux_runner }}{% raw %}
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@{% endraw %}{{ gha_checkout }}{% raw %}
24+
25+
- name: Setup node
26+
uses: actions/setup-node@{% endraw %}{{ gha_setup_node }}{% raw %}
27+
with:
28+
node-version: {% endraw %}{{ node_version }}{% raw %}
29+
30+
- name: Install latest versions of python packages
31+
uses: ./.github/actions/install_deps_uv
32+
with:
33+
python-version: {% endraw %}{{ python_version }}{% raw %}
34+
35+
- name: Set up mutex # Github concurrency management is horrible, things get arbitrarily cancelled if queued up. So using mutex until github fixes itself. When multiple jobs are modifying cache at once, weird things can happen. possible issue is https://github.com/actions/toolkit/issues/658
36+
if: ${{ runner.os != 'Windows' }} # we're just gonna have to YOLO on Windows, because this action doesn't support it yet https://github.com/ben-z/gh-action-mutex/issues/14
37+
uses: ben-z/gh-action-mutex@{% endraw %}{{ gha_mutex }}{% raw %}
38+
with:
39+
branch: mutex-venv-{% endraw %}{{ gha_linux_runner }}{% raw %}-py{% endraw %}{{ python_version }}{% raw %}
40+
timeout-minutes: 30 # this is the amount of time this action will wait to attempt to acquire the mutex lock before failing, e.g. if other jobs are queued up in front of it
41+
42+
- name: Cache Pre-commit hooks
43+
uses: actions/cache@{% endraw %}{{ gha_cache }}{% raw %}
44+
env:
45+
cache-name: cache-pre-commit-hooks
46+
with:
47+
path: ${{ env.PRE_COMMIT_HOME }}
48+
key: {% endraw %}{{ gha_linux_runner }}{% raw %}-py{% endraw %}{{ python_version }}{% raw %}-build-${{ env.cache-name }}-${{ hashFiles('.pre-commit-config.yaml') }}
49+
restore-keys: |
50+
{% endraw %}{{ gha_linux_runner }}{% raw %}-py{% endraw %}{{ python_version }}{% raw %}-build-${{ env.cache-name }}-
51+
52+
- name: Run pre-commit
53+
run: pre-commit run -a
54+
55+
required-check:
56+
runs-on: {% endraw %}{{ gha_linux_runner }}{% raw %}
57+
needs: [ lint ]
58+
if: always()
59+
steps:
60+
- name: fail if prior job failure
61+
if: needs.lint.result != 'success'
62+
run: |
63+
exit 1{% endraw %}

template/.pre-commit-config.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ repos:
162162

163163
# Linting
164164

165+
- repo: local
166+
hooks:
167+
- id: typescript-check
168+
name: typescript-check
169+
entry: bash -c "pnpm --dir frontend run type-check"
170+
files: '.+\.ts$|.+\.vue$'
171+
# don't pass filenames else the command line sees them twice
172+
pass_filenames: false
173+
language: system
174+
# use require_serial so that script is only called once per commit
175+
require_serial: true
176+
# print the number of files as a sanity-check
177+
verbose: true
178+
179+
- repo: local
180+
hooks:
181+
- id: eslint
182+
name: eslint
183+
entry: bash -c "pnpm --dir frontend run lint"
184+
files: '.+\.ts$|.+\.vue$|.+\.js$'
185+
# don't pass filenames else the command line sees them twice
186+
pass_filenames: false
187+
language: system
188+
# use require_serial so that script is only called once per commit
189+
require_serial: true
190+
# print the number of files as a sanity-check
191+
verbose: true
192+
165193
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
166194
rev: 501f3d60cee13c712492103343bc23efdc7b3d1f #v1.0.1
167195
hooks:

0 commit comments

Comments
 (0)