python-package.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. with:
  16. ref: master # 确保签出 master 分支
  17. fetch-depth: 0 # 确保获取完整的 git 历史记录
  18. - name: Set up Python
  19. uses: actions/setup-python@v5
  20. with:
  21. python-version: "3.10"
  22. - name: Update version.py
  23. run: |
  24. python update_version.py
  25. - name: Verify version.py
  26. run: |
  27. ls -l magic_pdf/libs/version.py
  28. cat magic_pdf/libs/version.py
  29. - name: Commit changes
  30. run: |
  31. git config --local user.email "moe@myhloli.com"
  32. git config --local user.name "myhloli"
  33. git add magic_pdf/libs/version.py
  34. if git diff-index --quiet HEAD; then
  35. echo "No changes to commit"
  36. else
  37. git commit -m "Update version.py with new version"
  38. fi
  39. id: commit_changes
  40. - name: Push changes
  41. if: steps.commit_changes.outcome == 'success'
  42. env:
  43. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  44. run: |
  45. git push origin HEAD:master
  46. build:
  47. runs-on: ubuntu-latest
  48. strategy:
  49. fail-fast: false
  50. matrix:
  51. python-version: ["3.10"]
  52. steps:
  53. - name: Checkout code
  54. uses: actions/checkout@v4
  55. with:
  56. fetch-depth: 0
  57. - name: Set up Python ${{ matrix.python-version }}
  58. uses: actions/setup-python@v5
  59. with:
  60. python-version: ${{ matrix.python-version }}
  61. - name: Install dependencies
  62. run: |
  63. python -m pip install --upgrade pip
  64. if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  65. - name: Install wheel
  66. run: |
  67. python -m pip install wheel
  68. - name: Build wheel
  69. run: |
  70. python setup.py bdist_wheel
  71. - name: Upload artifact
  72. uses: actions/upload-artifact@v4
  73. with:
  74. name: wheel-file
  75. path: dist/*.whl
  76. retention-days: 30
  77. release:
  78. needs: [ build ]
  79. runs-on: ubuntu-latest
  80. steps:
  81. - name: Checkout code
  82. uses: actions/checkout@v4
  83. - name: Download artifact
  84. uses: actions/download-artifact@v4
  85. with:
  86. name: wheel-file
  87. path: dist
  88. - name: Create and Upload Release
  89. id: create_release
  90. uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981
  91. with:
  92. files: './dist/*.whl'
  93. env:
  94. GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
  95. # - name: Publish to PyPI
  96. # uses: pypa/gh-action-pypi-publish@release/v1
  97. # with:
  98. # user: __token__
  99. # password: ${{ secrets.PYPI_TOKEN }}