Skip to content

Commit 56f12e6

Browse files
samestepfacebook-github-bot
authored andcommitted
Add annotations to PRs from forks (#54779)
Summary: We've been using [pytorch/add-annotations-github-action](https://github.com/pytorch/add-annotations-github-action) to add annotations to PRs when they fail Flake8 or clang-tidy. Up until now, though, that functionality has only worked on PRs in pytorch/pytorch itself, not on PRs from forks. This PR fixes that using a technique from [this GitHub blog post](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) (also linked in a comment in this diff). Pull Request resolved: #54779 Test Plan: janeyx99 and I tested this in the same GitHub repo used to test #54685 and #54693, including with PRs from forks. Reviewed By: walterddr Differential Revision: D27364777 Pulled By: samestep fbshipit-source-id: a830d372d7bb3b2529fc633b707b44f2b6cf9baa
1 parent 68af6d9 commit 56f12e6

File tree

2 files changed

+81
-28
lines changed

2 files changed

+81
-28
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Add annotations
2+
3+
on:
4+
workflow_run:
5+
types:
6+
- completed
7+
workflows:
8+
- Lint
9+
10+
jobs:
11+
annotate:
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- name: flake8-py3
17+
regex: '^(?<filename>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+): (?<errorCode>\w+\d+) (?<errorDesc>.*)'
18+
- name: clang-tidy
19+
regex: '^(?<filename>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+): (?<errorDesc>.*?) \[(?<errorCode>.*)\]'
20+
if: github.event.workflow_run.event == 'pull_request'
21+
runs-on: ubuntu-18.04
22+
steps:
23+
- name: Download artifact
24+
uses: actions/github-script@v3
25+
with:
26+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
27+
script: |
28+
const artifacts = await github.actions.listWorkflowRunArtifacts({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
run_id: ${{ github.event.workflow_run.id }},
32+
});
33+
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
34+
return artifact.name == '${{ matrix.name }}';
35+
})[0];
36+
const download = await github.actions.downloadArtifact({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
artifact_id: matchArtifact.id,
40+
archive_format: 'zip',
41+
});
42+
const fs = require('fs');
43+
fs.writeFileSync('${{ github.workspace }}/linter-output.zip', Buffer.from(download.data));
44+
- name: Unzip artifact
45+
run: unzip linter-output.zip
46+
- name: Get commit SHA
47+
run: echo ::set-output name=commit-sha::$(cat commit-sha.txt)
48+
id: get-commit-sha
49+
- name: Add annotations
50+
uses: pytorch/add-annotations-github-action@master
51+
with:
52+
check_name: ${{ matrix.name }}
53+
linter_output_path: warnings.txt
54+
commit_sha: ${{ steps.get-commit-sha.outputs.commit-sha }}
55+
regex: ${{ matrix.regex }}
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/lint.yml

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,25 @@ jobs:
6868
uses: actions/checkout@v2
6969
with:
7070
ref: ${{ github.event.pull_request.head.sha }}
71-
- name: Get HEAD commit SHA
72-
run: echo ::set-output name=commit-sha::$(git rev-parse HEAD)
73-
id: get-commit-sha
71+
- name: Prepare output dir with HEAD commit SHA
72+
run: |
73+
mkdir flake8-output
74+
cd flake8-output
75+
echo ${{ github.event.pull_request.head.sha }} > commit-sha.txt
7476
- name: Run flake8
7577
run: |
7678
set -eux
7779
pip install -r requirements-flake8.txt
7880
flake8 --version
79-
flake8 | tee ${GITHUB_WORKSPACE}/flake8-output.txt
80-
- name: Add annotations
81-
uses: pytorch/add-annotations-github-action@master
81+
flake8 | tee ${GITHUB_WORKSPACE}/flake8-output/warnings.txt
82+
- name: Upload artifact
83+
uses: actions/upload-artifact@v2
8284
with:
83-
check_name: 'flake8-py3'
84-
linter_output_path: 'flake8-output.txt'
85-
commit_sha: ${{ steps.get-commit-sha.outputs.commit-sha }}
86-
regex: '^(?<filename>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+): (?<errorCode>\w+\d+) (?<errorDesc>.*)'
87-
env:
88-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89-
- name: Catch any other warnings
90-
run: |
91-
[ ! -s flake8-output.txt ]
85+
name: flake8-py3
86+
path: flake8-output/
87+
- name: Fail if there were any warnings
88+
run: |
89+
[ ! -s flake8-output/warnings.txt ]
9290
9391
clang-tidy:
9492
if: github.event_name == 'pull_request'
@@ -104,9 +102,11 @@ jobs:
104102
with:
105103
ref: ${{ github.event.pull_request.head.sha }}
106104
fetch-depth: 0 # deep clone, to allow us to use git merge-base
107-
- name: Get HEAD commit SHA
108-
run: echo ::set-output name=commit-sha::$(git rev-parse HEAD)
109-
id: get-commit-sha
105+
- name: Prepare output dir with HEAD commit SHA
106+
run: |
107+
mkdir clang-tidy-output
108+
cd clang-tidy-output
109+
echo ${{ github.event.pull_request.head.sha }} > commit-sha.txt
110110
- name: Install dependencies
111111
run: |
112112
set -eux
@@ -180,18 +180,14 @@ jobs:
180180
-g"-torch/csrc/deploy/interpreter/interpreter.h" \
181181
-g"-torch/csrc/deploy/interpreter/interpreter_impl.h" \
182182
-g"-torch/csrc/deploy/interpreter/test_main.cpp" \
183-
"$@" > ${GITHUB_WORKSPACE}/clang-tidy-output.txt
183+
"$@" > ${GITHUB_WORKSPACE}/clang-tidy-output/warnings.txt
184184
185-
cat ${GITHUB_WORKSPACE}/clang-tidy-output.txt
186-
- name: Add annotations
187-
uses: pytorch/add-annotations-github-action@master
185+
cat ${GITHUB_WORKSPACE}/clang-tidy-output/warnings.txt
186+
- name: Upload artifact
187+
uses: actions/upload-artifact@v2
188188
with:
189-
check_name: 'clang-tidy'
190-
linter_output_path: 'clang-tidy-output.txt'
191-
commit_sha: ${{ steps.get-commit-sha.outputs.commit-sha }}
192-
regex: '^(?<filename>.*?):(?<lineNumber>\d+):(?<columnNumber>\d+): (?<errorDesc>.*?) \[(?<errorCode>.*)\]'
193-
env:
194-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
189+
name: clang-tidy
190+
path: clang-tidy-output/
195191

196192
cmakelint:
197193
runs-on: ubuntu-18.04

0 commit comments

Comments
 (0)