python-package.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
  2. # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
  3. name: Python package
  4. on:
  5. push:
  6. tags:
  7. - '*released'
  8. workflow_dispatch:
  9. jobs:
  10. update-version:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout repository
  14. uses: actions/checkout@v4
  15. - name: Set up Python
  16. uses: actions/setup-python@v5
  17. with:
  18. python-version: "3.10"
  19. - name: Update version.py
  20. run: |
  21. python update_version.py
  22. - name: Verify version.py
  23. run: |
  24. ls -l magic_pdf/libs/version.py
  25. cat magic_pdf/libs/version.py
  26. - name: Commit changes
  27. run: |
  28. git config --local user.email "moe@myhloli.com"
  29. git config --local user.name "myhloli"
  30. git add magic_pdf/libs/version.py
  31. if git diff-index --quiet HEAD; then
  32. echo "No changes to commit"
  33. else
  34. git commit -m "Update version.py with new version"
  35. fi
  36. - name: Push changes
  37. if: always() # 确保始终运行此步骤
  38. env:
  39. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  40. run: |
  41. git push origin main
  42. build:
  43. runs-on: ubuntu-latest
  44. strategy:
  45. fail-fast: false
  46. matrix:
  47. python-version: ["3.10"]
  48. steps:
  49. - name: Checkout code
  50. uses: actions/checkout@v4
  51. with:
  52. fetch-depth: 0
  53. - name: Set up Python ${{ matrix.python-version }}
  54. uses: actions/setup-python@v5
  55. with:
  56. python-version: ${{ matrix.python-version }}
  57. - name: Install dependencies
  58. run: |
  59. python -m pip install --upgrade pip
  60. if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  61. - name: Install wheel
  62. run: |
  63. python -m pip install wheel
  64. - name: Build wheel
  65. run: |
  66. python setup.py bdist_wheel
  67. - name: Upload artifact
  68. uses: actions/upload-artifact@v4
  69. with:
  70. name: wheel-file
  71. path: dist/*.whl
  72. retention-days: 30
  73. release:
  74. needs: [ build ]
  75. runs-on: ubuntu-latest
  76. steps:
  77. - name: Checkout code
  78. uses: actions/checkout@v4
  79. - name: Download artifact
  80. uses: actions/download-artifact@v4
  81. with:
  82. name: wheel-file
  83. path: dist
  84. - name: Create and Upload Release
  85. id: create_release
  86. uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981
  87. with:
  88. files: './dist/*.whl'
  89. env:
  90. GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
  91. # - name: Publish to PyPI
  92. # uses: pypa/gh-action-pypi-publish@release/v1
  93. # with:
  94. # user: __token__
  95. # password: ${{ secrets.PYPI_TOKEN }}