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
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
921998d
Add automated pytest with GitHub Actions and fix egrid test
jpfleischer Sep 19, 2024
0d6e434
Merge branch 'master' of https://github.com/JGreenlee/e-mission-commo…
jpfleischer Sep 19, 2024
22a9c18
Remove redundant GitHub Actions jobs
jpfleischer Sep 19, 2024
8633c2c
Add jest job
jpfleischer Sep 20, 2024
8d0bcc9
Fix npm test
jpfleischer Sep 20, 2024
fd71135
Fix jest
jpfleischer Sep 20, 2024
cd8250a
Fix babel and jest
jpfleischer Sep 20, 2024
8ce82d2
Remove .babelrc
jpfleischer Sep 20, 2024
65820a6
Try to see the exception in github actions
jpfleischer Sep 20, 2024
9ff5581
Debug no fetch
jpfleischer Sep 20, 2024
4676309
Reset util.js
jpfleischer Sep 20, 2024
2c1698d
Update emcommon.metrics.footprint.util.js
jpfleischer Sep 20, 2024
85ad3ca
Fix end of line
jpfleischer Sep 20, 2024
400431a
Simplify workflow jobs
jpfleischer Sep 20, 2024
f0c6af9
Add miniconda
jpfleischer Sep 20, 2024
e880ad8
Debug
jpfleischer Sep 20, 2024
1f17500
Add architecture to platform
jpfleischer Sep 20, 2024
60ff612
Elaborate on prerequisites for README
jpfleischer Sep 20, 2024
462e5d6
Simplify workflow yaml
jpfleischer Sep 20, 2024
37488fd
Merge branch 'master' of https://github.com/JGreenlee/e-mission-commo…
JGreenlee Oct 23, 2024
27d9999
remove unneeded files/packages
JGreenlee Oct 23, 2024
dc5e097
Merge branch 'master' of https://github.com/JGreenlee/e-mission-commo…
JGreenlee Oct 23, 2024
4a05a62
Revert "remove unit-tests.yml experiment"
JGreenlee Oct 23, 2024
4316185
update README, remove unneeded notes, add GH Actions section
JGreenlee Oct 23, 2024
9ef8349
make all bin/*.sh scripts executable
JGreenlee Oct 23, 2024
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
56 changes: 56 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# taken from https://github.com/e-mission/e-mission-server/blob/master/.github/workflows/test-with-manual-install.yml

name: pytest

# Controls when the action will run. Triggers the workflow on push or pull request
on:
push:
pull_request:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test-pytest:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
auto-update-conda: true
auto-activate-base: true

- name: Run setup
shell: bash -l {0}
run: |
set -x && . bin/setup.sh

- name: Run pytest
shell: bash -l {0}
run: |
. bin/run_pytest.sh

test-jest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22'

- name: Install dependencies
run: npm install

- name: Run jest tests
run: npx jest
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ This repository uses the [Transcrypt](https://www.transcrypt.org/) library to co

## Setup

```
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?

```bash
. bin/setup.sh
```

Expand All @@ -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

1. Commit changes from both the `src` and `emcommon_js` directories to your branch.

## Tips for writing code to work in both Python and JavaScript
Expand Down
4 changes: 4 additions & 0 deletions bin/export_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# taken from https://github.com/e-mission/e-mission-server/blob/master/setup/export_versions.sh

export EXP_CONDA_VER=23.5.2
export EXP_CONDA_VER_SUFFIX=0
Empty file modified bin/run_pytest.sh
100644 → 100755
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

Empty file.
41 changes: 31 additions & 10 deletions bin/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
#!/bin/bash

# Check if conda exists
if ! command -v conda &> /dev/null; then
echo "conda could not be found"
return 1
fi

# Determine platform and architecture
ARCH=$(uname -m)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
TARGET_PLATFORM="Linux-x86_64"
elif [[ "$ARCH" == "aarch64" ]]; then
TARGET_PLATFORM="Linux-aarch64"
else
echo "Unsupported architecture $ARCH on Linux"
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
TARGET_PLATFORM="MacOSX-x86_64"
elif [[ "$ARCH" == "arm64" ]]; then
TARGET_PLATFORM="MacOSX-arm64"
else
echo "Unsupported architecture $ARCH on macOS"
exit 1
fi
else
echo "Unsupported platform $OSTYPE"
exit 1
fi

# copy the 'setup' directory from the e-mission-server repo
git clone -n --depth=1 --filter=tree:0 https://github.com/e-mission/e-mission-server.git
cd e-mission-server
Expand All @@ -9,16 +40,6 @@ cp -r setup ../
cd ..
rm -rf e-mission-server

# determine platform
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
TARGET_PLATFORM="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
TARGET_PLATFORM="mac"
else
echo "Unsupported platform $OSTYPE"
exit 1
fi

# set up conda using the e-mission-server scripts
. setup/setup_conda.sh $TARGET_PLATFORM
. setup/activate_conda.sh
Expand Down
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"description": "A common library to share code between projects in the e-mission-platform. Written in Python and exposed as both Python and JavaScript.",
"main": "./emcommon_js/index.js",
"types": "./emcommon_js/dist/index.d.ts",
"scripts": {
"test": "jest"
},
"jest": {
"testMatch": [
"**/test_*.js"
],
"globals": { "window": {} },
"transform": {}
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
},
"prettier": {
"printWidth": 100,
Expand All @@ -25,8 +30,18 @@
"dependencies": {
"color": "^3.1.2"
},
"babel": {
"presets": [
"@babel/preset-env"
]
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@babel/preset-env": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.14.5",
"babel-jest": "^27.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"mapshaper": "^0.6.99",
Expand Down