Skip to content

Commit 06c14c0

Browse files
committed
Revert "[workflows] Split pr-code-format into two parts to make it more secure (#78216)"
This reverts commit bc06cd5. This caused the job to fail for PRs which still had an older version of code-format-helper.py in their tree.
1 parent f6b3875 commit 06c14c0

File tree

3 files changed

+18
-127
lines changed

3 files changed

+18
-127
lines changed

.github/workflows/issue-write.yml

Lines changed: 0 additions & 89 deletions
This file was deleted.

.github/workflows/pr-code-format.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: "Check code formatting"
2-
on: pull_request
2+
on: pull_request_target
3+
permissions:
4+
pull-requests: write
35

46
jobs:
57
code_formatter:
@@ -25,6 +27,18 @@ jobs:
2527
separator: ","
2628
skip_initial_fetch: true
2729

30+
# We need to make sure that we aren't executing/using any code from the
31+
# PR for security reasons as we're using pull_request_target. Checkout
32+
# the target branch with the necessary files.
33+
- name: Fetch code formatting utils
34+
uses: actions/checkout@v4
35+
with:
36+
sparse-checkout: |
37+
llvm/utils/git/requirements_formatting.txt
38+
llvm/utils/git/code-format-helper.py
39+
sparse-checkout-cone-mode: false
40+
path: code-format-tools
41+
2842
- name: "Listed files"
2943
env:
3044
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
@@ -42,10 +56,10 @@ jobs:
4256
with:
4357
python-version: '3.11'
4458
cache: 'pip'
45-
cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt'
59+
cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
4660

4761
- name: Install python dependencies
48-
run: pip install -r llvm/utils/git/requirements_formatting.txt
62+
run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
4963

5064
- name: Run code formatter
5165
env:
@@ -58,17 +72,9 @@ jobs:
5872
# explicitly in code-format-helper.py and not have to diff starting at
5973
# the merge base.
6074
run: |
61-
python ./llvm/utils/git/code-format-helper.py \
62-
--write-comment-to-file \
75+
python ./code-format-tools/llvm/utils/git/code-format-helper.py \
6376
--token ${{ secrets.GITHUB_TOKEN }} \
6477
--issue-number $GITHUB_PR_NUMBER \
6578
--start-rev $(git merge-base $START_REV $END_REV) \
6679
--end-rev $END_REV \
6780
--changed-files "$CHANGED_FILES"
68-
69-
- uses: actions/upload-artifact@v2
70-
if: always()
71-
with:
72-
name: workflow-args
73-
path: |
74-
comments

llvm/utils/git/code-format-helper.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class FormatArgs:
4444
token: str = None
4545
verbose: bool = True
4646
issue_number: int = 0
47-
write_comment_to_file: bool = False
4847

4948
def __init__(self, args: argparse.Namespace = None) -> None:
5049
if not args is None:
@@ -54,14 +53,12 @@ def __init__(self, args: argparse.Namespace = None) -> None:
5453
self.token = args.token
5554
self.changed_files = args.changed_files
5655
self.issue_number = args.issue_number
57-
self.write_comment_to_file = args.write_comment_to_file
5856

5957

6058
class FormatHelper:
6159
COMMENT_TAG = "<!--LLVM CODE FORMAT COMMENT: {fmt}-->"
6260
name: str
6361
friendly_name: str
64-
comment: dict = None
6562

6663
@property
6764
def comment_tag(self) -> str:
@@ -122,13 +119,6 @@ def update_pr(self, comment_text: str, args: FormatArgs, create_new: bool) -> No
122119
comment_text = self.comment_tag + "\n\n" + comment_text
123120

124121
existing_comment = self.find_comment(pr)
125-
126-
if args.write_comment_to_file:
127-
self.comment = {"body": comment_text}
128-
if existing_comment:
129-
self.comment["id"] = existing_comment.id
130-
return
131-
132122
if existing_comment:
133123
existing_comment.edit(comment_text)
134124
elif create_new:
@@ -319,8 +309,6 @@ def hook_main():
319309
if fmt.has_tool():
320310
if not fmt.run(args.changed_files, args):
321311
failed_fmts.append(fmt.name)
322-
if fmt.comment:
323-
comments.append(fmt.comment)
324312
else:
325313
print(f"Couldn't find {fmt.name}, can't check " + fmt.friendly_name.lower())
326314

@@ -361,11 +349,6 @@ def hook_main():
361349
type=str,
362350
help="Comma separated list of files that has been changed",
363351
)
364-
parser.add_argument(
365-
"--write-comment-to-file",
366-
action="store_true",
367-
help="Don't post comments on the PR, instead write the comments and metadata a file called 'comment'",
368-
)
369352

370353
args = FormatArgs(parser.parse_args())
371354

@@ -374,18 +357,9 @@ def hook_main():
374357
changed_files = args.changed_files.split(",")
375358

376359
failed_formatters = []
377-
comments = []
378360
for fmt in ALL_FORMATTERS:
379361
if not fmt.run(changed_files, args):
380362
failed_formatters.append(fmt.name)
381-
if fmt.comment:
382-
comments.append(fmt.comment)
383-
384-
if len(comments):
385-
with open("comments", "w") as f:
386-
import json
387-
388-
json.dump(comments, f)
389363

390364
if len(failed_formatters) > 0:
391365
print(f"error: some formatters failed: {' '.join(failed_formatters)}")

0 commit comments

Comments
 (0)