From 48cd2c44c1992710817d32b4cc064f078755e2b7 Mon Sep 17 00:00:00 2001 From: bottler Date: Wed, 27 Nov 2024 06:03:38 -0800 Subject: [PATCH] github actions ghstack-source-id: a60ee82712fdb171ebca3a27f4c29aa71cf37eee Pull Request resolved: https://github.com/facebookresearch/nevergrad/pull/1654 --- .github/actions/ubuntu_restore_all/action.yml | 24 ++++ .github/check-yaml.py | 7 + .github/workflows/every_commit.yml | 125 ++++++++++++++++++ .github/workflows/main.yml | 19 +++ .github/workflows/version.yml | 44 ++++++ 5 files changed, 219 insertions(+) create mode 100644 .github/actions/ubuntu_restore_all/action.yml create mode 100644 .github/check-yaml.py create mode 100644 .github/workflows/every_commit.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/version.yml diff --git a/.github/actions/ubuntu_restore_all/action.yml b/.github/actions/ubuntu_restore_all/action.yml new file mode 100644 index 000000000..011b8e815 --- /dev/null +++ b/.github/actions/ubuntu_restore_all/action.yml @@ -0,0 +1,24 @@ +name: ubuntu_restore_all +runs: + using: composite + steps: + - uses: actions/checkout@v4.1.0 + - name: restore_cache + uses: actions/cache@v3.3.2 + with: + key: v4-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/main.txt"}}-{{ checksum "requirements/bench.txt"}} + path: ./venv + restore-keys: | + v4-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/main.txt"}}-{{ checksum "requirements/bench.txt"}} + v4-dependencies-main-{{ checksum "requirements/main.txt"}} + - name: "[all] Install dependencies" + run: | + #python3 -m venv venv + rm -rf venv && python3 -m venv venv + . venv/bin/activate + pip install --progress-bar off -U pip setuptools + pip install --progress-bar off -e .[all] + #pip install --progress-bar off --use-deprecated=legacy-resolver -e .[all] + pip install --progress-bar off -U numpy==1.24.0 matplotlib==2.2.3 pyomo==5.7.1 + pip install keras==2.6.0 # issue on Nov 4th 2021 + shell: bash diff --git a/.github/check-yaml.py b/.github/check-yaml.py new file mode 100644 index 000000000..df70a2428 --- /dev/null +++ b/.github/check-yaml.py @@ -0,0 +1,7 @@ +import pathlib +import yaml + +for path in pathlib.Path(".").glob("**/*.yml"): + print(path) + with open(path) as f: + yaml.load(f, Loader=yaml.FullLoader) diff --git a/.github/workflows/every_commit.yml b/.github/workflows/every_commit.yml new file mode 100644 index 000000000..412aaf05c --- /dev/null +++ b/.github/workflows/every_commit.yml @@ -0,0 +1,125 @@ +name: facebookresearch/nevergrad/every_commit +on: + push: + branches: + - main + pull-request: +jobs: + install: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - name: restore_cache + uses: actions/cache@v3.3.2 + with: + key: v4-dependencies-main-{{ checksum "requirements/main.txt"}} + path: "./venv" + restore-keys: v4-dependencies-main-{{ checksum "requirements/main.txt"}} + - name: "[no-extra] Install dependencies" + run: | + rm -rf venv && python3 -m venv venv + . venv/bin/activate + pip install --progress-bar off pip==23.2 + pip install --progress-bar off -e . + - name: "[no-extra] Print installation" + run: | + . venv/bin/activate + pip freeze + - name: "[no-extra] Run basic tests (checking dependencies)" + run: | + . venv/bin/activate + python -m nevergrad.optimization.requirements_check # calls a bit of everything + - uses: "./.github/actions/ubuntu_restore_all" + - name: save_cache + uses: actions/cache@v3.3.2 + with: + path: "./venv" + key: v4-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/main.txt"}}-{{ checksum "requirements/bench.txt"}} + - name: "[all] Print installation" + run: | + . venv/bin/activate + pip freeze + - name: Run wheel and check package + run: | + . venv/bin/activate + pip install wheel + rm -rf dist # make sure it's clean + echo "Creating sdist" + python setup.py sdist + echo "Created sdist, now creating wheel" + python setup.py bdist_wheel + echo "Created wheel" + mkdir nevergrad-build + mv dist nevergrad-build/ + python -c "from pathlib import Path;files = Path('nevergrad.egg-info/SOURCES.txt').read_text().split(); assert 'LICENSE' in files" + python3 -m venv test_wheel + . test_wheel/bin/activate + pip install -U pip + cd .. # don't use nevergrad locally + echo "Installing wheel" + pip install --progress-bar off repo/nevergrad-build/dist/nevergrad-*any.whl + #pip install --progress-bar off --use-deprecated=legacy-resolver repo/nevergrad-build/dist/nevergrad-*any.whl + echo "Installed wheel" + python -c "from nevergrad import functions;f = functions.ArtificialFunction(name='sphere', block_dimension=2);f([2, 3])" + - name: Build docs + run: | + . venv/bin/activate + cd docs/ + make html + - name: Upload static files as artifact + id: deployment + uses: actions/upload-pages-artifact@v3 + with: + path: docs/_build/html/ + if: github.event_name != 'pull_request' + deploy-docs: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: install + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + static: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: Run mypy + run: | + . venv/bin/activate + mypy --version + mypy nevergrad + - name: Run basic pylint + run: | + . venv/bin/activate + pylint --version + pylint nevergrad --disable=all --enable=unused-import,unused-argument,unused-variable,undefined-loop-variable,redefined-builtin,used-before-assignment,super-init-not-called,useless-super-delegation,dangerous-default-value,unnecessary-pass,attribute-defined-outside-init + - name: Run black + run: | + . venv/bin/activate + pip install black + black --version + black nevergrad --check --diff + pytests: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: "[all] Run pytest" + run: | + . venv/bin/activate + pip install pytest + pytest --circleci-parallelize nevergrad -v --durations=20 --cov=nevergrad + #pytest nevergrad -v --exitfirst --durations=20 --cov=nevergrad diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..1a35199bc --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,19 @@ +name: facebookresearch/nevergrad/main +on: + push: + branches: + - main +jobs: + docs-links: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: Check links + run: | + . venv/bin/activate + cd docs/ + make linkcheck diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 000000000..0340020db --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,44 @@ +name: facebookresearch/nevergrad/release +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+.post[0-9]+' +env: + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + CIRCLE_TAG: ${{ github.ref_name }} +jobs: + pypi-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: Run wheel and check package + run: | + . venv/bin/activate + pip install wheel + rm -rf dist # make sure it's clean + echo "Creating sdist" + python setup.py sdist + echo "Created sdist, now creating wheel" + python setup.py bdist_wheel + echo "Created wheel" + mkdir nevergrad-build + mv dist nevergrad-build/ + - name: Create .pypirc + run: | + echo -e "[pypi]" >> ~/.pypirc + echo -e "username = __token__" >> ~/.pypirc + echo -e "password = $PYPI_PASSWORD" >> ~/.pypirc + - name: Verify tag + run: python setup.py verify_circleci_version + - name: upload to pypi + run: | + echo "Deploying" + . venv/bin/activate + du -h nevergrad-build/dist/* + twine check nevergrad-build/dist/nevergrad-* + twine upload nevergrad-build/dist/nevergrad-* --verbose