Skip to content

Commit

Permalink
Merge pull request #125 from ekiefl/streamline-publishing
Browse files Browse the repository at this point in the history
Streamline publishing
  • Loading branch information
ekiefl authored Jul 28, 2024
2 parents c696a12 + 7cedbad commit a45a8da
Show file tree
Hide file tree
Showing 13 changed files with 1,316 additions and 700 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
name: lint-and-test
name: format

on:
pull_request:
branches: [main]

jobs:
lint-and-test:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Cache Poetry install
uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
path: ~/.local
key: poetry-1.8.3-0

- name: Install Poetry
uses: snok/install-poetry@v1
python-version: "3.12"
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true

- name: Cache Poetry dependencies
id: cache-poetry-deps
uses: actions/cache@v2
poetry-version: "1.8.3"
- name: Setup a local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}

- run: poetry install --no-interaction --no-root
if: steps.cache-poetry-deps.outputs.cache-hit != 'true'
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install project dependencies
run: poetry install

# --- Ruff

Expand All @@ -56,16 +46,6 @@ jobs:
poetry run ruff format . --check --verbose --diff
echo "ruff_format_failed=$?" >> $GITHUB_ENV
# --- Pytest

- name: pytest
id: pytest
continue-on-error: true
run: |
poetry run pytest --version
poetry run pytest
echo "pytest_failed=$?" >> $GITHUB_ENV
# --- Pyright

- name: pyright
Expand All @@ -78,25 +58,13 @@ jobs:
# --- Main

- name: Test results
- name: Results
if: always()
run: |
# Print out test results
passed=()
failed=()
if [[ "${{ env.pytest_failed }}" != "0" ]]; then
failed+=("pytest")
else
passed+=("pytest")
fi
if [[ "${{ env.pyright_failed }}" != "0" ]]; then
failed+=("pyright")
else
passed+=("pyright")
fi
if [[ "${{ env.ruff_lint_failed }}" != "0" ]]; then
failed+=("ruff_lint")
else
Expand All @@ -109,6 +77,12 @@ jobs:
passed+=("ruff_format")
fi
if [[ "${{ env.pyright_failed }}" != "0" ]]; then
failed+=("pyright")
else
passed+=("pyright")
fi
if [ ${#passed[@]} -ne 0 ]; then
echo "✅ PASSED:"
for check in "${passed[@]}"; do
Expand All @@ -124,7 +98,7 @@ jobs:
echo " - $check"
done
else
echo "🚀🚀 ALL TESTS PASSED 🚀🚀"
echo "🚀🚀 ALL FORMATTING & TYPE-CHECKING PASSED 🚀🚀"
fi
echo ""
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: test

on:
pull_request:
branches: [main]

jobs:
test:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.12"]
poetry-version: ["1.8.3"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Setup a local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install project dependencies
run: poetry install
- name: Run tests
run: poetry run pytest
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include .env

# Note: `poetry` does not appear to read the `POETRY_PYPI_TOKEN_<NAME>` environment variable,
# so we need to pass it explicitly in the `publish` command.
.PHONY: test-publish
test-publish:
echo ${POETRY_PYPI_TOKEN_PYPI_TEST}
poetry publish \
--repository pypi-test \
--username __token__ \
--password ${POETRY_PYPI_TOKEN_PYPI_TEST}

.PHONY: publish
publish: build
poetry publish \
--username __token__ \
--password ${POETRY_PYPI_TOKEN_PYPI}
88 changes: 0 additions & 88 deletions PYPI.md

This file was deleted.

101 changes: 101 additions & 0 deletions docs/publish_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Publishing a new pooltool release

These are instructions for how to make new pip-installable pooltool versions on PyPi.

## 1. House keeping

- Update `logo.png` if its not a sub-version (rename logo_small.png to previous version (e.g. logo_v0p1.png) open Blender file, update textures, render at top, save as logo.png). Then make a copy of logo.png that is 640 x 360 called logo_small.png.

## 2. Create a git tag

Versioning is handled dynamically based on git tags. So to make a new release, you first make a new git tag. Make sure you're on the main branch with no uncommitted changes.

```bash
RELEASE_VERSION=0.1.0
git tag -a v${RELEASE_VERSION} -m "Release version ${RELEASE_VERSION}"
git push origin v${RELEASE_VERSION}
```

If you need to delete a tag you've created (or even pushed), use:

```bash
git tag -d <tagname> # Locally delete
git push origin :refs/tags/<tagname> # If you pushed it
```

## 3. Build the distribution

```bash
poetry build
```

You should see something like this:

```bash
Building pooltool-billiards (0.1.0)
- Building sdist
- Built pooltool_billiards-0.1.0.tar.gz
- Building wheel
- Built pooltool_billiards-0.1.0-py3-none-any.whl
```

If there are additional metadata attached to the version (_e.g._ `0.3.4a2.dev1+eb17e9c.dirty`), then your tag isn't up to date.

Open the tar found in `dist/`. If you've added any non-Python files to the package since the last release, make sure they are either present or absent from the package (depending on the desired outcome).

Also open `pooltool/__init__.py` and make sure the `__version__` variable was populated with something other than the placeholder, `0.0.0`.

## 4. Publish to the **test** PyPI repository

- Populate your `.env` using `.env.copy` as a template.

- Run `make test-publish`. If this fails due to timing out (slow upload speed that gets cut short), skip ahead to trying out the installation locally.

- Create a fresh python environment to test the installation

```
source ~/.bashrc
conda deactivate
conda env remove --name asdf
conda create -y -n asdf python=3.8.10
PYTHONPATH=""
conda activate asdf
```

- Install:

```bash
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --extra-index-url https://archive.panda3d.org/ pooltool-billiards==${RELEASE_VERSION} --force-reinstall
```

If test PyPi is timing out, you can instead consider testing the installation with

```bash
pip install dist/pooltool_billiards-${RELEASE_VERSION}.tar.gz --force-reinstall --extra-index-url https://archive.panda3d.org/
```

- Test it out. Make sure `which run-pooltool` leads to the asdf environment: `/Users/evan/anaconda3/envs/asdf/bin/run_pooltool`. Then see if the interactive interface can be loaded: `run-pooltool`. Additionally, check the path of `cd ~; python -c "import pooltool; print(pooltool.__file__)"; cd -`. It should be in site-packages of asdf environment.

## 5. Publish to the **real** PyPI repository

- Go back to the dev environment.

- Run `make publish`

- Create a new python environment

```
source ~/.bashrc
conda deactivate
conda env remove --name asdf
conda create -y -n asdf python=3.8.10
PYTHONPATH=""
conda activate asdf
cd ~
```

- Test installation: `pip install pooltool-billiards==${RELEASE_VERSION}` (you may need to wait for version to be live)

## 6. Make a release

- Make a release on github from the tag. Upload the `.whl` and `.tar.gz` found in `dist/`.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- defaults
- conda-forge
dependencies:
- python==3.8.10
- python==3.12.4
- pip
- pip:
- poetry>=1.8.3
Loading

0 comments on commit a45a8da

Please sign in to comment.