diff --git a/.github/workflows/enqueue.yml b/.github/workflows/enqueue.yml new file mode 100644 index 00000000000..4c2b1b243f9 --- /dev/null +++ b/.github/workflows/enqueue.yml @@ -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 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + 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 }}" + body: | + Link: ${{ github.event.comment.body }} + Requested by: @${{ github.event.sender.login }} + + - name: Update report + if: ${{ steps.cpr.outputs.pull-request-number }} + run: + echo "See ${{ 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 diff --git a/scripts/enqueue.py b/scripts/enqueue.py new file mode 100644 index 00000000000..cf80387ed3f --- /dev/null +++ b/scripts/enqueue.py @@ -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) + +env_path = os.getenv('GITHUB_ENV') +with open(env_path, 'w') as f: + f.write(f"SHOULD_OPEN_PR=1\n") + f.write(f"PR_TITLE={patch_name}\n")