|
| 1 | +# Most of this is inspired by the mypy primer |
| 2 | + |
| 3 | +name: Primer |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + pull_request: |
| 10 | + |
| 11 | +jobs: |
| 12 | + primer-run: |
| 13 | + name: Run |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Check out working version |
| 17 | + |
| 18 | + with: |
| 19 | + fetch-depth: 2 |
| 20 | + - name: Check out changeable version |
| 21 | + |
| 22 | + with: |
| 23 | + path: program_to_test |
| 24 | + fetch-depth: 0 |
| 25 | + - name: Set up Python 3.10 |
| 26 | + uses: actions/setup-python@v3 |
| 27 | + with: |
| 28 | + python-version: "3.10" |
| 29 | + - name: Install dependencies |
| 30 | + run: pip install -U -r requirements-test.txt |
| 31 | + - name: Run primer |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + cd program_to_test |
| 35 | + echo "new commit" |
| 36 | + git rev-list --format=%s --max-count=1 $GITHUB_SHA |
| 37 | +
|
| 38 | + MERGE_BASE=$(git merge-base $GITHUB_SHA origin/main) |
| 39 | + git checkout -b base_commit $MERGE_BASE |
| 40 | + echo "base commit" |
| 41 | + git rev-list --format=%s --max-count=1 base_commit |
| 42 | +
|
| 43 | + echo "installing changeable version" |
| 44 | + pip install -e . |
| 45 | + cd .. |
| 46 | +
|
| 47 | + python -m pydocstringformatter.testutils.primer.primer --prepare |
| 48 | + python -m pydocstringformatter.testutils.primer.primer --step-one |
| 49 | +
|
| 50 | + cd program_to_test |
| 51 | + git checkout $GITHUB_SHA |
| 52 | + cd .. |
| 53 | + python -m pydocstringformatter.testutils.primer.primer --step-two |
| 54 | + - name: Post comment |
| 55 | + id: post-comment |
| 56 | + uses: actions/github-script@v3 |
| 57 | + with: |
| 58 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + script: | |
| 60 | + const fs = require('fs') |
| 61 | + const data = fs.readFileSync('.pydocstringformatter_primer_tests/fulldiff.txt', { encoding: 'utf8' }) |
| 62 | + console.log("Diff from primer:") |
| 63 | + console.log(data) |
| 64 | + let body |
| 65 | + if (data.trim()) { |
| 66 | + body = 'Diff from the primer, showing the effect of this PR on open source code:\n' + data |
| 67 | + } else { |
| 68 | + body = 'According to the primer, this change has no effect on the checked open source code. 🤖🎉' |
| 69 | + } |
| 70 | + await github.issues.createComment({ |
| 71 | + issue_number: ${{ github.event.pull_request.number }}, |
| 72 | + owner: context.repo.owner, |
| 73 | + repo: context.repo.repo, |
| 74 | + body |
| 75 | + }) |
| 76 | + - name: Hide old comments |
| 77 | + # Taken from mypy primer |
| 78 | + # v0.3.0 |
| 79 | + uses: kanga333/comment-hider@bbdf5b562fbec24e6f60572d8f712017428b92e0 |
| 80 | + with: |
| 81 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + leave_visible: 1 |
| 83 | + issue_number: ${{ steps.post-comment.outputs.result }} |
0 commit comments