Skip to content

Commit

Permalink
Merge pull request #9038 from gem/fork-requirements
Browse files Browse the repository at this point in the history
Use GITHUB_REPOSITORY variable to install requirements from master in actions triggered by a fork
  • Loading branch information
ptormene committed Sep 26, 2023
2 parents 6b94e8d + c8f291b commit 328e9a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/engine_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
python-version: ["3.10"]
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REPOSITORY: ${{ github.repository }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -23,7 +24,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python install.py devel --version=$GITHUB_HEAD_REF
python install.py devel --version=$GITHUB_HEAD_REF --repository=$GITHUB_REPOSITORY
- name: Calculators and documentation tests
run: |
source ~/openquake/bin/activate
Expand All @@ -38,7 +39,8 @@ jobs:
os: [ubuntu-latest]
python-version: ["3.10"]
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REPOSITORY: ${{ github.repository }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -47,7 +49,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python install.py devel --version=$GITHUB_HEAD_REF
python install.py devel --version=$GITHUB_HEAD_REF --repository=$GITHUB_REPOSITORY
- name: Hazardlib tests
run: |
source ~/openquake/bin/activate
Expand All @@ -65,6 +67,7 @@ jobs:
python-version: ["3.10"]
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REPOSITORY: ${{ github.repository }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -73,7 +76,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python install.py devel --version=$GITHUB_HEAD_REF
python install.py devel --version=$GITHUB_HEAD_REF --repository=$GITHUB_REPOSITORY
- name: Server 'PUBLIC' mode tests
run: |
source ~/openquake/bin/activate
Expand All @@ -89,6 +92,7 @@ jobs:
python-version: ["3.10"]
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REPOSITORY: ${{ github.repository }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -97,7 +101,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python install.py devel --version=$GITHUB_HEAD_REF
python install.py devel --version=$GITHUB_HEAD_REF --repository=$GITHUB_REPOSITORY
- name: Server 'READ_ONLY' mode tests
run: |
source ~/openquake/bin/activate
Expand All @@ -113,6 +117,7 @@ jobs:
python-version: ["3.10"]
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_REPOSITORY: ${{ github.repository }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -121,7 +126,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python install.py devel --version=$GITHUB_HEAD_REF
python install.py devel --version=$GITHUB_HEAD_REF --repository=$GITHUB_REPOSITORY
- name: Server 'AELO' mode tests
run: |
source ~/openquake/bin/activate
Expand Down
14 changes: 10 additions & 4 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ def ensure(pip=None, pyvenv=None):
% sys.executable))


def get_branch(version, inst):
def get_requirements_branch(version, inst, repository):
"""
Convert "version" into a branch name
"""
if repository != 'gem/oq-engine':
return 'master'
if version is None:
if (inst is devel or inst is devel_server):
return 'master'
Expand Down Expand Up @@ -336,7 +338,7 @@ def fix_version(commit, venv):
f.write(''.join(lines))


def install(inst, version):
def install(inst, version, repository):
"""
Install the engine in one of the three possible modes
"""
Expand Down Expand Up @@ -383,7 +385,7 @@ def install(inst, version):
'pip', 'wheel'])

# install the requirements
branch = get_branch(version, inst)
branch = get_requirements_branch(version, inst, repository)
if sys.platform == 'darwin':
mac = '_' + platform.machine(), # x86_64 or arm64
else:
Expand Down Expand Up @@ -534,6 +536,10 @@ def remove(inst):
help="version to install (default stable)")
parser.add_argument("--dbport",
help="DbServer port (default 1907 or 1908)")
parser.add_argument("--repository",
help=("The owner and repository name. For example,"
" 'gem/oq-engine' or 'forkowner/oq-engine'"),
default='gem/oq-engine')
args = parser.parse_args()
if args.inst:
inst = globals()[args.inst]
Expand All @@ -542,6 +548,6 @@ def remove(inst):
if args.remove:
remove(inst)
else:
install(inst, args.version)
install(inst, args.version, args.repository)
else:
sys.exit("Please specify the kind of installation")

0 comments on commit 328e9a3

Please sign in to comment.