From b9bfe495ddfde3097c408cce4ecc1ab933ee2c2c Mon Sep 17 00:00:00 2001 From: mikesongming Date: Mon, 20 Jun 2022 11:48:41 +0000 Subject: [PATCH 1/3] Create PR for #13 From a1b438cef6aab4fbbd36bf562eda09fb1568a37f Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 21 Jun 2022 00:08:58 +0800 Subject: [PATCH 2/3] wheels after released [wheel build] --- .github/workflows/wheels.yml | 55 +++++++++++++++--------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index eb72981..52121d9 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -4,19 +4,21 @@ on: push: pull_request: issue_comment: - types: [created] + types: created + release: + types: released schedule: - cron: "30 1 * * 4" workflow_dispatch: jobs: - test_build: + build_package: uses: ./.github/workflows/build.yml if: >- contains(github.event.head_commit.message, '[wheel build]') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || - (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || + github.event_name == 'release' || (github.event_name == 'pull_request' && contains(github.event.action, 'opened')) || (github.event.issue.pull_request && github.event.comment.body == '/build') with: @@ -27,31 +29,8 @@ jobs: need_wheel: true need_sdist: true - debug_build: - runs-on: ubuntu-latest - needs: test_build - steps: - - run: | - echo ${{ needs.test_build.outputs.pkg_name }} - echo ${{ needs.test_build.outputs.pkg_version }} - - - name: Download sdist - uses: actions/download-artifact@v3 - with: - name: sdist - path: dist - - - name: Download all wheels - uses: actions/download-artifact@v3 - with: - name: wheels - path: wheelhouse - - - run: | - ls -R - - test_test: - needs: test_build + run_tests: + needs: build_package uses: ./.github/workflows/test.yml with: ref: >- @@ -62,17 +41,17 @@ jobs: python_version: "3.10" secrets: inherit - test_comment: - needs: test_test + update_PR_Comment: + needs: run_tests if: ${{ github.event.pull_request || github.event.issue.pull_request }} uses: ./.github/workflows/comment.yml - test_publish: + pypa_publish: name: ✨ publish to PYPY - needs: [test_build, test_test] + needs: [build_package, run_tests] runs-on: ubuntu-latest if: >- - needs.test_test.outputs.test_passed + needs.run_tests.outputs.test_passed steps: - name: Download sdist uses: actions/download-artifact@v3 @@ -87,6 +66,7 @@ jobs: path: dist - name: Publish package to TestPyPI + if: github.event_name != 'release' uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ @@ -94,3 +74,12 @@ jobs: repository_url: https://test.pypi.org/legacy/ skip_existing: true print_hash: true + + - name: Publish package to PyPI + if: github.event_name == 'release' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + print_hash: true From 600083b25970651b33b1c5777f0d74cd089e57eb Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 21 Jun 2022 01:50:49 +0800 Subject: [PATCH 3/3] rename pkgs when not released [wheel build] --- .github/scripts/rename_test_packages.py | 43 +++++++++++++ .github/workflows/build.yml | 13 ++++ .github/workflows/publish_pypi.yml | 82 +++++++++++++++++++++++++ .github/workflows/wheels.yml | 45 +++----------- 4 files changed, 148 insertions(+), 35 deletions(-) create mode 100644 .github/scripts/rename_test_packages.py create mode 100644 .github/workflows/publish_pypi.yml diff --git a/.github/scripts/rename_test_packages.py b/.github/scripts/rename_test_packages.py new file mode 100644 index 0000000..f93a452 --- /dev/null +++ b/.github/scripts/rename_test_packages.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +""" +REV='0.7.1.post2+ga1b438c' +N_REV='0.7.2' + +for pkg in `ls dist/* | grep ${REV}`; +do + n_pkg=`echo $pkg | awk -F "${REV}" "{print $1,${N_REV},$2}"` + echo $pkg '->' $n_pkg +done +""" +import os +from pathlib import Path + +rev = os.environ.get("REV") +next_rev = os.environ.get("N_REV") +assert rev is not None, "env.REV is not set!" +assert next_rev is not None, "env.N_REV is not set!" + +_script = Path(__file__) + + +def rename_pkg(pkg): + n_name = pkg.name.replace(rev, next_rev) + n_pkg = pkg.parent.joinpath(n_name) + print(n_pkg) + pkg.rename(n_pkg) + + +def main(): + project_root = _script.parent.parent.parent + dist = project_root.joinpath("dist") + + for pkg in dist.glob("*.tar.gz"): + rename_pkg(pkg) + + for pkg in dist.glob("*.whl"): + rename_pkg(pkg) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9fde323..2987141 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,12 @@ on: required: false type: boolean outputs: + rev: + description: version of head ref + value: ${{ jobs.build_sdist.outputs.rev }} + next_rev: + description: next version of head ref + value: ${{ jobs.build_sdist.outputs.next_rev }} pkg_name: description: name of sdist value: ${{ jobs.build_sdist.outputs.pkg_name }} @@ -117,6 +123,8 @@ jobs: if: ${{ inputs.need_sdist }} runs-on: ubuntu-latest outputs: + rev: ${{ steps.save.outputs.rev }} + next_rev: ${{ steps.save.outputs.next_rev }} pkg_name: ${{ steps.save.outputs.pkg_name }} pkg_version: ${{ steps.save.outputs.pkg_version }} steps: @@ -133,6 +141,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + python -m pip install versioningit python -m pip install build - name: Build sdist Package with Extension @@ -142,6 +151,8 @@ jobs: - name: Extract sdist package info run: | bash .github/scripts/extract_sdist_info.sh + echo "rev=$(python -m versioningit)" >> $GITHUB_ENV + echo "next_rev=$(python -m versioningit -n)" >> $GITHUB_ENV - name: Upload sdist as Artifact if: ${{ success() }} @@ -154,5 +165,7 @@ jobs: - name: Write outputs id: save run: | + echo "::set-output name=rev::${{ env.rev }}" + echo "::set-output name=next_rev::${{ env.next_rev }}" echo "::set-output name=pkg_name::${{ env.pkg_name }}" echo "::set-output name=pkg_version::${{ env.pkg_version }}" diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml new file mode 100644 index 0000000..08da30d --- /dev/null +++ b/.github/workflows/publish_pypi.yml @@ -0,0 +1,82 @@ +name: Publish to PYPI + +on: + workflow_call: + inputs: + ref: + required: true + type: string + is_release: + required: true + type: boolean + rev: + description: version of head ref + default: '' + required: false + type: string + next_rev: + description: next version of head ref + default: '' + required: false + type: string + sdist_artifact: + default: 'sdist' + required: false + type: string + wheels_artifact: + default: 'wheels' + required: false + type: string + +defaults: + run: + shell: bash + +jobs: + pypa_publish: + name: ✨ publish to PYPY + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + fetch-depth: 0 + + - name: Download sdist + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.sdist_artifact }} + path: dist + + - name: Download all wheels + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.wheels_artifact }} + path: dist + + - name: Rename packages + if: ${{ ! inputs.is_release }} + env: + REV: ${{ inputs.rev }} + N_REV: ${{ inputs.next_rev }} + run: | + python .github/scripts/rename_test_packages.py + + - name: Publish package to TestPyPI + if: ${{ ! inputs.is_release }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + skip_existing: true + print_hash: true + + - name: Publish package to PyPI + if: ${{ inputs.is_release }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true + print_hash: true diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 52121d9..959f970 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -47,39 +47,14 @@ jobs: uses: ./.github/workflows/comment.yml pypa_publish: - name: ✨ publish to PYPY needs: [build_package, run_tests] - runs-on: ubuntu-latest - if: >- - needs.run_tests.outputs.test_passed - steps: - - name: Download sdist - uses: actions/download-artifact@v3 - with: - name: sdist - path: dist - - - name: Download all wheels - uses: actions/download-artifact@v3 - with: - name: wheels - path: dist - - - name: Publish package to TestPyPI - if: github.event_name != 'release' - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - skip_existing: true - print_hash: true - - - name: Publish package to PyPI - if: github.event_name == 'release' - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - skip_existing: true - print_hash: true + uses: ./.github/workflows/publish_pypi.yml + if: needs.run_tests.outputs.test_passed + with: + ref: >- + ${{ github.event.pull_request && + github.event.pull_request.head.ref || github.ref_name + }} + is_release: ${{ github.event_name == 'release' }} + rev: ${{ needs.build_package.outputs.rev }} + next_rev: ${{ needs.build_package.outputs.next_rev }}