Skip to content

Commit

Permalink
script: automatic task submission
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Sep 17, 2024
1 parent 0245c3f commit 296115f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/enqueue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Enqueue

on:
issue_comment:
types: [created, edited]

jobs:
build:
if: github.event.issue.number == 1312 && github.event.sender.type == 'User'
runs-on: self-hosted

permissions:
issues: write
pull-requests: write
contents: write

steps:
- uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 0

- name: Set up Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git submodule update --init llvm/llvm-project
git -C llvm/llvm-project checkout .
git -C llvm/llvm-project clean -fdx
- name: Set up pre-commit info
id: info
run: |
echo -e "> $PATCH_URL\n\n" > ${{ github.workspace }}/scripts/issue.md
python3 ${{ github.workspace }}/scripts/enqueue.py 2>&1 | tee -a ${{ github.workspace }}/scripts/issue.md
env:
PATCH_URL: ${{ github.event.comment.body }}
USER: ${{ github.event.sender.login }}

- name: Create PR
if: steps.info.outputs.SHOULD_OPEN_PR == '1'
id: cpr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.PAT }}
branch: "test-run${{ github.run_id }}"
commit-message: "pre-commit: PR${{ steps.info.outputs.PR_TITLE }}"
title: "pre-commit: PR${{ steps.info.outputs.PR_TITLE }}"
add-paths: scripts/setup_pre_commit_patch.sh
body: |
Link: ${{ github.event.comment.body }}
Requested by: @${{ github.event.sender.login }}
- name: Update report
if: ${{ steps.cpr.outputs.pull-request-number }}
run:
echo -e "> ${{ github.event.comment.body }}\n\nSee ${{ steps.cpr.outputs.pull-request-url }}" > ${{ github.workspace }}/scripts/issue.md

- name: Comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body-path: ${{ github.workspace }}/scripts/issue.md
36 changes: 36 additions & 0 deletions scripts/enqueue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import subprocess
from urllib.parse import urlparse

patch_url = os.environ.get('PATCH_URL').strip().replace('@','')
user = os.environ.get('USER')
authorized_users = ['dtcxzyw','nikic','preames','topperc','goldsteinn','fhahn','RKSimon','arsenm','antoniofrighetto','asb']

if user not in authorized_users:
print(f'User {user} is not authorized to submit tasks.')
exit(0)

try:
res = urlparse(patch_url)
if res.scheme != 'https':
print(f'Please provide a valid HTTPS URL: {patch_url}')
exit(0)
if res.netloc != 'github.com':
print(f'Please provide a valid GitHub URL: {patch_url}')
exit(0)
except:
print(f'Invalid patch URL: {patch_url}')
exit(0)

patch_name = patch_url.replace('https://github.com/llvm/llvm-project/pull/', '')

try:
subprocess.check_call(['sed', '-i', f's|export GITHUB_PATCH_ID=.*|export GITHUB_PATCH_ID={patch_url}|', 'scripts/setup_pre_commit_patch.sh'])
except Exception as e:
print(f'Failed to set up patch: {e}')
exit(0)

output_path = os.getenv('GITHUB_OUTPUT')
with open(output_path, 'a') as f:
f.write(f"SHOULD_OPEN_PR=1\n")
f.write(f"PR_TITLE={patch_name}\n")

0 comments on commit 296115f

Please sign in to comment.