Skip to content

Commit 04e3ffd

Browse files
authored
Migrate from Azure to GH Actions (#1306)
* add pytest workflow * add some comments * set fail-fast to false * see if secrets work * move --remote-data tests to other workflow * remove secrets from default pytest workflow * simplify bare environment installation * simplify * un-simplify * thrashing around the "debug the CI" morass * fix macos py3.6 * disable codecov upload in azure pipelines * enable codecov in github actions * fix janky coverage hack * undo unnecessary changes to .coveragerc * add label reminder to PR template * rework workflows and codecov * whatsnew * remove azure config files * don't pytest on all pushes, only master * build sdist on PRs * switch to more convenient environment filenames * use most recent checkout action
1 parent f928d39 commit 04e3ffd

15 files changed

+251
-202
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
- [ ] Adds description and name entries in the appropriate "what's new" file in [`docs/sphinx/source/whatsnew`](https://github.com/pvlib/pvlib-python/tree/master/docs/sphinx/source/whatsnew) for all changes. Includes link to the GitHub Issue with `` :issue:`num` `` or this Pull Request with `` :pull:`num` ``. Includes contributor name and/or GitHub username (link with `` :ghuser:`user` ``).
88
- [ ] New code is fully documented. Includes [numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) compliant docstrings, examples, and comments where necessary.
99
- [ ] Pull request is nearly complete and ready for detailed review.
10-
- [ ] Maintainer: Appropriate GitHub Labels and Milestone are assigned to the Pull Request and linked Issue.
10+
- [ ] Maintainer: Appropriate GitHub Labels (including `remote-data`) and Milestone are assigned to the Pull Request and linked Issue.
1111

1212
<!-- Brief description of the problem and proposed solution (if not already fully described in the issue linked to above): -->

.github/workflows/publish.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: Publish distributions to PyPI
22

3-
# if this workflow is modified to be a generic CI workflow then
4-
# add an if statement to the publish step so it only runs on tags.
53
on:
4+
pull_request:
65
push:
7-
tags:
8-
- "v*"
6+
branches:
7+
- master
98

109
jobs:
1110
build-n-publish:
@@ -31,7 +30,9 @@ jobs:
3130
- name: Build packages
3231
run: python setup.py sdist bdist_wheel
3332

33+
# only publish distribution to PyPI for tagged commits
3434
- name: Publish distribution to PyPI
35+
if: startsWith(github.ref, 'refs/tags/v')
3536
uses: pypa/gh-action-pypi-publish@master
3637
with:
3738
user: __token__
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# A secondary test job that only runs the iotools tests if explicitly requested
2+
# (for pull requests) or on a push to the master branch.
3+
# Because the iotools tests require GitHub secrets, we need to be careful about
4+
# malicious PRs accessing the secrets and exposing them externally.
5+
#
6+
# We prevent this by only running this workflow when a maintainer has looked
7+
# over the PR's diff and verified that nothing malicious seems to be going on.
8+
# The maintainer then adds the "remote-data" label to the PR, which will then
9+
# trigger this workflow via the combination of the "on: ... types:"
10+
# and "if:" sections below. The first restricts the workflow to only run when
11+
# a label is added to the PR and the second requires one of the PR's labels
12+
# is the "remote-data" label. Technically this is slightly different from
13+
# triggering when the "remote-data" label is added, since it will also trigger
14+
# when "remote-data" is added, then later some other label is added. Maybe
15+
# there's a better way to do this.
16+
#
17+
# But wait, you say! Can't a malicious PR get around this by modifying
18+
# this workflow file and removing the label requirement? I think the answer
19+
# is "no" as long as we trigger the workflow on "pull_request_target" instead
20+
# of the usual "pull_request". The difference is what context the workflow
21+
# runs inside: "pull_request" runs in the context of the fork, where changes
22+
# to the workflow definition will take immediate effect, while "pull_request_target"
23+
# runs in the context of the main pvlib repository, where the original (non-fork)
24+
# workflow definition is used instead. Of course by switching away from the fork's
25+
# context to keep our original workflow definitions, we're also keeping all the
26+
# original code, so the tests won't be run against the PR's new code. To fix this
27+
# we explicitly check out the PR's code as the first step of the workflow.
28+
# This allows the job to run modified pvlib & pytest code, but only ever via
29+
# the original workflow file.
30+
# So long as a maintainer always verifies that the PR's code is not malicious prior to
31+
# adding the label and triggering this workflow, I think this should not present
32+
# a security risk.
33+
#
34+
# Note that this workflow can be triggered again by removing and re-adding the
35+
# "remote-data" label to the PR.
36+
#
37+
# Note also that "pull_request_target" is also the only way for the secrets
38+
# to be accessible in the first place.
39+
#
40+
# Further reading:
41+
# - https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
42+
# - https://i.8713187.xyzmunity/t/can-workflow-changes-be-used-with-pull-request-target/178626/7
43+
44+
name: pytest-remote-data
45+
46+
on:
47+
pull_request_target:
48+
types: [labeled]
49+
push:
50+
branches:
51+
- master
52+
53+
jobs:
54+
test:
55+
56+
strategy:
57+
fail-fast: false # don't cancel other matrix jobs when one fails
58+
matrix:
59+
python-version: [3.6, 3.7, 3.8, 3.9]
60+
suffix: [''] # the alternative to "-min"
61+
include:
62+
- python-version: 3.6
63+
suffix: -min
64+
65+
runs-on: ubuntu-latest
66+
if: (github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'remote-data')) || (github.event_name == 'push')
67+
68+
steps:
69+
- uses: actions/checkout@v3
70+
if: github.event_name == 'pull_request_target'
71+
# pull_request_target runs in the context of the target branch (pvlib/master),
72+
# but what we need is the hypothetical merge commit from the PR:
73+
with:
74+
ref: "refs/pull/${{ github.event.number }}/merge"
75+
76+
- uses: actions/checkout@v2
77+
if: github.event_name == 'push'
78+
79+
- name: Set up conda environment
80+
uses: conda-incubator/setup-miniconda@v2
81+
with:
82+
activate-environment: test_env
83+
environment-file: ${{ env.REQUIREMENTS }}
84+
python-version: ${{ matrix.python-version }}
85+
auto-activate-base: false
86+
env:
87+
# build requirement filename. First replacement is for the python
88+
# version, second is to add "-min" if needed
89+
REQUIREMENTS: ci/requirements-py${{ matrix.python-version }}${{ matrix.suffix }}.yml
90+
91+
- name: List installed package versions
92+
shell: bash -l {0} # necessary for conda env to be active
93+
run: conda list
94+
95+
- name: Run tests
96+
shell: bash -l {0} # necessary for conda env to be active
97+
env:
98+
# copy GitHub Secrets into environment variables for the tests to access
99+
NREL_API_KEY: ${{ secrets.NRELAPIKEY }}
100+
BSRN_FTP_USERNAME: ${{ secrets.BSRN_FTP_USERNAME }}
101+
BSRN_FTP_PASSWORD: ${{ secrets.BSRN_FTP_PASSWORD }}
102+
run: pytest pvlib/tests/iotools pvlib/tests/test_forecast.py --cov=./ --cov-report=xml --remote-data
103+
104+
- name: Upload coverage to Codecov
105+
if: matrix.python-version == 3.6 && matrix.suffix == ''
106+
uses: codecov/codecov-action@v2
107+
with:
108+
fail_ci_if_error: true
109+
verbose: true
110+
flags: remote-data # flags are configured in codecov.yml

.github/workflows/pytest.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: pytest
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
test:
11+
12+
strategy:
13+
fail-fast: false # don't cancel other matrix jobs when one fails
14+
matrix:
15+
# use macos-10.15 instead of macos-latest for py3.6 support
16+
os: [ubuntu-latest, macos-10.15, windows-latest]
17+
python-version: [3.6, 3.7, 3.8, 3.9]
18+
environment-type: [conda, bare]
19+
suffix: [''] # placeholder as an alternative to "-min"
20+
include:
21+
- os: ubuntu-latest
22+
python-version: 3.6
23+
environment-type: conda
24+
suffix: -min
25+
exclude:
26+
- os: macos-10.15
27+
environment-type: conda
28+
- os: windows-latest
29+
environment-type: bare
30+
31+
runs-on: ${{ matrix.os }}
32+
33+
steps:
34+
- uses: actions/checkout@v3
35+
36+
- name: Set up conda environment
37+
if: matrix.environment-type == 'conda'
38+
uses: conda-incubator/setup-miniconda@v2
39+
with:
40+
activate-environment: test_env
41+
environment-file: ${{ env.REQUIREMENTS }}
42+
python-version: ${{ matrix.python-version }}
43+
auto-activate-base: false
44+
env:
45+
# build requirement filename. First replacement is for the python
46+
# version, second is to add "-min" if needed
47+
REQUIREMENTS: ci/requirements-py${{ matrix.python-version }}${{ matrix.suffix }}.yml
48+
49+
- name: List installed package versions (conda)
50+
if: matrix.environment-type == 'conda'
51+
shell: bash -l {0} # necessary for conda env to be active
52+
run: conda list
53+
54+
- name: Install bare Python ${{ matrix.python-version }}${{ matrix.suffix }}
55+
if: matrix.environment-type == 'bare'
56+
uses: actions/setup-python@v1
57+
with:
58+
python-version: ${{ matrix.python-version }}
59+
60+
- name: Set up bare environment
61+
if: matrix.environment-type == 'bare'
62+
run: |
63+
pip install .[test]
64+
pip freeze
65+
66+
- name: Run tests
67+
shell: bash -l {0} # necessary for conda env to be active
68+
run: |
69+
# ignore iotools & forecast; those tests are run in a separate workflow
70+
pytest pvlib --cov=./ --cov-report=xml --ignore=pvlib/tests/iotools --ignore=pvlib/tests/test_forecast.py
71+
72+
- name: Upload coverage to Codecov
73+
if: matrix.python-version == 3.6 && matrix.suffix == '' && matrix.os == 'ubuntu-latest' && matrix.environment-type == 'conda'
74+
uses: codecov/codecov-action@v2
75+
with:
76+
fail_ci_if_error: true
77+
verbose: true
78+
flags: core # flags are configured in codecov.yml

azure-pipelines.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

ci/azure/conda_linux.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

ci/azure/conda_windows.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)