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

setup build and deploy action #18

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
8 changes: 8 additions & 0 deletions .github/actions/build-dist/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set -euo pipefail

echo "Ensuring pip is up to date"
python -m pip install --upgrade pip
echo "Installing the latest version of pypa/build"
pip install build
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why the pip upgrade is triggered with python -m and this uses pip straight. Why is that? ❓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

initially implemented by @plannigan so I am unsure!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was actually implemented by @jamescurtin, but it should be the same either way. I don't have an opinion on which should be used going forward.

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct: both are the same, I was just inconsistent in usage. (Reference).

python -m pip has the benefit of being explicit about which version of the python binary is used on a system that uses multiple (i.e. python vs. python3), but for our purposes either is fine.


python -m build --sdist --wheel --outdir dist/ .
8 changes: 8 additions & 0 deletions .github/actions/build-dist/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: "Build Python package"
description: "Build a wheel and sdist for the package"
runs:
using: "composite"
steps:
- name: "Build wheel"
run: "$GITHUB_ACTION_PATH/action.sh"
shell: "bash"
9 changes: 2 additions & 7 deletions .github/actions/verify-wheel/action.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
set -euo pipefail

MODULE_NAME=$1
WHEEL_LOCATION=$2

echo "Ensuring pip is up to date"
python -m pip install --upgrade pip
echo "Installing the latest setuptools & wheel"
pip install --upgrade setuptools wheel

echo "--------------"
echo "Building wheel"
python setup.py bdist_wheel

APP_DIR=$(pwd)

# move into root dir so Python will import the installed package instead of the local source files
cd /
echo "------------------"
echo "Installing package"
pip install ${APP_DIR}/dist/*.whl
pip install ${APP_DIR}/${WHEEL_LOCATION}/*.whl

echo "-----------------------------"
echo "Attempting to import package"
Expand Down
8 changes: 6 additions & 2 deletions .github/actions/verify-wheel/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name: "Verify Python Wheel"
description: "Build a wheel for the package and importing the package doesn't cause an error"
description: "Verify importing the package doesn't cause an error"
inputs:
package-import-name:
description: "Name used to import the package from python code"
required: true
packages-dir:
description: The target directory for distribution
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider wrapping the value in ""~ (and other strings in this file- helps keep things consistent and provides some measure of safety. 😁 )

required: false
default: dist
runs:
using: "composite"
steps:
- name: "Verify wheel"
run: "$GITHUB_ACTION_PATH/action.sh ${{ inputs.package-import-name }}"
run: "$GITHUB_ACTION_PATH/action.sh ${{ inputs.package-import-name }} ${{ inputs.packages-dir }}"
shell: "bash"
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheel
uses: ./.github/actions/build-dist
- name: Verify wheel
uses: ./.github/actions/verify-wheel
with:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish Release
Copy link
Collaborator

Choose a reason for hiding this comment

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

Likewise, consider wrapping all strings in this file in "". 🎞️

env:
PYTHON_VERSION: "3.9"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean the env that this workflow runs in going to be using Python 3.9? I'm curious if we should be running it in Python 3.8 since we don't add a 3.9 Classifier listing in setup.cfg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I should bump this down cause its just weird, but as we're publishing a pure-python wheel it shouldn't be an issue which version of python builds it

on:
release:
types: [published]
jobs:
build-and-publish-wheel-to-pypi:
runs-on: ubuntu-latest
environment: "Publish Release"
steps:
- name: Check out code
uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Build wheel
uses: ./.github/actions/build-dist

# v1.4.2 release. Using full SHA for security
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
password: ${{ secrets.PYPI_API_TOKEN }}
5 changes: 3 additions & 2 deletions little_cheesemonger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__version__ = "0.1.0"

from little_cheesemonger._errors import LittleCheesemongerError # noqa
from little_cheesemonger._run import run # noqa

__version__ = "0.1.0rc0"
12 changes: 6 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ long_description = file: README.md
long_description_content_type = text/markdown
license = See LICENSE
classifiers =
"Development Status :: 4 - Beta"
"Programming Language :: Python"
"Programming Language :: Python :: 3"
"Programming Language :: Python :: 3.6"
"Programming Language :: Python :: 3.7"
"Programming Language :: Python :: 3.8"
Development Status :: 4 - Beta
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also add a Programming Language :: Python :: 3.9 classifier (if we intend to publish for 3.9) and a License :: OSI Approved :: MIT License classifier like in Columbo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeppers


[options]

Expand Down