Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: limit installs for dependent-tests.yml #792

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
17 changes: 17 additions & 0 deletions .github/scripts/update_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import argparse
import fileinput
from pathlib import Path

Expand All @@ -22,6 +23,13 @@
# dependency, we can do this for the ones we own to make sure that when the sdk updates
# its dependencies, these upstream github repos will not be impacted.

parser = argparse.ArgumentParser()

# --branch={branch_name}
parser.add_argument("-b", "--branch", help="PR branch name")

args = parser.parse_args()

package = "amazon-braket-sdk"
path = Path.cwd().parent.resolve()

Expand All @@ -32,3 +40,12 @@
line if package not in line else f'"{package} @ file://{path}/{package}-python",\n'
)
print(replaced_line, end="")

for line in fileinput.input("tox.ini", inplace=True):
# Ensure that tox uses the working branch for the SDK PR.
replaced_line = (
line
if package not in line
else f" git+https://github.com/amazon-braket/{package}-python.git@{args.branch}\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work if someone is raising a PR from their personal fork. Is there a way we could handle that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am testing this with a forked branch of the repo. The action runner syncs the repo so this should work across forks with the new commit

)
print(replaced_line, end="")
13 changes: 7 additions & 6 deletions .github/workflows/dependent-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ jobs:
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: ${{ matrix.python-version }}
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Install dependencies
run: |
pip install --upgrade pip
pip install --upgrade git+https://github.com/aws/amazon-braket-schemas-python.git@main
pip install --upgrade git+https://github.com/aws/amazon-braket-default-simulator-python.git@main
pip install -e .
cd ..
git clone https://github.com/aws/${{ matrix.dependent }}.git
cd ${{ matrix.dependent }}
# Update the amazon-braket-sdk dependency to reference the current commit
python ${GITHUB_WORKSPACE}/.github/scripts/update_dependency.py
pip install -e .[test]
python ${GITHUB_WORKSPACE}/.github/scripts/update_dependency.py --branch ${{ steps.extract_branch.outputs.branch }}
pip install tox
- name: Run unit tests
run: |
cd ../${{ matrix.dependent }}
pytest
tox -e unit-tests
Loading