python-package.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. build:
  47. needs: [ update-version ]
  48. runs-on: ubuntu-latest
  49. strategy:
  50. fail-fast: false
  51. matrix:
  52. python-version: ["3.10"]
  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 dependencies
  68. run: |
  69. python -m pip install --upgrade pip
  70. if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  71. - name: Install wheel
  72. run: |
  73. python -m pip install wheel
  74. - name: Build wheel
  75. run: |
  76. python setup.py bdist_wheel
  77. - name: Upload artifact
  78. uses: actions/upload-artifact@v4
  79. with:
  80. name: wheel-file
  81. path: dist/*.whl
  82. retention-days: 30
  83. release:
  84. needs: [ build ]
  85. runs-on: ubuntu-latest
  86. steps:
  87. - name: Checkout code
  88. uses: actions/checkout@v4
  89. - name: Download artifact
  90. uses: actions/download-artifact@v4
  91. with:
  92. name: wheel-file
  93. path: dist
  94. - name: Create and Upload Release
  95. id: create_release
  96. uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981
  97. with:
  98. files: './dist/*.whl'
  99. env:
  100. GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
  101. - name: Publish distribution to PyPI
  102. run: |
  103. pip install twine
  104. twine upload dist/* -u __token__ -p ${{ secrets.PYPI_TOKEN }}