Skip to content

Commit 8b06d6a

Browse files
committed
Use overrides for using the same branchname over multiple repos
1 parent 95ac3d8 commit 8b06d6a

File tree

5 files changed

+131
-48
lines changed

5 files changed

+131
-48
lines changed

.github/workflows/coverage.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ jobs:
2525
- name: Set up PDM
2626
uses: pdm-project/setup-pdm@v4
2727

28+
- name: Generate overrides to use current branch if PR
29+
if: github.event_name == 'pull_request'
30+
run: |
31+
pdm run tools/gen_overrides.py ${{github.head_ref}} > overrides.txt
32+
echo "Generated overrides:"
33+
cat overrides.txt
34+
35+
- name: Relock PDM
36+
if: github.event_name != 'pull_request'
37+
run: pdm lock -d
38+
39+
- name: Relock PDM (PR)
40+
if: github.event_name == 'pull_request'
41+
run: pdm lock -d --override overrides.txt
42+
2843
- name: Install dependencies
2944
run: |
3045
pdm install

.github/workflows/main.yaml

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,21 @@ jobs:
1919
- name: Set up PDM
2020
uses: pdm-project/setup-pdm@v4
2121

22-
- name: Re-lock PDM dependencies
22+
- name: Generate overrides to use current branch if PR
23+
if: github.event_name == 'pull_request'
24+
run: |
25+
pdm run tools/gen_overrides.py ${{github.head_ref}} > overrides.txt
26+
echo "Generated overrides:"
27+
cat overrides.txt
28+
29+
- name: Relock PDM
30+
if: github.event_name != 'pull_request'
2331
run: pdm lock -d
2432

33+
- name: Relock PDM (PR)
34+
if: github.event_name == 'pull_request'
35+
run: pdm lock -d --override overrides.txt
36+
2537
- name: Install dependencies
2638
run: pdm install
2739

@@ -42,11 +54,18 @@ jobs:
4254
with:
4355
fetch-depth: 0
4456
- name: Check source code licenses
45-
run: |
46-
docker run --platform=linux/amd64 -v ${PWD}:/src ghcr.io/google/addlicense -v -check -l BSD-2-Clause -c "ChipFlow" -s=only -ignore **/__init__.py **/*.py
57+
run: ./tools/license_check.sh
4758

4859
test-submit:
4960
runs-on: ubuntu-latest
61+
strategy:
62+
matrix:
63+
dry: [true, false]
64+
env:
65+
DRY: ${{ matrix.dry && '--dry-run' || '' }}
66+
IS_DRY: ${{ matrix.dry && '(dry run)' || '' }}
67+
name: ${{ matrix.dry && 'Test Submit - Dry run' || 'Test submit' }}
68+
5069
steps:
5170
- name: Check out source code
5271
uses: actions/checkout@v4
@@ -60,71 +79,47 @@ jobs:
6079
repository: ChipFlow/chipflow-examples
6180
fetch-depth: 0
6281
path: chipflow-examples
82+
ref: ${{ github.head_ref || 'refs/heads/main' }}
6383

6484
- name: Set up PDM
6585
uses: pdm-project/setup-pdm@v4
6686
with:
67-
python-version: "3.10"
87+
python-version: '3.10'
6888
cache: true
6989
cache-dependency-path: "./**/pyproject.toml"
7090

71-
- name: Re-lock PDM dependencies
72-
working-directory: ./chipflow-examples
73-
run: pdm lock -d
74-
75-
- name: Install dependencies
91+
- name: Generate overrides to use current branch if PR
7692
working-directory: ./chipflow-examples
93+
if: github.event_name == 'pull_request'
7794
run: |
78-
pdm install
79-
pdm run python -m ensurepip
80-
pdm run python -m pip install -e ../chipflow-lib
95+
pdm run tools/gen_overrides.py ${{github.head_ref}} > overrides.txt
96+
echo "Generated overrides:"
97+
cat overrides.txt
8198
82-
- name: Run tests
83-
working-directory: ./chipflow-examples/minimal
84-
run: |
85-
pdm test
86-
pdm run chipflow pin lock
87-
pdm run chipflow silicon submit --wait
88-
env:
89-
CHIPFLOW_API_KEY: ${{ secrets.CHIPFLOW_API_KEY}}
90-
91-
test-submit-dry:
92-
runs-on: ubuntu-latest
93-
steps:
94-
- name: Check out source code
95-
uses: actions/checkout@v4
96-
with:
97-
fetch-depth: 0
98-
path: chipflow-lib
99-
100-
- name: Check out chipflow-examples
101-
uses: actions/checkout@v4
102-
with:
103-
repository: ChipFlow/chipflow-examples
104-
fetch-depth: 0
105-
path: chipflow-examples
106-
107-
- name: Set up PDM
108-
uses: pdm-project/setup-pdm@v4
109-
with:
110-
python-version: "3.10"
111-
cache: true
112-
cache-dependency-path: "./**/pyproject.toml"
113-
114-
- name: Re-lock PDM dependencies
99+
- name: Relock PDM
115100
working-directory: ./chipflow-examples
101+
if: github.event_name != 'pull_request'
116102
run: pdm lock -d
117103

104+
- name: Relock PDM (PR)
105+
working-directory: ./chipflow-examples
106+
if: github.event_name == 'pull_request'
107+
run: pdm lock -d --override overrides.txt
108+
118109
- name: Install dependencies
119110
working-directory: ./chipflow-examples
120111
run: |
121112
pdm install
122-
pdm run python -m ensurepip
123-
pdm run python -m pip install -e ../chipflow-lib
124113
125114
- name: Run tests
126115
working-directory: ./chipflow-examples/minimal
127116
run: |
128117
pdm test
118+
119+
- name: Submit build ${{ env.is_dry }}
120+
working-directory: ./chipflow-examples/minimal
121+
run: |
129122
pdm run chipflow pin lock
130-
pdm run chipflow silicon submit --dry-run
123+
pdm run chipflow silicon submit --wait $DRY
124+
env:
125+
CHIPFLOW_API_KEY: ${{ secrets.CHIPFLOW_API_KEY}}

.github/workflows/preview-docs.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ jobs:
2020
python-version: 3.12
2121
cache: true
2222

23+
- name: Generate overrides to use current branch if PR
24+
if: github.event_name == 'pull_request'
25+
run: |
26+
pdm run tools/gen_overrides.py ${{github.head_ref}} > overrides.txt
27+
echo "Generated overrides:"
28+
cat overrides.txt
29+
30+
- name: Relock PDM
31+
if: github.event_name != 'pull_request'
32+
run: pdm lock -d
33+
34+
- name: Relock PDM (PR)
35+
if: github.event_name == 'pull_request'
36+
run: pdm lock -d --override overrides.txt
37+
2338
- name: Install dependencies
2439
run: pdm install
2540

tools/gen_overrides.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# gen-overrides.py
2+
# /// script
3+
# requires-python = ">=3.10"
4+
# dependencies = [
5+
# "pyproject-parser",
6+
# "requirements-parser",
7+
# ]
8+
# ///
9+
# SPDX-License-Identifier: BSD-2-Clause
10+
import os
11+
import subprocess
12+
import sys
13+
import urllib
14+
from pathlib import Path
15+
16+
from pyproject_parser import PyProject
17+
from requirements.requirement import Requirement
18+
19+
20+
rootdir = Path(os.environ["PDM_PROJECT_ROOT"])
21+
22+
def get_branch(repo_dir):
23+
"""Get the current git branch"""
24+
return subprocess.check_output(['git', 'branch', '--show-current'], text=True).strip()
25+
26+
def get_remote_branch(repo, branch):
27+
return subprocess.call(
28+
['git', 'ls-remote', '--exit-code', '--heads', repo, f'refs/heads/{branch}'],
29+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0
30+
31+
def gen_overrides():
32+
if len(sys.argv) > 1:
33+
branch = sys.argv[1]
34+
if branch.startswith("refs/heads/"):
35+
branch = branch[11:]
36+
else:
37+
branch = get_branch(rootdir)
38+
prj = PyProject.load(rootdir / "pyproject.toml")
39+
reqs = prj.project['dependencies']
40+
git_reqs = [r for r in reqs if r.url and r.url.startswith('git+')]
41+
for r in git_reqs:
42+
parts = urllib.parse.urlparse(r.url, allow_fragments=True)
43+
# remove any branches that might already be there
44+
base = parts.path.rsplit(sep="@",maxsplit=1)[0]
45+
clone_url = urllib.parse.urlunparse(parts._replace(path=base, scheme="https"))
46+
if get_remote_branch(clone_url, branch):
47+
path = f"{parts.path}@{branch}"
48+
else:
49+
path = parts.path
50+
r.url = urllib.parse.urlunparse(parts._replace(path=path))
51+
print(str(r))
52+
53+
if __name__ == "__main__":
54+
gen_overrides()

tools/license_check.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
docker run --platform=linux/amd64 -v ${PWD}:/src ghcr.io/google/addlicense -v -check -l BSD-2-Clause -c "ChipFlow" -s=only -ignore **/__init__.py **/*.py
3+
4+

0 commit comments

Comments
 (0)