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

Automatic packaging and CI test updates #386

Merged
merged 34 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0419097
Reorganizing the requirements locations
HGSilveri Jul 11, 2022
081a1a0
WIP: Trying out composite Github actions
HGSilveri Jul 11, 2022
15d5845
Incorporating composite Github action in CI suite
HGSilveri Jul 11, 2022
8266f66
Make CI run on all PRs
HGSilveri Jul 12, 2022
8edefa5
Bug: Requirements files were switched
HGSilveri Jul 26, 2022
2c42dee
Merge branch 'develop' into auto-package
HGSilveri Jul 26, 2022
cf4d623
Moving jsonschema to requirements
HGSilveri Jul 26, 2022
e657c14
Installing only the necessary requirements in CI
HGSilveri Jul 26, 2022
92c825d
Adding pytest to type-checking required packages
HGSilveri Jul 26, 2022
09d9ded
Complementing the CI test description
HGSilveri Jul 26, 2022
fa05558
WIP: Test version check
HGSilveri Jul 27, 2022
1f87321
WIP: Check new version validity
HGSilveri Jul 27, 2022
6ea38bb
WIP: Test version validity [fail 1]
HGSilveri Jul 27, 2022
aa2d165
WIP: Test version check [fail 2]
HGSilveri Jul 27, 2022
ab75ea7
Bring version back
HGSilveri Jul 27, 2022
73662a0
Trigger new workflow run
HGSilveri Jul 27, 2022
0e8b718
WIP: Test stable version validity [fail 3]
HGSilveri Jul 27, 2022
9a3ee02
WIP: Test stable version validity [pass]
HGSilveri Jul 27, 2022
f9eb005
Finish version checker tests
HGSilveri Jul 27, 2022
e522d26
Adding full test workflow
HGSilveri Jul 27, 2022
77de473
Make full tests run on push only
HGSilveri Jul 27, 2022
f6a2d5c
Centralizing the different packages
HGSilveri Jul 28, 2022
44c0555
Add packaging script
HGSilveri Jul 28, 2022
61bc3c2
WIP: Test publish workflow
HGSilveri Jul 28, 2022
a2c1f65
Test: Trigger 'publish' workflow
HGSilveri Jul 28, 2022
28dd75a
WIP: 2nd 'publish' workflow test
HGSilveri Jul 28, 2022
cc2eff3
WIP: 3rd 'publish' workflow test
HGSilveri Jul 28, 2022
b2ff50c
Finish the 'publish' workflow
HGSilveri Jul 28, 2022
125fe3f
Documenting the Release procedure
HGSilveri Jul 29, 2022
5aa66db
Merge branch 'develop' into auto-package
HGSilveri Aug 4, 2022
c19f495
Merge branch 'develop' into auto-package
HGSilveri Aug 5, 2022
68953a4
Merge branch 'develop' into auto-package
HGSilveri Aug 8, 2022
f978dcf
Review comments + Details on merge commit messages
HGSilveri Aug 8, 2022
d70924c
Adding review suggestions
HGSilveri Aug 9, 2022
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
27 changes: 27 additions & 0 deletions .github/scripts/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Exit if something fails
set -e

# Find and change to the repository directory
repo_dir=$(git rev-parse --show-toplevel)
cd "${repo_dir}"

# Removing existing files in /dist
rm -rf dist

packages=$(cat packages.txt)
# Build the pulser packages
for pkg in $packages
do
echo "Packaging $pkg"
python $pkg/setup.py -q bdist_wheel -d "../dist"
rm -r $pkg/build
done

# Build the pulser metapackage
python setup.py -q bdist_wheel -d "dist"
rm -r build

echo "Built wheels:"
ls dist
67 changes: 22 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,60 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out Pulser
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/checkout@v3
- name: Pulser + flake8 setup
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
uses: ./.github/workflows/pulser-setup
with:
python-version: 3.8
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e ./pulser-core -e ./pulser-simulation
pip install -r requirements.txt
extra-packages: flake8
- name: Lint with flake8
run: flake8
black:
runs-on: ubuntu-latest
steps:
- name: Check out Pulser
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/checkout@v3
- name: Pulser + black setup
uses: ./.github/workflows/pulser-setup
with:
python-version: 3.8
- name: Install black
run: |
python -m pip install --upgrade pip
pip install black
pip install 'black[jupyter]'
extra-packages: black
- name: Check formatting with black
run: black --check --diff .
isort:
runs-on: ubuntu-latest
steps:
- name: Check out Pulser
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/checkout@v3
- name: Pulser + isort setup
uses: ./.github/workflows/pulser-setup
with:
python-version: 3.8
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e ./pulser-core -e ./pulser-simulation
pip install -r requirements.txt
extra-packages: isort
- name: Check import sorting with isort
run: isort --check-only --diff .
typing:
runs-on: ubuntu-latest
steps:
- name: Check out Pulser
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/checkout@v3
- name: Pulser + mypy setup
uses: ./.github/workflows/pulser-setup
with:
python-version: 3.8
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e ./pulser-core -e ./pulser-simulation
pip install -r requirements.txt
extra-packages: '''mypy\|pytest'''
MatthieuMoreau0 marked this conversation as resolved.
Show resolved Hide resolved
- name: Type check with mypy
run: mypy
test:
if: github.event_name != 'push'
Copy link
Collaborator

@MatthieuMoreau0 MatthieuMoreau0 Aug 9, 2022

Choose a reason for hiding this comment

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

Question: Why do we not run test on push events ? Not super familiar with all the event types in github actions, so maybe these test are triggered through a merge_request event or something which would be redundant with the push event

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just because I wrote a more complete test workflow to run only on push to the protected branches, so these would be redundant.

HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ${{ matrix.os }}
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.9]
steps:
- name: Check out Pulser
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/checkout@v3
- name: Pulser + pytest setup
uses: ./.github/workflows/pulser-setup
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e ./pulser-core -e ./pulser-simulation
pip install -r requirements.txt
extra-packages: pytest
- name: Run the unit tests & generate coverage report
run: pytest --cov --cov-fail-under=100
79 changes: 79 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Upload Release Package to PyPI

on:
release:
types: [released]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out Pulser
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build packages
shell: bash
run: ./.github/scripts/package.sh
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
- name: Publish to TestPyPI
env:
TWINE_USERNAME: ${{ secrets.TESTPYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TESTPYPI_PASSWORD }}
run: twine upload --repository testpypi dist/*
- name: Install from TestPyPI
timeout-minutes: 5
shell: bash
run: |
version="$(head -1 VERSION.txt)"
until pip install -i https://test.pypi.org/simple/ pulser==$version --extra-index-url https://pypi.org/simple
do
echo "Failed to install from TestPyPI, will wait for upload and retry."
sleep 30
done
- name: Test the installation
# Installs pytest from dev_requirements.txt (in case it has a version specifier)
run: |
grep -e pytest dev_requirements.txt | sed 's/ //g' | xargs pip install
pytest
- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload dist/*

check-release:
needs: deploy
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10']
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Check out Pulser
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Pulser from PyPI
shell: bash
run: |
python -m pip install --upgrade pip
pip install pulser
- name: Test the installation
shell: bash
run: |
version="$(head -1 VERSION.txt)"
python -c "import pulser; assert pulser.__version__ == '$version'"
grep -e pytest dev_requirements.txt | sed 's/ //g' | xargs pip install
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: As per my other comment, having specific extras_require would have the extra benefit to avoid duplicating this grep magic several times

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True indeed

pytest
31 changes: 31 additions & 0 deletions .github/workflows/pulser-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pulser setup
description: "Sets up Python and installs Pulser."
inputs:
python-version:
description: Python version
required: false
default: '3.9'
extra-packages:
description: Extra packages to install (give to grep)
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
- name: Install Pulser
shell: bash
run: |
python -m pip install --upgrade pip
pip install -e ./pulser-core -e ./pulser-simulation
MatthieuMoreau0 marked this conversation as resolved.
Show resolved Hide resolved
- name: Install extra packages from the dev requirements
if: "${{ inputs.extra-packages != '' }}"
shell: bash
run: |
grep -e ${{ inputs.extra-packages }} dev_requirements.txt \
| sed 's/ //g' \
| xargs pip install
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: test

on:
push:
branches:
- master
- develop
Comment on lines +5 to +7
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean that these tests would not run on feature branches before merging to develop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly. I figured they are a bit excessive to be ran on every update to a PR. There are still tests in the ci.yml that should catch everything, these tests are run just to really ensure we didn't miss anything related to a specifc OS or python version.
On the rare case something fails, we can always follow up with a fix.


jobs:
full-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Check out Pulser
uses: actions/checkout@v3
- name: Pulser + pytest setup
uses: ./.github/workflows/pulser-setup
with:
python-version: ${{ matrix.python-version }}
extra-packages: pytest
- name: Run the unit tests & generate coverage report
run: pytest --cov --cov-fail-under=100
48 changes: 48 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: version

on:
pull_request:
paths:
- 'VERSION.txt'

jobs:
validate-version:
runs-on: ubuntu-latest
steps:
- name: Check out base branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Get old version
run: |
old_version="$(head -1 VERSION.txt)"
echo "Old version: $old_version"
echo "old_version=$old_version" >> $GITHUB_ENV
- name: Check out head branch
uses: actions/checkout@v3
- name: Get new version
run: |
new_version="$(head -1 VERSION.txt)"
echo "New version: $new_version"
echo "new_version=$new_version" >> $GITHUB_ENV
- name: Compare versions
run: dpkg --compare-versions "${{ env.old_version }}" lt "${{ env.new_version }}"
- name: Check stable version validity
if: github.event.pull_request.base.ref == 'master'
run: |
pattern=^\(0\|[1-9]\d*\)\.\(0\|[1-9]\d*\)\.\(0\|[1-9]\d*\)$
if [[ ${{ env.new_version }} =~ $pattern ]]; then
echo "New version is valid."; exit 0
else
echo "New version is invalid."; exit 1
fi
- name: Check development version validity
if: github.event.pull_request.base.ref != 'master'
run: |
pattern=^\(0\|[1-9]\d*\)\.\(0\|[1-9]\d*\)dev\(0\|[1-9]\d*\)$
if [[ ${{ env.new_version }} =~ $pattern ]]; then
echo "New version is valid."; exit 0
else
echo "New version is invalid."; exit 1
fi

2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ sphinx:
python:
install:
- requirements: docs/requirements.txt
- requirements: requirements.txt
- requirements: dev_requirements.txt
- requirements: pulser-core/rtd_requirements.txt
- requirements: pulser-simulation/rtd_requirements.txt
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Here are the steps you should follow to make your contribution:
We enforce some continuous integration standards in order to maintain the quality of Pulser's code. Make sure you follow them, otherwise your pull requests will be blocked until you fix them. To check if your changes pass all CI tests before you make the PR, you'll need additional packages, which you can install by running

```shell
pip install -r requirements.txt
pip install -r dev_requirements.txt
```

- **Tests**: We use [`pytest`](https://docs.pytest.org/en/latest/) to run unit tests on our code. If your changes break existing tests, you'll have to update these tests accordingly. Additionally, we aim for 100% coverage over our code. Try to cover all the new lines of code with simple tests, which should be placed in the `Pulser/pulser/tests` folder. To run all tests and check coverage, run:
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
include README.md
include requirements.txt
include LICENSE
include VERSION.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ your installation will change accordingly.
To run the tutorials or the test suite locally, after installation first run the following to install the development requirements:

```bash
pip install -r requirements.txt
pip install -r dev_requirements.txt
```

Then, you can do the following to run the test suite and report test coverage:
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0.dev
0.7dev0
17 changes: 17 additions & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# tests
black
black[jupyter]
flake8
flake8-docstrings
isort
mypy == 0.921
pytest
pytest-cov

# CI
pre-commit

# tutorials
notebook
python-igraph
scikit-optimize
2 changes: 1 addition & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ your installation will change accordingly.
If you want to install the development requirements, stay inside the same ``Pulser``
directory and follow up by running: ::

pip install -r requirements.txt
pip install -r dev_requirements.txt
2 changes: 2 additions & 0 deletions packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pulser-core
pulser-simulation
6 changes: 6 additions & 0 deletions pulser-core/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jsonschema == 4.4.0
matplotlib
numpy >= 1.20
scipy
backports.cached-property; python_version == '3.7'
typing-extensions; python_version == '3.7'
Loading