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

Add pytest in GitHub Actions #9

Merged
merged 25 commits into from
Oct 23, 2024
Merged

Conversation

jpfleischer
Copy link
Contributor

This change adds an automated pytest using the conda environment.
The workflow is inspired from the one in e-mission-server: https://github.com/e-mission/e-mission-server/blob/master/.github/workflows/test-with-manual-install.yml

Add pytest with conda

Allow workflow to run on pytest branch

Fix script location

Fix conda environment sourcing

Add conda version script

Add conda init

Test setup miniconda

Add conda creation

Test

Fix conda environment name

Add execute permissions

Fix pytest command

Activate emcommon

Fix footprint calculations

Attempt to fix footprint test

Attempt to fix footprint test

Add MODE for footprint test

Reset test footprint

Sync with Jack
Copy link
Owner

@JGreenlee JGreenlee left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. This has been on my todo list.

I think this can be significantly simplified and expanded to include the Javascript tests as well

Copy link
Owner

Choose a reason for hiding this comment

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

there's no diff here so I'm guessing you just made it executable, which is good

Comment on lines 7 to 20
on:
push:
branches:
- master
- pytest
- gis-based-mode-detection
pull_request:
branches:
- master
- pytest
- gis-based-mode-detection
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '5 4 * * 0'
Copy link
Owner

@JGreenlee JGreenlee Sep 19, 2024

Choose a reason for hiding this comment

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

It can run on any push or PR to master. Don't need the other branches and don't need a schedule

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
Copy link
Owner

Choose a reason for hiding this comment

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

Ultimately I'd like to have 2 jobs that run in parallel, one for pytest and one for jest. Maybe this workflow can be named more generally

Comment on lines 35 to 69
- uses: actions/checkout@v2

- name: Install and start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.4.0

- uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
channels: bioconda, conda-forge, defaults
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
auto-update-conda: true
auto-activate-base: true

- name: Check existing version of miniconda
shell: bash -l {0}
run: conda info -a

- name: Install emcommon conda environment
shell: bash -l {0}
run: |
# echo Test
conda env update -n emcommon -f bin/environment.yml

- name: Show current conda environment
shell: bash -l {0}
run: |
conda activate emcommon && conda info --envs

- name: Switch to emcommon and run the tests
shell: bash -l {0}
run: |
conda activate emcommon
PYTHONPATH=./src pytest test --asyncio-mode=auto
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think all of this is needed because setup.sh handles setting up the conda environment.

Can it just run setup.sh followed by run_pytest.sh?

@jpfleischer
Copy link
Contributor Author

I have implemented all of the above. Thank you for your feedback.
Please let me know if you want the js compilation automated

Copy link
Owner

@JGreenlee JGreenlee left a comment

Choose a reason for hiding this comment

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

I apologize for this late feedback; I wrote these comments weeks ago but had left them "pending" so they were not visible yet.

README.md Outdated
Comment on lines 11 to 12
Anaconda is required.

Copy link
Owner

Choose a reason for hiding this comment

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

It should not be necessary to install Anaconda manually, since the setup script automatically downloads miniconda and uses that.

Does this differ from what you've experienced?

README.md Outdated
@@ -21,7 +23,7 @@ Re-run this if you change the dependencies in `environment.yml` or `package.json
## To contribute

1. Make your changes to Python code under the `src` directory.
1. Run `bash bin/compile_to_js.sh` to build the JavaScript. This will produce output JS files in the `emcommon_js` directory.
1. Run `bash bin/compile_to_js.sh` to build the JavaScript. This will produce output JS files in the `emcommon_js` directory. However, `pip install transcrypt` is required.
Copy link
Owner

Choose a reason for hiding this comment

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

The setup script should automatically install transcrypt to the emcommon conda environment, so pip install transcrypt should not be necessary either

export_versions.sh is in the 'setup' folder of e-mission-server and will be downloaded dynamically via bin/setup.sh; does not need to be duplicated here

We do not need babel to run the jest tests because Transcrypt outputs jest-compliant JS
Copy link
Owner

@JGreenlee JGreenlee left a comment

Choose a reason for hiding this comment

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

Since I was so late with giving feedback and we want to unblock #10, I went ahead and made the changes I was looking for to the workflow.

Next I will squash merge to keep the commit history clean.

@JGreenlee JGreenlee merged commit e8ae9dc into JGreenlee:master Oct 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants