Repository navigation
148 lines (122 loc) · 5.53 KB
/
Copy pathpr-checks.yml
File metadata and controls
148 lines (122 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: PR
on:
pull_request:
branches: [develop]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: pr-checks-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
checks:
name: Build and tests
runs-on: windows-latest
env:
# Real-type tests fail instead of being skipped when an assembly is missing
CI: 'true'
PYTHONPATH: ${{ github.workspace }}/.ci/generation
BHOM_JSONSCHEMA_ROOT: ${{ github.workspace }}\.repos\BHoM_JSONSchema
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: pyproject.toml
- name: Install the built BHoM assemblies
uses: ./.github/actions/bhom-assemblies
# The published JSON schemas are the test oracle for the JSON that Python writes. Read only; the generator does not use them.
- name: Clone BHoM_JSONSchema (test oracle)
shell: pwsh
run: git clone https://github.com/BHoM/BHoM_JSONSchema.git .repos/BHoM_JSONSchema --depth 1 --quiet
- name: Create the virtual environment
shell: pwsh
run: |
python -m venv .venv
.venv\Scripts\python -m pip install -e ".[dev]"
# Build, NUnit, py2cs drafts and the Roslyn round trip, pytest, and Pyright
- name: Build and test
shell: pwsh
run: ./.ci/unit-tests/run-all.ps1
- name: Does the Python PR change the classes?
id: changed
shell: pwsh
if: github.event_name == 'pull_request'
run: |
$base = "${{ github.event.pull_request.base.sha }}"
$changed = git diff --name-only $base HEAD -- src/bhom_schema
"classes=$([bool]$changed)".ToLower() | Out-File $env:GITHUB_OUTPUT -Append
- name: Get the classes before the change
if: steps.changed.outputs.classes == 'true'
shell: pwsh
run: git worktree add "$env:RUNNER_TEMP/base" ${{ github.event.pull_request.base.sha }}
- name: py2cs check (every problem of the changed Python, descriptions)
if: steps.changed.outputs.classes == 'true'
shell: pwsh
run: .venv\Scripts\python -m py2cs check --root src/bhom_schema --base-root "$env:RUNNER_TEMP/base/src/bhom_schema"
# Its own job, so that the pull request page names what is pending. The Python PR is a proposal: this only passes once the linked C# pull
# request is merged, because the assemblies built here come from the C# develop branches. After that merge, re-run this job.
# It waits for the first job, which saves the build cache, so that a change in a C# repository is built once; it runs even when the tests fail.
alignment:
name: C# alignment (fails until the linked C# PR is merged)
needs: checks
if: ${{ !cancelled() }}
runs-on: windows-latest
env:
PYTHONPATH: ${{ github.workspace }}/.ci/generation
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: pyproject.toml
- name: Does the Python PR change the classes?
id: changed
shell: pwsh
if: github.event_name == 'pull_request'
run: |
$base = "${{ github.event.pull_request.base.sha }}"
$changed = git diff --name-only $base HEAD -- src/bhom_schema
"classes=$([bool]$changed)".ToLower() | Out-File $env:GITHUB_OUTPUT -Append
- name: Install the built BHoM assemblies
if: steps.changed.outputs.classes == 'true'
uses: ./.github/actions/bhom-assemblies
- name: Build the generator
if: steps.changed.outputs.classes == 'true'
run: dotnet build .ci/generation/PythonSchemaGeneration/PythonSchemaGeneration.csproj -c Release --nologo
- name: Create the virtual environment
if: steps.changed.outputs.classes == 'true'
shell: pwsh
run: |
python -m venv .venv
.venv\Scripts\python -m pip install -e .
- name: Get the classes before the change
if: steps.changed.outputs.classes == 'true'
shell: pwsh
run: git worktree add "$env:RUNNER_TEMP/base" ${{ github.event.pull_request.base.sha }}
- name: py2cs align
id: align
if: steps.changed.outputs.classes == 'true'
shell: pwsh
run: |
.venv\Scripts\python -m py2cs align `
--base-root "$env:RUNNER_TEMP/base/src/bhom_schema" `
--head-root src/bhom_schema `
--assemblies "$env:ProgramData\BHoM\Assemblies"
- name: Explain the failure
if: failure() && steps.align.conclusion == 'failure'
shell: pwsh
run: |
@'
## C# alignment failed
The classes changed in this pull request are compared with the Python that the generator writes from the **merged C#**. They differ, which usually means the linked C# pull request is not merged yet.
1. Open the linked draft pull request (the comment on this pull request links it) and merge it in the C# repository.
2. Re-run this job. It should then pass.
If the C# is already merged and it still fails, the differences are listed in the log of the step `py2cs align`: either the C# review changed the class (copy that change into the Python), or the generator and py2cs disagree (a bug to fix in this repository).
'@ | Out-File $env:GITHUB_STEP_SUMMARY -Append