From c117017cbb7c31e67db78ffca03b3c27e6b45ff9 Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 02:46:03 +0700 Subject: [PATCH 1/6] Adds Actions to automatically add/remove S-ready from PRs --- .github/workflows/main.yml | 11 ++++---- .github/workflows/pr.yml | 43 ++++++++++++++++++++++++------- .github/workflows/qc-prebuild.yml | 12 --------- 3 files changed, 40 insertions(+), 26 deletions(-) delete mode 100644 .github/workflows/qc-prebuild.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a444609bc..7bdd9189c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,10 +32,11 @@ jobs: for pull in repo.get_pulls("open", "updated", "desc", "${{ github.ref_name }}"): if (now - pull.updated_at).days > 30: break - ood = False + ready = False for label in pull.labels: - if label.name == "B-out-of-date": - ood = True - if not ood: - pull.add_to_labels("B-out-of-date") + if label.name == "S-ready": + ready = True + if ready: + print(f"Removing S-ready from {pull.title}") + pull.remove_from_labels("S-ready") shell: python diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c9da4e1d0..9234e257c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -5,18 +5,43 @@ on: - '*' concurrency: pr-${{ github.ref }} jobs: - quality-checks: - name: Pre-Build - uses: ./.github/workflows/qc-prebuild.yml - windows: - needs: quality-checks + prebuild: + name: Pre build + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v4 + - name: Check Rust styles + run: cargo fmt --check + working-directory: src + build-windows: name: Build uses: ./.github/workflows/ci-windows.yml - linux: - needs: quality-checks + needs: prebuild + build-linux: name: Build uses: ./.github/workflows/ci-linux.yml - mac: - needs: quality-checks + needs: prebuild + build-mac: 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: Install Python modules + run: pip install PyGithub + - name: Update PR + run: | + from github import Auth, Github + + gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) + repo = gh.get_repo("${{ github.repository }}") + cmp = repo.compare("${{ github.base_ref }}", "${{ github.head_ref }}") + + if cmp.status != "behind": + pull = repo.get_pull(${{ github.event.number }}) + pull.add_to_labels("S-ready") + shell: python diff --git a/.github/workflows/qc-prebuild.yml b/.github/workflows/qc-prebuild.yml deleted file mode 100644 index 4b8918bdf..000000000 --- a/.github/workflows/qc-prebuild.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Prebuild Quality Checks -on: - workflow_call: -jobs: - code-checks: - name: Code Checks - runs-on: ubuntu-22.04 - steps: - - name: Checkout source - uses: actions/checkout@v4 - - name: Run RustFMT Check - run: cd src && cargo fmt --check From 7f3df7810f43e5d7545c6706884237b1c9e18c8f Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 03:04:32 +0700 Subject: [PATCH 2/6] Fixes incorrect head when compare the PR --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9234e257c..0993e1d17 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -39,7 +39,7 @@ jobs: gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) repo = gh.get_repo("${{ github.repository }}") - cmp = repo.compare("${{ github.base_ref }}", "${{ github.head_ref }}") + cmp = repo.compare("${{ github.base_ref }}", "${{ github.event.head.user.login }}:${{ github.event.head.sha }}") if cmp.status != "behind": pull = repo.get_pull(${{ github.event.number }}) From 31633782698597b13e199f6cfce650c485ad1d86 Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 03:27:23 +0700 Subject: [PATCH 3/6] Fixes empty head when compare the PR --- .github/workflows/pr.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0993e1d17..3e672d724 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -37,9 +37,11 @@ jobs: run: | from github import Auth, Github + author = "${{ github.event.pull_request.head.user.login }}" + head = "${{ github.event.pull_request.head.sha }}" gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) repo = gh.get_repo("${{ github.repository }}") - cmp = repo.compare("${{ github.base_ref }}", "${{ github.event.head.user.login }}:${{ github.event.head.sha }}") + cmp = repo.compare("${{ github.base_ref }}", f"{author}:{head}") if cmp.status != "behind": pull = repo.get_pull(${{ github.event.number }}) From 81e2baadfd9ca2f0541cc9899ec3d03ee21813b4 Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 03:45:48 +0700 Subject: [PATCH 4/6] Fixes insufficient permission to add labels --- .github/workflows/pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3e672d724..4056f983d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -30,6 +30,8 @@ jobs: name: Post build runs-on: ubuntu-latest needs: [build-windows, build-linux, build-mac] + permissions: + pull-requests: write steps: - name: Install Python modules run: pip install PyGithub From 1b042ed6760e93e16f6619fbd88d04dbf15f07ac Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 04:04:54 +0700 Subject: [PATCH 5/6] Grants write access for issues --- .github/workflows/pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 4056f983d..f7cfde6d2 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -31,6 +31,7 @@ jobs: runs-on: ubuntu-latest needs: [build-windows, build-linux, build-mac] permissions: + issues: write pull-requests: write steps: - name: Install Python modules From 8ce753d1afe68ebf291ec885d264a4f11d522efd Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 13:56:02 +0700 Subject: [PATCH 6/6] Adds a dedicated workflow for updating the PRs --- .github/workflows/pr-postbuild.yml | 37 ++++++++++++++++++++++++++++++ .github/workflows/pr.yml | 24 ------------------- 2 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/pr-postbuild.yml diff --git a/.github/workflows/pr-postbuild.yml b/.github/workflows/pr-postbuild.yml new file mode 100644 index 000000000..65078cd1d --- /dev/null +++ b/.github/workflows/pr-postbuild.yml @@ -0,0 +1,37 @@ +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.yml b/.github/workflows/pr.yml index f7cfde6d2..831ae8410 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -26,27 +26,3 @@ 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] - permissions: - issues: write - pull-requests: write - steps: - - name: Install Python modules - run: pip install PyGithub - - name: Update PR - run: | - from github import Auth, Github - - author = "${{ github.event.pull_request.head.user.login }}" - head = "${{ github.event.pull_request.head.sha }}" - gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) - repo = gh.get_repo("${{ github.repository }}") - cmp = repo.compare("${{ github.base_ref }}", f"{author}:{head}") - - if cmp.status != "behind": - pull = repo.get_pull(${{ github.event.number }}) - pull.add_to_labels("S-ready") - shell: python