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

Migrate unit and integration tests from TravisCI to GitHub Actions #580

Merged
merged 19 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/actions/install-icepyx/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Install icepyx'
description: 'Install icepyx and dev dependencies'

inputs:
python-version:
required: true

runs:
using: "composite"
steps:
- uses: "actions/setup-python@v5"
with:
python-version: "${{ inputs.python-version }}"

- name: "Install package and test dependencies"
shell: "bash"
run: |
python -m pip install .
python -m pip install -r requirements-dev.txt
40 changes: 40 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Integration test"
# NOTE: We're just running the tests that require earthdata login here; we
# don't distinguish between unit and integration tests yet.

on:
pull_request:
push:
branches:
- "main"
- "development"
Copy link
Member

Choose a reason for hiding this comment

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

Given these are slightly "expensive" tests since they download files (and running them for every commit could ultimately influence the icepyx metrics), what are our options for restricting how often they run for a given PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

These triggers (branches:) would be for every merge, not for every commit on PRs. We can customize the pull_request: triggers. By default, they run on open and synchronize (effectively, when the PR is pushed to, not on every commit). The full list is here: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request

I think the best way we can limit these runs is by adding paths: filters. That would enable e.g. docs changes to not trigger the expensive tests!

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we consider this part of this PR, or create an issue to track the work?

Copy link
Member

Choose a reason for hiding this comment

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

(effectively, when the PR is pushed to, not on every commit).

Right - forgot this subtlety - but a PR can have a lot of pushes too!

Should we consider this part of this PR, or create an issue to track the work?

I would definitely consider it part of this PR. I don't want to have a setup running that will trigger so many runs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would definitely consider it part of this PR. I don't want to have a setup running that will trigger so many runs.

Don't want to push back too hard, because I am fine doing it however, but I do want to raise that Travis CI behaves this way already:

https://github.com/icesat2py/icepyx/blob/development/.travis.yml#L21-L24

I would lean towards breaking this work into two PRs: (1) migrate Travis -> GH; (2) more efficient. When those PRs are merged into development, they will produce two clearer commits and entries in the changelog. I'm OK with immediately following this PR up with step 2 if you're OK with dividing it!

Copy link
Member Author

@mfisher87 mfisher87 Aug 27, 2024

Choose a reason for hiding this comment

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

Or "approved"? I think this is how I set up the uml diagram action so it only runs once per PR.

There is no approved event type. That workflow checks the current state of the PR after triggering the workflow, and if it's not "approved", it sets the workflow to "skipped":

if: github.event.review.state == 'approved'

If there was an approved event type, then we could avoid the triggering in the first place :(

Since we have other possible triggers we would need something like ${{ github.event.action != "pull_request_review" || github.event.review.state == "approved" }}. Otherwise, integration tests would be skipped on our release PRs until they were approved, and if we want that behavior we can remove the pull_request trigger. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

There is no approved event type.

Guess that was wishful thinking on my part then.

Since we have other possible triggers we would need something like ${{ github.event.action != "pull_request_review" || github.event.review.state == "approved" }}. Otherwise, integration tests would be skipped on our release PRs until they were approved, and if we want that behavior we can remove the pull_request trigger. Thoughts?

I'm happy with the latest edits versus this. I don't think we tend to have a lot of official "reviews" until we're getting pretty close to merging, and it would be great to have the tests run on release PRs right away.

Copy link
Member

Choose a reason for hiding this comment

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

I'm happy with the latest edits versus this. I don't think we tend to have a lot of official "reviews" until we're getting pretty close to merging, and it would be great to have the tests run on release PRs right away.

I might need to rescind this. I'm noticing the integration test is running, which makes me think that GH considers a comment (regardless of approval) to be a "review", thus triggering the action for any comment made on the PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking the least unpalatable option at this point is your suggestion to remove the PR trigger and add something like ${{ github.event.action != "pull_request_review" || github.event.review.state == "approved" }}.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's try it on for size!



jobs:
test:
name: "Test"
JessicaS11 marked this conversation as resolved.
Show resolved Hide resolved
if: "github.repository == 'icesat2py/icepyx'"
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0

- uses: "./.github/actions/install-icepyx"
with:
python-version: "3.12"

- name: "Run tests"
env:
EARTHDATA_USERNAME: "${{ secrets.EARTHDATA_USERNAME }}"
mfisher87 marked this conversation as resolved.
Show resolved Hide resolved
EARTHDATA_PASSWORD: "${{ secrets.EARTHDATA_PASSWORD }}"
mfisher87 marked this conversation as resolved.
Show resolved Hide resolved
run: |
pytest icepyx/ --verbose --cov app \
icepyx/tests/test_behind_NSIDC_API_login.py \
icepyx/tests/test_auth.py

- name: "Upload coverage report"
uses: "codecov/[email protected]"
with:
token: "${{ secrets.CODECOV_TOKEN }}"
39 changes: 39 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Unit test"
# NOTE: We're just skipping the tests requiring earthdata login here; we don't
# distinguish yet between unit and integration tests.

on:
pull_request:
push:
branches:
- "main"
- "development"


jobs:
test:
runs-on: "ubuntu-latest"
JessicaS11 marked this conversation as resolved.
Show resolved Hide resolved
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.12"] #NOTE: min and max Python versions supported by icepyx

steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0

- uses: "./.github/actions/install-icepyx"
with:
python-version: "${{ matrix.python-version }}"

- name: "Run tests"
run: |
pytest icepyx/ --verbose --cov app \
--ignore=icepyx/tests/test_behind_NSIDC_API_login.py \
--ignore=icepyx/tests/test_auth.py

- name: "Upload coverage report"
uses: "codecov/[email protected]"
with:
token: "${{ secrets.CODECOV_TOKEN }}"
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

Loading