Skip to content

Commit 138e340

Browse files
Merge pull request #367 from sneakers-the-rat/testing-upstream-branch
Specify repo and branch when testing against upstream
2 parents a887aec + fab1d2f commit 138e340

File tree

2 files changed

+117
-5
lines changed

2 files changed

+117
-5
lines changed

.github/workflows/test-upstream.yaml

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ on:
44
branches:
55
- main
66
workflow_dispatch:
7+
inputs:
8+
upstream_repo:
9+
description: "Upstream linkml repository to test against"
10+
required: true
11+
default: "linkml/linkml"
12+
upstream_branch:
13+
description: "Upstream linkml branch to test against"
14+
required: true
15+
default: "main"
716

817
jobs:
918
test_upstream:
1019
strategy:
20+
fail-fast: false
1121
matrix:
1222
os: [ ubuntu-latest, windows-latest ]
1323
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
@@ -23,13 +33,61 @@ jobs:
2333
POETRY_VIRTUALENVS_IN_PROJECT: true
2434

2535
steps:
36+
- name: Get upstream branch and repo from first lines of PR Body
37+
if: github.event_name == 'pull_request'
38+
shell: bash
39+
env:
40+
PR_BODY: ${{ github.event.pull_request.body }}
41+
run: |
42+
set +e
43+
set +o pipefail
44+
45+
UPSTREAM_BRANCH=$( \
46+
echo "$PR_BODY" | \
47+
head -2 | \
48+
grep upstream_branch | \
49+
cut -d ":" -f 2 | \
50+
awk '{$1=$1};1' \
51+
)
52+
echo "Got upstream branch:"
53+
echo $UPSTREAM_BRANCH
54+
55+
if [[ -z "$UPSTREAM_BRANCH" ]]; then
56+
echo "Using main as default"
57+
UPSTREAM_BRANCH="main"
58+
fi
59+
60+
UPSTREAM_REPO=$( \
61+
echo "$PR_BODY" | \
62+
head -2 | \
63+
grep upstream_repo | \
64+
cut -d ":" -f 2 | \
65+
awk '{$1=$1};1' \
66+
)
67+
echo "Got upstream repo:"
68+
echo $UPSTREAM_REPO
69+
70+
if [[ -z "$UPSTREAM_REPO" ]]; then
71+
echo "Using linkml/linkml as default"
72+
UPSTREAM_REPO="linkml/linkml"
73+
fi
74+
75+
echo "upstream_branch=$UPSTREAM_BRANCH" >> "$GITHUB_ENV"
76+
echo "upstream_repo=$UPSTREAM_REPO" >> "$GITHUB_ENV"
77+
78+
- name: Get upstream branch from workflow dispatch
79+
if: github.event_name == 'workflow_dispatch'
80+
shell: bash
81+
run: |
82+
echo "upstream_branch=${{ inputs.upstream_branch }}" >> "$GITHUB_ENV"
83+
echo "upstream_repo=${{ inputs.upstream_repo }}" >> $GITHUB_ENV"
2684
2785
- name: checkout upstream
2886
uses: actions/checkout@v4
2987
with:
30-
repository: linkml/linkml
88+
repository: "${{ env.upstream_repo }}"
3189
path: linkml
32-
ref: main
90+
ref: "${{ env.upstream_branch }}"
3391
fetch-depth: 0
3492

3593
- name: checkout linkml-runtime
@@ -40,7 +98,14 @@ jobs:
4098
path: linkml-runtime
4199
fetch-depth: 0
42100

43-
- name: Ensure tags if not run from main repo
101+
- name: Ensure tags for linkml upstream if a different one than linkml/linkml is specified
102+
if: "${{ env.upstream_repo != 'linkml/linkml' }}"
103+
working-directory: linkml
104+
run: |
105+
git remote add upstream https://github.com/linkml/linkml
106+
git fetch upstream --tags
107+
108+
- name: Ensure tags for linkml-runtime if not run from main repo
44109
if: github.repository != 'linkml/linkml-runtime'
45110
working-directory: linkml-runtime
46111
run: |
@@ -68,7 +133,7 @@ jobs:
68133
# make extra sure we're removing any old version of linkml-runtime that exists
69134
- name: uninstall potentially cached linkml-runtime
70135
working-directory: linkml
71-
run: poetry run pip uninstall linkml-runtime
136+
run: poetry run pip uninstall -y linkml-runtime
72137

73138
# we are not using linkml-runtime's lockfile, but simulating what will happen
74139
# when we merge this and update linkml's lockfile

CONTRIBUTING.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,39 @@ ALSO NOTE: github.com lets you create a pull request from the main branch, autom
3131

3232
> A code review (which happens with both the contributor and the reviewer present) is required for contributing.
3333
34+
## Pull Requests
35+
36+
### Upstream Testing
37+
38+
`linkml-runtime` is tightly coupled to upstream `linkml`,
39+
so all pull requests have their changes tested by running the upstream tests
40+
against the PR version of `linkml-runtime`.
41+
42+
In some circumstances, paired changes need to be made against *both*
43+
`linkml` and `linkml-runtime`, where testing against the `main` branch
44+
of `linkml` is insufficient.
45+
46+
When opening a pull request, you can specify that your PR needs to be
47+
tested against a specific upstream branch and repository by specifying it
48+
in the first two lines of your pull request like this:
49+
50+
> upstream_repo: my-cool-username/linkml
51+
> upstream_branch: some-complicated-feature
52+
>
53+
> Hey everyone what up it's me your boy MC spongebob here with another banger
54+
> ... (PR continues)
55+
56+
The order of the `upstream_repo` and `upstream_branch` tags doesn't matter,
57+
but they must be on the first two lines of the pull request comment and separated with a colon.
58+
59+
Maintainers can also specify upstream branches to test against when
60+
dispatching the `test-upstream` workflow manually via the GUI prompt.
61+
62+
Testing against an unverified upstream branch is not necessarily dangerous,
63+
since the [input is stored as a variable first and not executed as untrusted code](https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable),
64+
but maintainers should take care to verify that the upstream branch and repo
65+
are correct and expected given the context of the PR.
66+
3467
## Development environment setup
3568

3669
1. Install [poetry](https://python-poetry.org/docs/#installation).
@@ -70,7 +103,21 @@ All code added to the linkml-runtime source must have tests. The repo uses the n
70103
You can run the test suite in the following way:
71104

72105
```
73-
poetry run python -m unittest discover
106+
poetry run python -m pytest
107+
```
108+
109+
### Upstream Testing
110+
111+
To run the upstream `linkml` tests against your branch,
112+
install `linkml` locally with poetry, and then manually install your
113+
local copy of `linkml-runtime`
114+
115+
```shell
116+
git clone https://github.com/linkml/linkml
117+
cd linkml
118+
poetry install --all-extras --with tests
119+
poetry run pip install -e ~/location/of/linkml-runtime
120+
poetry run pytest
74121
```
75122

76123
## Code style

0 commit comments

Comments
 (0)