szdiff.yml 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. name: Check Line Counts
  2. on:
  3. pull_request_target:
  4. # Cancel the workflow in progress in newer build is about to start.
  5. concurrency:
  6. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  7. cancel-in-progress: true
  8. jobs:
  9. checkbranch:
  10. name: Check PR Branch status
  11. runs-on: ubuntu-latest
  12. outputs:
  13. branchstat: ${{ steps.brstat.outputs.stat}}
  14. steps:
  15. - name: Check code from PR branch
  16. uses: actions/checkout@v4
  17. with:
  18. repository: ${{ github.event.pull_request.head.repo.full_name }}
  19. ref: ${{ github.event.pull_request.head.sha }}
  20. fetch-depth: 0
  21. - name: Check whether branch is up-to-date
  22. id: brstat
  23. run: |
  24. git remote add tinygrad https://github.com/tinygrad/tinygrad
  25. git fetch tinygrad master
  26. echo "${{ github.event.pull_request.head.sha }}"
  27. git rev-list --left-right --count tinygrad/master...${{ github.event.pull_request.head.sha }} | awk '{print "Behind "$1" - Ahead "$2""}'
  28. count=$(git rev-list --left-right --count tinygrad/master...${{ github.event.pull_request.head.sha }} | awk '{print $1}')
  29. if [ $count -gt 0 ]
  30. then
  31. echo "Current branch is behind tinygrad master branch!"
  32. echo "stat=true" >> "$GITHUB_OUTPUT"
  33. else
  34. echo "stat=false" >> "$GITHUB_OUTPUT"
  35. fi
  36. szdiff:
  37. name: Core Library Line Difference
  38. permissions:
  39. contents: read
  40. pull-requests: write
  41. runs-on: ubuntu-latest
  42. needs: checkbranch
  43. if: needs.checkbranch.outputs.branchstat == 'false'
  44. steps:
  45. - name: Checkout code from PR branch
  46. uses: actions/checkout@v4
  47. with:
  48. repository: ${{ github.event.pull_request.head.repo.full_name }}
  49. ref: ${{ github.event.pull_request.head.sha }}
  50. path: pr
  51. # the base default to tinygrad master and cannot be other fork branch for security purpose
  52. - name: Checkout code from tinygrad master
  53. uses: actions/checkout@v4
  54. with:
  55. path: base
  56. - name: Set up Python 3.10
  57. uses: actions/setup-python@v5
  58. with:
  59. python-version: '3.10'
  60. - name: Count Line Diff
  61. run: |
  62. pip install tabulate
  63. BASE="$GITHUB_WORKSPACE/base"
  64. PR="$GITHUB_WORKSPACE/pr"
  65. cp "$BASE/sz.py" .
  66. echo "loc_content<<EOF" >> "$GITHUB_ENV"
  67. python sz.py "$BASE" "$PR" >> "$GITHUB_ENV"
  68. echo "EOF" >> "$GITHUB_ENV"
  69. - name: Comment Code Line Diff
  70. continue-on-error: false
  71. uses: marocchino/sticky-pull-request-comment@v2
  72. with:
  73. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  74. ignore_empty: true
  75. skip_unchanged: true
  76. recreate: true
  77. message: ${{ env.loc_content }}
  78. rebase:
  79. name: Core Library Line Difference
  80. permissions:
  81. pull-requests: write
  82. runs-on: ubuntu-latest
  83. needs: checkbranch
  84. if: needs.checkbranch.outputs.branchstat == 'true'
  85. steps:
  86. - name: Comment Rebase
  87. continue-on-error: false
  88. uses: marocchino/sticky-pull-request-comment@v2
  89. with:
  90. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  91. skip_unchanged: true
  92. recreate: true
  93. message: |
  94. This branch currently is behind tinygrad/master. The line count difference bot is disabled.