|
| 1 | +name: Test with upstream linkml |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + 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" |
| 16 | + |
| 17 | +jobs: |
| 18 | + test_upstream: |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + os: [ ubuntu-latest, windows-latest ] |
| 23 | + python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] |
| 24 | + exclude: |
| 25 | + - os: windows-latest |
| 26 | + python-version: "3.10" |
| 27 | + - os: windows-latest |
| 28 | + python-version: "3.11" |
| 29 | + - os: windows-latest |
| 30 | + python-version: "3.12" |
| 31 | + runs-on: ${{ matrix.os }} |
| 32 | + env: |
| 33 | + POETRY_VIRTUALENVS_IN_PROJECT: true |
| 34 | + |
| 35 | + 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" |
| 84 | +
|
| 85 | + - name: checkout upstream |
| 86 | + uses: actions/checkout@v4 |
| 87 | + with: |
| 88 | + repository: "${{ env.upstream_repo }}" |
| 89 | + path: linkml |
| 90 | + ref: "${{ env.upstream_branch }}" |
| 91 | + fetch-depth: 0 |
| 92 | + |
| 93 | + - name: checkout linkml-runtime |
| 94 | + uses: actions/checkout@v4 |
| 95 | + with: |
| 96 | + # don't specify repository like this or else we won't get pull request branches correctly |
| 97 | + # repository: linkml/linkml-runtime |
| 98 | + path: linkml-runtime |
| 99 | + fetch-depth: 0 |
| 100 | + |
| 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 |
| 109 | + if: github.repository != 'linkml/linkml-runtime' |
| 110 | + working-directory: linkml-runtime |
| 111 | + run: | |
| 112 | + git remote add upstream https://github.com/linkml/linkml-runtime |
| 113 | + git fetch upstream --tags |
| 114 | +
|
| 115 | + - name: set up python |
| 116 | + uses: actions/setup-python@v5 |
| 117 | + with: |
| 118 | + python-version: ${{ matrix.python-version }} |
| 119 | + |
| 120 | + - name: Install poetry |
| 121 | + run: pipx install poetry==1.* |
| 122 | + |
| 123 | + - name: Check Poetry version |
| 124 | + run: poetry --version |
| 125 | + |
| 126 | + - name: Install dynamic versioning plugin |
| 127 | + run: poetry self add "poetry-dynamic-versioning[plugin]" |
| 128 | + |
| 129 | + - name: Load cached venv |
| 130 | + id: cached-poetry-dependencies |
| 131 | + uses: actions/cache@v3 |
| 132 | + with: |
| 133 | + path: linkml/.venv |
| 134 | + key: venv-${{ matrix.python-version }}-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 135 | + |
| 136 | + # make extra sure we're removing any old version of linkml-runtime that exists |
| 137 | + - name: uninstall potentially cached linkml-runtime |
| 138 | + working-directory: linkml |
| 139 | + run: poetry run pip uninstall -y linkml-runtime |
| 140 | + |
| 141 | + # we are not using linkml-runtime's lockfile, but simulating what will happen |
| 142 | + # when we merge this and update linkml's lockfile |
| 143 | + - name: add linkml-runtime to lockfile |
| 144 | + working-directory: linkml |
| 145 | + run: poetry add ../linkml-runtime |
| 146 | + |
| 147 | + # note that we run the installation step always, even if we restore a venv, |
| 148 | + # the cache will restore the old version of linkml-runtime, but the lockfile |
| 149 | + # will only store the directory dependency (and thus will reinstall it) |
| 150 | + # the cache will still speedup the rest of the installation |
| 151 | + - name: install linkml |
| 152 | + working-directory: linkml |
| 153 | + run: poetry install --no-interaction -E tests |
| 154 | + |
| 155 | + - name: print linkml-runtime version |
| 156 | + working-directory: linkml |
| 157 | + run: poetry run python -c 'import linkml_runtime; from importlib.metadata import version; print(linkml_runtime.__file__); print(version("linkml_runtime"))' |
| 158 | + |
| 159 | + - name: run tests |
| 160 | + working-directory: linkml |
| 161 | + run: poetry run python -m pytest --with-slow |
| 162 | + |
| 163 | + |
| 164 | + |
0 commit comments