diff --git a/.github/workflows/pr-postbuild.yml b/.github/workflows/pr-postbuild.yml deleted file mode 100644 index 65078cd1d..000000000 --- a/.github/workflows/pr-postbuild.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: PR Post Build -on: - workflow_run: - workflows: [PR Build] - types: - - completed -jobs: - postbuild: - name: Update PR - runs-on: ubuntu-latest - if: github.event.workflow_run.conclusion == 'success' - steps: - - name: Install Python modules - run: pip install PyGithub - - name: Update PR - run: | - from github import Auth, Github - import json - - event = json.loads('${{ toJSON(github.event) }}') - gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) - repo = gh.get_repo("${{ github.repository }}") - - for pull in event["workflow_run"]["pull_requests"]: - author = pull["head"]["repo"]["name"] - head = pull["head"]["sha"] - cmp = repo.compare(pull["base"]["ref"], f"{author}:{head}") - - if cmp.status != "behind": - pull = repo.get_pull(pull["number"]) - 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 diff --git a/.github/workflows/pr-update.yml b/.github/workflows/pr-update.yml new file mode 100644 index 000000000..02bfb2cd8 --- /dev/null +++ b/.github/workflows/pr-update.yml @@ -0,0 +1,47 @@ +name: PR Post Build +on: + workflow_run: + workflows: [PR Build] + types: + - completed +jobs: + postbuild: + name: Update PR + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' + steps: + - name: Install Python modules + run: pip install PyGithub + - name: Update PR + run: | + from github import Auth, Github + import json + from urllib.request import urlopen + from zipfile import ZipFile + + event = json.loads('''${{ toJSON(github.event.workflow_run) }}''') + gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) + repo = gh.get_repo("${{ github.repository }}") + run = repo.get_workflow_run(event["id"]) + info = None + + for artifact in run.get_artifacts(): + if artifact.name == "build-info": + info = artifact + + with urlopen(info.archive_download_url) as info: + zip = ZipFile(info) + with zip.open("build-info.json") as info: + info = json.load(info) + + cmp = repo.compare(info["base"], f"{info["author"]}:{info["head"]}") + + if cmp.status != "behind": + pull = repo.get_pull(info["pr"]) + 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 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 831ae8410..a34a26046 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -26,3 +26,27 @@ jobs: name: Build uses: ./.github/workflows/ci-mac.yml needs: prebuild + postbuild: + name: Post build + runs-on: ubuntu-latest + needs: [build-windows, build-linux, build-mac] + steps: + - name: Generate build information + run: | + import json + + info = { + "pr": ${{ github.event.number }}, + "base": "${{ github.base_ref }}", + "head": "${{ github.event.pull_request.head.sha }}", + "author": "${{ github.event.pull_request.head.user.login }}" + } + + with open("build-info.json", "w") as fp: + json.dump(info, fp) + shell: python + - name: Upload build information + uses: actions/upload-artifact@v4 + with: + name: build-info + path: build-info.json