Skip to content

Commit b6818c0

Browse files
committed
Add workflow to run gdrive and aws tests on forks with a label.
1 parent c2f4643 commit b6818c0

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

.github/workflows/code_test_and_deploy.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
tags:
88
- 'v*'
99
pull_request:
10-
types: [opened, synchronize, reopened, ready_for_review]
10+
1111
schedule:
1212
# Cron runs on the 1st and 15th of every month.
1313
# This will only run on main by default.
@@ -20,6 +20,7 @@ jobs:
2020
- uses: neuroinformatics-unit/actions/lint@v2
2121

2222
test:
23+
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
2324
needs: [linting]
2425
name: ${{ matrix.os }} py${{ matrix.python-version }}
2526
runs-on: ${{ matrix.os }}
@@ -74,22 +75,29 @@ jobs:
7475
sudo service mysql stop # free up port 3306 for ssh tests
7576
pytest tests/tests_transfers/ssh
7677
77-
- name: Test Google Drive
78+
- name: Test Google Drive and AWS
79+
# AWS and GDrive tests require secrets, which are empty string by default on forked repositories.
80+
# The below flag ensures that these tests do not run on forked repositories. To run, the
81+
# ok-to-run-gdrive-aws label must be manually added, after checking no malicious code
82+
# that extracts the secrets is found on the PR.
83+
if: >
84+
github.event_name != 'pull_request' ||
85+
github.event.pull_request.head.repo.full_name == github.repository ||
86+
contains(
87+
join(fromJSON('["' + join(github.event.pull_request.labels.*.name, '","') + '"]')),
88+
'ok-to-run-gdrive-aws'
89+
)
7890
env:
7991
GDRIVE_CLIENT_ID: ${{ secrets.GDRIVE_CLIENT_ID }}
8092
GDRIVE_CLIENT_SECRET: ${{ secrets.GDRIVE_CLIENT_SECRET }}
8193
GDRIVE_ROOT_FOLDER_ID: ${{ secrets.GDRIVE_ROOT_FOLDER_ID }}
8294
GDRIVE_CONFIG_TOKEN: ${{ secrets.GDRIVE_CONFIG_TOKEN }}
83-
run: |
84-
pytest tests/tests_transfers/gdrive
85-
86-
- name: Test AWS
87-
env:
8895
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
8996
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
9097
AWS_REGION: ${{ secrets.AWS_REGION }}
9198
AWS_BUCKET_NAME: ${{ secrets.AWS_BUCKET_NAME }}
9299
run: |
100+
pytest tests/tests_transfers/gdrive
93101
pytest tests/tests_transfers/aws
94102
95103
- name: All Other Tests
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Secure Tests Workflow
2+
#
3+
# Runs the Google Drive and AWS transfer tests that need secrets.
4+
# GitHub doesn’t pass secrets to pull requests from forks, so this
5+
# workflow exists to let maintainers explicitly approve those runs.
6+
7+
name: Secure tests (label gated)
8+
9+
on:
10+
pull_request_target:
11+
types: [labeled]
12+
13+
jobs:
14+
run-secure-tests:
15+
if: github.event.label.name == 'ok-to-run-gdrive-aws'
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
20+
steps:
21+
- name: Checkout PR merge ref
22+
uses: actions/checkout@v4
23+
with:
24+
ref: refs/pull/${{ github.event.pull_request.number }}/merge
25+
26+
- name: Set up Conda
27+
uses: conda-incubator/setup-miniconda@v3
28+
with:
29+
python-version: 3.12
30+
channels: conda-forge
31+
activate-environment: datashuttle-test
32+
33+
- name: Install deps
34+
run: |
35+
conda activate datashuttle-test
36+
conda install -c conda-forge -y rclone
37+
python -m pip install --upgrade pip
38+
pip install .[dev]
39+
40+
- name: Google Drive tests
41+
env:
42+
GDRIVE_CLIENT_ID: ${{ secrets.GDRIVE_CLIENT_ID }}
43+
GDRIVE_CLIENT_SECRET: ${{ secrets.GDRIVE_CLIENT_SECRET }}
44+
GDRIVE_ROOT_FOLDER_ID: ${{ secrets.GDRIVE_ROOT_FOLDER_ID }}
45+
GDRIVE_CONFIG_TOKEN: ${{ secrets.GDRIVE_CONFIG_TOKEN }}
46+
run: pytest tests/tests_transfers/gdrive
47+
48+
- name: AWS tests
49+
env:
50+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
51+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
52+
AWS_REGION: ${{ secrets.AWS_REGION }}
53+
AWS_BUCKET_NAME: ${{ secrets.AWS_BUCKET_NAME }}
54+
run: pytest tests/tests_transfers/aws

tests/tests_transfers/aws/aws_test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ def has_aws_environment_variables():
5353
]:
5454
if key not in os.environ:
5555
return False
56+
57+
if os.environ[key].strip() == "":
58+
return False
59+
5660
return True

tests/tests_transfers/gdrive/gdrive_test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ def has_gdrive_environment_variables():
6767
]:
6868
if key not in os.environ:
6969
return False
70+
71+
if os.environ[key].strip() == "":
72+
return False
73+
7074
return True

0 commit comments

Comments
 (0)