python-package.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. refs: 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. # git remote set-url origin https://myhloli:${{ secrets.RELEASE_TOKEN }}@github.com/magicpdf/Magic-PDF.git
  47. # git checkout -b update-version-branch || git checkout update-version-branch
  48. # git push --set-upstream origin update-version-branch
  49. # id: push_changes
  50. # - name: Create Pull Request
  51. # if: steps.push_changes.outcome == 'success'
  52. # id: create_pull_request
  53. # uses: peter-evans/create-pull-request@v5
  54. # with:
  55. # token: ${{ secrets.RELEASE_TOKEN }}
  56. # commit-message: Update version.py with new version
  57. # branch: update-version-branch
  58. # title: 'Update version.py'
  59. # body: 'This PR updates the version.py file with the latest version.'
  60. # base: master
  61. # labels: 'automated PR'
  62. #
  63. # - name: Merge Pull Request
  64. # if: steps.create_pull_request.outputs.pull-request-number
  65. # uses: actions/github-script@v6
  66. # with:
  67. # github-token: ${{ secrets.RELEASE_TOKEN }}
  68. # script: |
  69. # const pullRequestNumber = parseInt('${{ steps.create_pull_request.outputs.pull-request-number }}');
  70. # await github.pulls.merge({
  71. # owner: context.repo.owner,
  72. # repo: context.repo.repo,
  73. # pull_number: pullRequestNumber,
  74. # merge_method: 'merge'
  75. # });
  76. build:
  77. needs: [ update-version ]
  78. runs-on: ubuntu-latest
  79. strategy:
  80. fail-fast: false
  81. matrix:
  82. python-version: ["3.10"]
  83. steps:
  84. - name: Checkout code
  85. uses: actions/checkout@v4
  86. with:
  87. fetch-depth: 0
  88. - name: Set up Python ${{ matrix.python-version }}
  89. uses: actions/setup-python@v5
  90. with:
  91. python-version: ${{ matrix.python-version }}
  92. - name: Install dependencies
  93. run: |
  94. python -m pip install --upgrade pip
  95. if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  96. - name: Install wheel
  97. run: |
  98. python -m pip install wheel
  99. - name: Build wheel
  100. run: |
  101. python setup.py bdist_wheel
  102. - name: Upload artifact
  103. uses: actions/upload-artifact@v4
  104. with:
  105. name: wheel-file
  106. path: dist/*.whl
  107. retention-days: 30
  108. release:
  109. needs: [ build ]
  110. runs-on: ubuntu-latest
  111. steps:
  112. - name: Checkout code
  113. uses: actions/checkout@v4
  114. - name: Download artifact
  115. uses: actions/download-artifact@v4
  116. with:
  117. name: wheel-file
  118. path: dist
  119. - name: Create and Upload Release
  120. id: create_release
  121. uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981
  122. with:
  123. files: './dist/*.whl'
  124. env:
  125. GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
  126. # - name: Publish to PyPI
  127. # uses: pypa/gh-action-pypi-publish@release/v1
  128. # with:
  129. # user: __token__
  130. # password: ${{ secrets.PYPI_TOKEN }}