Skip to content

Commit

Permalink
Automatic packaging and CI test updates (#386)
Browse files Browse the repository at this point in the history
* Reorganizing the requirements locations

* WIP: Trying out composite Github actions

* Incorporating composite Github action in CI suite

* Make CI run on all PRs

* Bug: Requirements files were switched

* Moving jsonschema to requirements

* Installing only the necessary requirements in CI

* Adding pytest to type-checking required packages

* Complementing the CI test description

* WIP: Test version check

* WIP: Check new version validity

* WIP: Test version validity [fail 1]

* WIP: Test version check [fail 2]

* Bring version back

* Trigger new workflow run

* WIP: Test stable version validity [fail 3]

* WIP: Test stable version validity [pass]

* Finish version checker tests

* Adding full test workflow

* Make full tests run on push only

* Centralizing the different packages

* Add packaging script

* WIP: Test publish workflow

* Test: Trigger 'publish' workflow

* WIP: 2nd 'publish' workflow test

* WIP: 3rd 'publish' workflow test

* Finish the 'publish' workflow

* Documenting the Release procedure

* Review comments + Details on merge commit messages

* Adding review suggestions
  • Loading branch information
HGSilveri authored Aug 9, 2022
1 parent d60fc2c commit 4ecad78
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 105 deletions.
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
70 changes: 23 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,59 @@ 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 install
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 install
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 install
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 install
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'''
- name: Type check with mypy
run: mypy
test:
runs-on: ${{ matrix.os }}
if: github.event_name != 'push'
runs-on: ubuntu-latest
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 install
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
- 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']
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
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
- 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

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

0 comments on commit 4ecad78

Please sign in to comment.