Skip to content

Commit 7225cd8

Browse files
committed
script: automatic task submission
1 parent 0245c3f commit 7225cd8

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/workflows/enqueue.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Enqueue
2+
3+
on:
4+
issue_comment:
5+
types: [created, edited]
6+
7+
jobs:
8+
build:
9+
if: github.event.issue.number == 1312 && github.event.sender.type == 'User'
10+
runs-on: self-hosted
11+
12+
permissions:
13+
issues: write
14+
pull-requests: write
15+
contents: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: false
21+
fetch-depth: 0
22+
23+
- name: Set up Git
24+
run: |
25+
git config user.name "github-actions[bot]"
26+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
27+
git submodule update --init llvm/llvm-project
28+
git -C llvm/llvm-project checkout .
29+
git -C llvm/llvm-project clean -fdx
30+
31+
- name: Set up pre-commit info
32+
id: info
33+
run: |
34+
echo -e "> $PATCH_URL\n\n" > ${{ github.workspace }}/scripts/issue.md
35+
python3 ${{ github.workspace }}/scripts/enqueue.py 2>&1 | tee -a ${{ github.workspace }}/scripts/issue.md
36+
env:
37+
PATCH_URL: ${{ github.event.comment.body }}
38+
USER: ${{ github.event.sender.login }}
39+
40+
- name: Create PR
41+
if: steps.info.outputs.SHOULD_OPEN_PR == '1'
42+
id: cpr
43+
uses: peter-evans/create-pull-request@v7
44+
with:
45+
token: ${{ secrets.PAT }}
46+
branch: "test-run${{ github.run_id }}"
47+
commit-message: "pre-commit: PR${{ steps.info.outputs.PR_TITLE }}"
48+
title: "pre-commit: PR${{ steps.info.outputs.PR_TITLE }}"
49+
add-paths: scripts/setup_pre_commit_patch.sh
50+
body: |
51+
Link: ${{ github.event.comment.body }}
52+
Requested by: @${{ github.event.sender.login }}
53+
54+
- name: Update report
55+
if: ${{ steps.cpr.outputs.pull-request-number }}
56+
run:
57+
echo -e "> ${{ github.event.comment.body }}\n\nSee ${{ steps.cpr.outputs.pull-request-url }}" > ${{ github.workspace }}/scripts/issue.md
58+
59+
- name: Comment
60+
uses: peter-evans/create-or-update-comment@v4
61+
with:
62+
issue-number: ${{ github.event.issue.number }}
63+
body-path: ${{ github.workspace }}/scripts/issue.md

scripts/enqueue.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import subprocess
3+
from urllib.parse import urlparse
4+
5+
patch_url = os.environ.get('PATCH_URL').strip().replace('@','')
6+
user = os.environ.get('USER')
7+
authorized_users = ['dtcxzyw','nikic','preames','topperc','goldsteinn','fhahn','RKSimon','arsenm','antoniofrighetto','asb']
8+
9+
if user not in authorized_users:
10+
print(f'User {user} is not authorized to submit tasks.')
11+
exit(0)
12+
13+
try:
14+
res = urlparse(patch_url)
15+
if res.scheme != 'https':
16+
print(f'Please provide a valid HTTPS URL: {patch_url}')
17+
exit(0)
18+
if res.netloc != 'github.com':
19+
print(f'Please provide a valid GitHub URL: {patch_url}')
20+
exit(0)
21+
patch_url = res.path.removeprefix('/')
22+
except:
23+
print(f'Invalid patch URL: {patch_url}')
24+
exit(0)
25+
26+
patch_name = patch_url.removeprefix('llvm/llvm-project/pull/')
27+
28+
try:
29+
subprocess.check_call(['sed', '-i', f's|export GITHUB_PATCH_ID=.*|export GITHUB_PATCH_ID={patch_url}|', 'scripts/setup_pre_commit_patch.sh'])
30+
except Exception as e:
31+
print(f'Failed to set up patch: {e}')
32+
exit(0)
33+
34+
output_path = os.getenv('GITHUB_OUTPUT')
35+
with open(output_path, 'a') as f:
36+
f.write(f"SHOULD_OPEN_PR=1\n")
37+
f.write(f"PR_TITLE={patch_name}\n")

0 commit comments

Comments
 (0)