|
| 1 | +name: Run mypy_primer |
| 2 | + |
| 3 | +on: |
| 4 | + # Only run on PR, since we diff against master |
| 5 | + # pull_request_target gives us access to a write token |
| 6 | + pull_request_target: |
| 7 | + paths-ignore: |
| 8 | + - 'docs/**' |
| 9 | + - '**/*.rst' |
| 10 | + - '**/*.md' |
| 11 | + - 'mypyc/**' |
| 12 | + |
| 13 | +jobs: |
| 14 | + mypy_primer: |
| 15 | + name: Run mypy_primer |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v2 |
| 19 | + with: |
| 20 | + path: mypy_to_test |
| 21 | + fetch-depth: 0 |
| 22 | + # pull_request_target checks out the PR base branch by default |
| 23 | + ref: refs/pull/${{ github.event.pull_request.number }}/merge |
| 24 | + - uses: actions/setup-python@v2 |
| 25 | + with: |
| 26 | + python-version: 3.8 |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + python -m pip install -U pip |
| 30 | + pip install git+https://github.com/hauntsaninja/mypy_primer.git |
| 31 | + - name: Run mypy_primer |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + cd mypy_to_test |
| 35 | + echo "new commit" |
| 36 | + COMMIT=$(git rev-parse HEAD) |
| 37 | + git rev-list --format=%s --max-count=1 $COMMIT |
| 38 | + git checkout -b upstream_master origin/master |
| 39 | + echo "base commit" |
| 40 | + git rev-list --format=%s --max-count=1 upstream_master |
| 41 | + echo '' |
| 42 | + cd .. |
| 43 | + ( mypy_primer --repo mypy_to_test --new $COMMIT --old upstream_master --mypyc-compile-level 0 -o concise | tee diff.txt ) || [ $? -eq 1 ] |
| 44 | + - name: Post comment |
| 45 | + uses: actions/github-script@v3 |
| 46 | + with: |
| 47 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 48 | + script: | |
| 49 | + const fs = require('fs').promises; |
| 50 | + try { |
| 51 | + data = await fs.readFile('diff.txt', 'utf-8') |
| 52 | + if (data.trim()) { |
| 53 | + await github.issues.createComment({ |
| 54 | + issue_number: context.issue.number, |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + body: 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```' |
| 58 | + }) |
| 59 | + } |
| 60 | + } catch (error) { |
| 61 | + console.log(error) |
| 62 | + } |
0 commit comments