0

I want to test my Python package not only when built locally, but also when it is installed via pip. For this, I basically want to do a pip3 install git+https://github.com/…, like this:

name: CI test

on: [push, pull_request]

jobs:
  tests:
    name: Pip test
    runs-on: ubuntu-20.04

    steps:
      - name: Setup basic environment
        run: |
          sudo apt-get update
          sudo apt-get install --no-install-recommends python3-dev python3-pip

      - name: Install my package via pip
        run: |
          pip3 install git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA

      - name: Run tests
        run: |
          python3 -m pytest -s --pyargs mypkg

This works nicely for pushed commits, but the Pull Request actions fail claiming that the GITHUB_SHA is "not a tree". How can I change this so that it works on both commits and pull requests?

olebole
  • 521
  • 4
  • 17
  • Why not just checkout code and run `pip install .`? I think they are basically the same. – Allan Chain Sep 07 '21 at 06:59
  • I want to be as close as possible on a user's pip install, and this would do it without an explicit git checkout. – olebole Sep 07 '21 at 07:04
  • https://stackoverflow.com/a/50095199/7976758 Found in https://stackoverflow.com/search?q=%5Bpip%5D+install+pull+request. Unfortunately, I don't see any variable that holds PR number. – phd Sep 07 '21 at 11:57
  • Most probably you should use [`$GITHUB_HEAD_REF`](https://docs.github.com/en/actions/reference/environment-variables) – phd Sep 07 '21 at 12:13
  • From the link, `$GITHUB_HEAD_REF` is only available on pull requests, not on push actions. I would need both. – olebole Sep 07 '21 at 13:35

0 Answers0