Update PR #1103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update PR | |
on: | |
workflow_run: | |
workflows: [PR Build] | |
types: | |
- completed | |
jobs: | |
postbuild: | |
name: Update PR | |
runs-on: ubuntu-24.04 | |
if: github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: Install System Packages | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3-github | |
- name: Update PR | |
run: | | |
from github import Auth, Github | |
from io import BytesIO | |
import json | |
from urllib.request import Request, urlopen | |
from zipfile import ZipFile | |
tok = "${{ secrets.GITHUB_TOKEN }}" | |
gh = Github(auth=Auth.Token(tok)) | |
repo = gh.get_repo("${{ github.repository }}") | |
run = repo.get_workflow_run(${{ github.event.workflow_run.id }}) | |
info = None | |
for artifact in run.get_artifacts(): | |
if artifact.name == "build-info": | |
info = artifact | |
req = Request(info.archive_download_url) | |
req.add_unredirected_header("Authorization", f"token {tok}") | |
req.add_unredirected_header("Accept", "application/vnd.github+json") | |
with urlopen(req) as info: | |
zip = ZipFile(BytesIO(info.read())) | |
with zip.open("build-info.json") as info: | |
info = json.load(info) | |
pull = repo.get_pull(info["pr"]) | |
if not pull.draft: | |
author = info["author"]; | |
head = info["head"] | |
cmp = repo.compare(info["base"], f"{author}:{head}") | |
if cmp.status != "behind": | |
ready = False | |
for label in pull.labels: | |
if label.name == "S-ready": | |
ready = True | |
if not ready: | |
pull.add_to_labels("S-ready") | |
shell: python |