Skip to content

Commit

Permalink
Automated CI/CD (#74)
Browse files Browse the repository at this point in the history
* Regression testing is expanded (#54)

* Added a github action to build and install

* Test on more python versions

* Test the devel branch

* Added a missing requirement to fix tests

* Test on Windows and MacOS too

* Auto-detect python version and require at least Python 3.9 (#55)

* Fix conda runtime on Windows (operating from within conda as well) (#56)

* Added basic locking (#58)

* Fixed README after the modules are split in two (#57)

* Auto-deply to pypi (#61)

* Create SECURITY.md
  • Loading branch information
openvmp authored Jan 14, 2024
1 parent 7f7b5f3 commit 8f6d69e
Show file tree
Hide file tree
Showing 28 changed files with 431 additions and 126 deletions.
9 changes: 7 additions & 2 deletions .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.3.2"
current_version = "0.3.56"
commit = "true"
commit_args = "--no-verify"
tag = "true"
Expand Down Expand Up @@ -29,4 +29,9 @@ replace = "__version__: str = \"{new_version}\""
[[tool.bumpversion.files]]
filename = "partcad-cli/src/partcad_cli/__init__.py"
search = "__version__: str = \"{current_version}\""
replace = "__version__: str = \"{new_version}\""
replace = "__version__: str = \"{new_version}\""

[[tool.bumpversion.files]]
filename = "version.sh"
search = "=\"{current_version}\""
replace = "=\"{new_version}\""
41 changes: 0 additions & 41 deletions .github/workflows/python-app.yml

This file was deleted.

59 changes: 59 additions & 0 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CD on Linux, MacOS and Windows

on:
push:
branches: ["main", "devel"]
pull_request:
branches: ["main", "devel"]

permissions:
contents: write

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}
if: "!startsWith(github.event.head_commit.message, 'Version updated')"
env:
BIN_DIR: ${{ matrix.os == 'windows-latest' && 'Scripts' || 'bin' }}

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Prepare environments
run: |
python -m pip install --upgrade pip build
mkdir .venv
python -m venv .venv/build
(. .venv/build/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
python -m venv .venv/build-cli
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
python -m venv .venv/install
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
- name: Test building and packaging
run: |
(. .venv/build/${{ env.BIN_DIR }}/activate && cd partcad && python -m build && cd .. && deactivate)
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
cp README.md partcad-cli
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && cd partcad-cli && python -m build && cd .. && deactivate)
- name: Test installation
run: |
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad-cli/requirements.txt && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad-cli/dist partcad-cli && deactivate)
137 changes: 137 additions & 0 deletions .github/workflows/python-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Deployment to PyPI

on:
push:
tags:
- "**"

permissions:
contents: write

jobs:
# Keep the "build" job identical to "python-build.yml".
# TODO(clairbee): include "python-build.yml" instead
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
runs-on: ${{ matrix.os }}
env:
BIN_DIR: ${{ matrix.os == 'windows-latest' && 'Scripts' || 'bin' }}

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Prepare environments
run: |
python -m pip install --upgrade pip build
mkdir .venv
python -m venv .venv/build
(. .venv/build/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
python -m venv .venv/build-cli
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
python -m venv .venv/install
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
- name: Test building and packaging
run: |
(. .venv/build/${{ env.BIN_DIR }}/activate && cd partcad && python -m build && cd .. && deactivate)
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
cp README.md partcad-cli
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && cd partcad-cli && python -m build && cd .. && deactivate)
- name: Test installation
run: |
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad-cli/requirements.txt && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad-cli/dist partcad-cli && deactivate)
# Upload artifact from the selected OS/Python version combination only
- name: Upload "partcad"
if:
"startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest'
&& matrix.python-version == '3.11'"
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: partcad/dist/
- name: Upload "partcad-cli"
if:
"startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest'
&& matrix.python-version == '3.11'"
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: partcad-cli/dist/

publish-to-pypi:
name: Publish to PyPI
if: "startsWith(github.ref, 'refs/tags/')"
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi

steps:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist

- name: Clone the repo
run: |
git clone https://github.com/openvmp/partcad
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
cd partcad;
if ( git branch -a --contains ${{ github.ref_name }} | grep -q -e "^ remotes/origin/devel" -e "^ remotes/origin/main" ); then
gh release create '${{ github.ref_name }}' --repo '${{ github.repository }}' --notes "";
fi
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
cd partcad;
if ( git branch -a --contains ${{ github.ref_name }} | grep -q -e "^ remotes/origin/devel" -e "^ remotes/origin/main" ); then
cd ..;
gh release upload '${{ github.ref_name }}' dist/** --repo '${{ github.repository }}';
cd partcad;
fi
if ( git branch -a --contains ${{ github.ref_name }} | grep -q "^ remotes/origin/main" ); then
echo "DEPLOY_TO_TEST=FALSE" >> $GITHUB_ENV;
else
echo "DEPLOY_TO_TEST=TRUE" >> $GITHUB_ENV;
fi
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url:
"${{ env.DEPLOY_TO_TEST=='FALSE' && 'https://pypi.org/legacy/' ||
'https://test.pypi.org/legacy/' }}"
user: __token__
password:
"${{ env.DEPLOY_TO_TEST=='FALSE' && secrets.PYPI_KEY ||
secrets.TEST_PYPI_KEY }}"
53 changes: 53 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI on Linux, MacOS and Windows

on:
push:
branches: ["main", "devel"]
pull_request:
branches: ["main", "devel"]

permissions:
contents: read

jobs:
test:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.9", "3.10", "3.11"]
exclude:
- os: "windows-latest"
python-version: "3.11"
runs-on: ${{ matrix.os }}
if: "!startsWith(github.event.head_commit.message, 'Version updated')"

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: latest
activate-environment: pc-conda-env
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U pytest
pip install -r partcad/requirements.txt
# pip install -r partcad-cli/requirements.txt
- name: Test with pytest
env:
PYTHONPATH: partcad/src
PYTHONWARNINGS: ignore
run: |
pytest -x -p no:error-for-skips
20 changes: 13 additions & 7 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
name: Updates version and tags
on:
push:
branches:
- main
branches: ["main", "devel"]
permissions:
contents: write
jobs:
update_version_and_tag:
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, '[SKIP]')"

if:
"!startsWith(github.event.head_commit.message, '[SKIP]') &&
!startsWith(github.event.head_commit.message, 'Version updated')"
environment:
name: CD

steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
- name: Install Python 3
uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -57,8 +62,9 @@ jobs:
bump-my-version bump patch
if: env.SKIPBUMP == 'FALSE'

- name: Commit version change to master
- name: Commit version change to repo
run: |
git push --force --follow-tags
# TODO(clairbee): publish the package as seen in https://github.com/joaomcteixeira/python-project-skeleton/blob/main/.github/workflows/version-bump-and-package.yml
# git push --force origin $(git rev-parse --abbrev-ref HEAD)
# . ./version.sh
# git push origin $PARTCAD_VERSION
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.conda
.venv
*.egg-info
__pycache__
.pytest_cache
Expand Down
13 changes: 6 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@
"**/LICENSE.txt": true,
".ocp_vscode": true,
".conda": true,
".venv": true,
".tox": true,
"**/.partcad": true,
"partcad*/build": true,
"partcad*/dist": true
},
"markdown.extension.toc.omittedFromToc": {
"README.md": [
"# PartCAD"
]
"# PartCAD"
]
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.testing.pytestArgs": [
],
"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.terminal.executeInFileDir": true,
"python.terminal.launchArgs": [
],
"python.terminal.launchArgs": [],
"OcpCadViewer.advanced.autostart": false,
"yaml.format.bracketSpacing": false // prevent YAML formatter from breaking Jinja2 templates
}
}
Loading

0 comments on commit 8f6d69e

Please sign in to comment.