diff --git a/.github/test_files/setup.cfg b/.github/test_files/setup.cfg new file mode 100644 index 0000000..17e9f36 --- /dev/null +++ b/.github/test_files/setup.cfg @@ -0,0 +1,6 @@ +# THIS IS A TEST FILE + +[metadata] +name = test-project +version = attr: .__version__ +description = This is a test project diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7740eea..4d716a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,9 @@ jobs: test-stage-1: runs-on: ubuntu-latest timeout-minutes: 5 + strategy: + matrix: + pep517: [true, false] steps: - name: Checkout repo uses: actions/checkout@v2 @@ -64,11 +67,15 @@ jobs: assert_equal "$HEAD_REF" 'prepare-9.2.3' assert_equal "$( git branch --show-current )" 'prepare-9.2.3' - - name: Setup mock __init__.py, setup.py & changelog files + - name: Setup mock project files run: | cp .github/test_files/__init__.py ./__init__.py - cp .github/test_files/setup.py ./setup.py cp .github/test_files/CHANGES.md ./CHANGES.md + if ${{ matrix.pep517 }}; then + cp .github/test_files/setup.cfg ./setup.cfg + else + cp .github/test_files/setup.py ./setup.py + fi echo "[command]git add ."; git add . echo "[command]git commit" @@ -88,8 +95,15 @@ jobs: from __init__ import __version__ assert __version__ == '9.2.3', f'::error:: assert version {__version__} == 9.2.3' " - setup_py_version='${{ steps.set-package-version.outputs.setup-py-version }}' - assert_equal "$setup_py_version" '1!9.2.3' + package_version='${{ steps.set-package-version.outputs.package-version }}' + # In setup.py projects, the __init__.py __version__ may be different to the setup.py version + # but in PEP 517 projects, the setup.cfg version will be the same as __init__.py __version__ + if ${{ matrix.pep517 }}; then + expected_version="9.2.3" + else + expected_version="1!9.2.3" + fi + assert_equal "$package_version" "$expected_version" # Check changes to init file are staged exact_grep "M __init__.py" <(git status -s) diff --git a/build-python-package/action.yml b/build-python-package/action.yml index f0a726e..a0b9c09 100644 --- a/build-python-package/action.yml +++ b/build-python-package/action.yml @@ -8,10 +8,19 @@ inputs: runs: using: composite steps: - - name: Install dependencies - shell: bash - run: python3 -m pip install wheel - - name: Build shell: bash - run: python3 setup.py bdist_wheel sdist + run: | + if [[ -f setup.py ]]; then + # old style setup.py project + # (must manually install build dependencies) + echo "setup.py detected" + python3 -m pip install wheel + python3 setup.py bdist_wheel sdist + else + # PEP517 project + # (must install a builder, this installs build deps for us) + echo "PEP 517 project detected" + python3 -m pip install build + python3 -m build + fi diff --git a/stage-1/set-python-package-version/action.yml b/stage-1/set-python-package-version/action.yml index 8e644a8..f177efd 100644 --- a/stage-1/set-python-package-version/action.yml +++ b/stage-1/set-python-package-version/action.yml @@ -15,9 +15,9 @@ inputs: required: false default: true outputs: - setup-py-version: + package-version: description: Version number as outputted by setup.py (might be different from __init__.py, e.g. if epoch prefixed) - value: ${{ steps.get-setup-py-version.outputs.version }} + value: ${{ steps.get-package-version.outputs.version }} runs: using: composite steps: @@ -53,21 +53,31 @@ runs: git add "$INIT_FILE" fi - - name: Get setup.py version + - name: Get package version # Might differ slightly from __init__.py, e.g. if epoch prefixed - id: get-setup-py-version + id: get-package-version shell: bash run: | - setup_py_version=$( python setup.py --version ) + if [[ -f setup.py ]]; then + # get version from the setup.py for pre PEP517 projects + echo "setup.py detected" + package_version=$( python setup.py --version ) + else + # shim to get the project version from a PEP517 project + echo "PEP 517 project detected" + echo 'from setuptools import setup; setup()' > setup.py + package_version=$( python setup.py --version ) + rm setup.py + fi # Check version number is valid: - cmp_py_versions "$setup_py_version" "$setup_py_version" - echo "setup.py version: ${setup_py_version}" - echo "::set-output name=version::$setup_py_version" + cmp_py_versions "$package_version" "$package_version" + echo "package version: ${package_version}" + echo "::set-output name=version::$package_version" - name: Check version doesn't already exist on PyPI.org shell: bash working-directory: ${{ github.action_path }} env: PYPI_PACKAGE_NAME: ${{ inputs.pypi-package-name }} - SETUP_PY_VERSION: ${{ steps.get-setup-py-version.outputs.version }} + SETUP_PY_VERSION: ${{ steps.get-package-version.outputs.version }} run: node check-pypi.js diff --git a/stage-2/comment-on-pr/comment-on-pr.js b/stage-2/comment-on-pr/comment-on-pr.js index 7f8d176..3740cae 100644 --- a/stage-2/comment-on-pr/comment-on-pr.js +++ b/stage-2/comment-on-pr/comment-on-pr.js @@ -41,8 +41,12 @@ You can still publish the dist to PyPI manually: (Make sure you have commit \`${pr_event.merge_commit_sha}\` checked out) \`\`\`shell -# Create the build +# Create the build (old style for setup.py projects) python3 setup.py bdist_wheel sdist + +# Create the build (PEP517) +python -m build + # Upload your build to PyPI twine upload dist/* \`\`\`