Skip to content

Commit b4d682e

Browse files
authored
Merge pull request #8 from switchbox-data/gha-devcontainer
Use devcontainer in GHA if python_data_science is selected
2 parents 698fbf3 + 57c4d46 commit b4d682e

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed

template/{% if python %}.pre-commit-config.yaml{% endif %}.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ repos:
1717
- id: check-json
1818
- id: check-toml
1919
- id: check-added-large-files
20+
exclude: uv.lock
2021
- id: check-merge-conflict
2122
- id: check-case-conflict
2223

@@ -25,4 +26,4 @@ repos:
2526
- id: ty
2627
name: ty check
2728
entry: uv run ty check . --ignore unresolved-import
28-
language: system
29+
language: system
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Run in devcontainer
2+
description: "Run a command in a devcontainer shell"
3+
inputs:
4+
runCmd:
5+
description: command to run
6+
required: true
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- shell: /usr/bin/bash -e -c "devcontainer exec --workspace-folder . bash -e - < '{0}'"
12+
run: ${{ inputs.runCmd }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
types: [ opened, synchronize, reopened, ready_for_review ]
8+
9+
jobs:
10+
tests-and-checks:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v5
14+
15+
- uses: devcontainers/[email protected]
16+
with:
17+
push: never
18+
runCmd: echo "Container started"
19+
20+
- name: run pre-commit hooks
21+
uses: ./.github/actions/run-in-devcontainer
22+
with:
23+
runCmd: prek -a
24+
25+
- name: run tests
26+
uses: ./.github/actions/run-in-devcontainer
27+
with:
28+
runCmd: uv run python -m pytest tests
29+
30+
- name: ty check
31+
uses: ./.github/actions/run-in-devcontainer
32+
with:
33+
runCmd: uv run ty check

template/{% if use_github %}.github{% endif %}/workflows/{% if use_github and python %}on-release-main.yml{% endif %}.jinja renamed to template/{% if use_github %}.github{% endif %}/workflows/{% if python_package %}on-release-main.yml{% endif %}.jinja

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ on:
55
types: [published]
66

77
jobs:
8-
{% if python_package %}
98
set-version:
109
runs-on: ubuntu-24.04
1110
steps:
1211
- uses: actions/checkout@v4
1312

1413
- name: Export tag
1514
id: vars
16-
run: echo tag=${{'{{'}}GITHUB_REF#refs/*/{{'}}'}} >> $GITHUB_OUTPUT
15+
run: echo tag=${GITHUB_REF#refs/tags/} >> $GITHUB_OUTPUT
1716
if: ${{'{{'}} github.event_name == 'release' {{'}}'}}
1817

1918
- name: Update project version
@@ -64,4 +63,3 @@ jobs:
6463

6564
- name: Deploy documentation
6665
run: uv run mkdocs gh-deploy --force
67-
{% endif %}

template/{% if use_github %}.github{% endif %}/workflows/{% if use_github and python %}main.yml{% endif %}.jinja renamed to template/{% if use_github %}.github{% endif %}/workflows/{% if python_package %}python-package-main.yml{% endif %}.jinja

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
- name: Run ruff, ty and pre-commit hooks
2121
uses: j178/prek-action@v1
2222

23-
2423
tests-and-type-check:
2524
runs-on: ubuntu-latest
2625
strategy:
@@ -45,7 +44,6 @@ jobs:
4544
- name: Check typing
4645
run: uv run ty check
4746

48-
{% if python_package %}
4947
check-docs:
5048
runs-on: ubuntu-latest
5149
steps:
@@ -57,7 +55,7 @@ jobs:
5755

5856
- name: Check if documentation can be built
5957
run: uv run mkdocs build -s
60-
58+
6159
deploy-docs:
6260
if: github.event_name == 'push'
6361
needs: [check-docs]
@@ -71,5 +69,4 @@ jobs:
7169
uses: ./.github/actions/setup-python-env
7270

7371
- name: Deploy documentation
74-
run: uv run mkdocs gh-deploy --force
75-
{% endif %}
72+
run: uv run mkdocs gh-deploy --force

tests/test_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_python_mkdocs_only(tmp_path: Path) -> None:
157157
assert_file_contains(dest, "Justfile", "# 📚 DOCUMENTATION")
158158
assert_file_contains(dest, "Justfile", "docs:")
159159
# Check that GitHub workflow contains docs check job (python_package boolean bug)
160-
assert_file_contains(dest, ".github/workflows/main.yml", "check-docs:")
160+
assert_file_contains(dest, ".github/workflows/python-package-main.yml", "check-docs:")
161161
# Check that release workflow contains set-version job (python_package boolean bug)
162162
assert_file_contains(dest, ".github/workflows/on-release-main.yml", "set-version:")
163163

0 commit comments

Comments
 (0)