python-package.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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
  17. fetch-depth: 0
  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.RELEASE_TOKEN }}
  44. run: |
  45. git push origin HEAD:master
  46. check-install:
  47. needs: [ update-version ]
  48. runs-on: ubuntu-latest
  49. strategy:
  50. fail-fast: false
  51. matrix:
  52. python-version: ["3.10", "3.11", "3.12", "3.13"]
  53. steps:
  54. - name: Checkout code
  55. uses: actions/checkout@v4
  56. with:
  57. ref: master
  58. fetch-depth: 0
  59. - name: Verify version.py
  60. run: |
  61. ls -l magic_pdf/libs/version.py
  62. cat magic_pdf/libs/version.py
  63. - name: Set up Python ${{ matrix.python-version }}
  64. uses: actions/setup-python@v5
  65. with:
  66. python-version: ${{ matrix.python-version }}
  67. - name: Install magic-pdf
  68. run: |
  69. python -m pip install --upgrade pip
  70. pip install -e .[full]
  71. build:
  72. needs: [ check-install ]
  73. runs-on: ubuntu-latest
  74. strategy:
  75. fail-fast: false
  76. matrix:
  77. python-version: [ "3.10"]
  78. steps:
  79. - name: Checkout code
  80. uses: actions/checkout@v4
  81. with:
  82. ref: master
  83. fetch-depth: 0
  84. - name: Install wheel
  85. run: |
  86. python -m pip install wheel
  87. - name: Build wheel
  88. run: |
  89. python setup.py bdist_wheel
  90. - name: Upload artifact
  91. uses: actions/upload-artifact@v4
  92. with:
  93. name: wheel-file
  94. path: dist/*.whl
  95. retention-days: 30
  96. release:
  97. needs: [ build ]
  98. runs-on: ubuntu-latest
  99. steps:
  100. - name: Checkout code
  101. uses: actions/checkout@v4
  102. - name: Download artifact
  103. uses: actions/download-artifact@v4
  104. with:
  105. name: wheel-file
  106. path: dist
  107. - name: Create and Upload Release
  108. id: create_release
  109. uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981
  110. with:
  111. files: './dist/*.whl'
  112. env:
  113. GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
  114. - name: Publish distribution to PyPI
  115. run: |
  116. pip install -U twine id keyring packaging readme-renderer requests requests-toolbelt rfc3986 rich urllib3
  117. twine check dist/*
  118. twine upload dist/* -u __token__ -p ${{ secrets.PYPI_TOKEN }}