From dbfb4ea7b82fd1cbdc79dccbc1a5968ca816da37 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Wed, 6 Sep 2023 10:06:55 +0100 Subject: [PATCH] Make CI more friendly for external contributors. Second try (#5210) ## Problem `approved-for-ci-run` label logic doesn't work as expected: - https://github.com/neondatabase/neon/pull/4722#issuecomment-1636742145 - https://github.com/neondatabase/neon/pull/4722#issuecomment-1636755394 Continuation of https://github.com/neondatabase/neon/pull/4663 Closes #2222 (hopefully) ## Summary of changes - Create a twin PR automatically - Allow `GITHUB_TOKEN` to manipulate with labels --- .github/workflows/approved-for-ci-run.yml | 32 ++++++++++++++++++----- .github/workflows/build_and_test.yml | 1 - .github/workflows/neon_extra_builds.yml | 1 - 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/approved-for-ci-run.yml b/.github/workflows/approved-for-ci-run.yml index ac9e908c09..c2be9adea2 100644 --- a/.github/workflows/approved-for-ci-run.yml +++ b/.github/workflows/approved-for-ci-run.yml @@ -3,6 +3,8 @@ name: Handle `approved-for-ci-run` label on: pull_request: + branches: + - main types: # Default types that triggers a workflow ([1]): # - [1] https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request @@ -18,29 +20,34 @@ env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + jobs: remove-label: # Remove `approved-for-ci-run` label if the workflow is triggered by changes in a PR. # The PR should be reviewed and labelled manually again. - runs-on: [ ubuntu-latest ] - if: | contains(fromJSON('["opened", "synchronize", "reopened", "closed"]'), github.event.action) && contains(github.event.pull_request.labels.*.name, 'approved-for-ci-run') + runs-on: ubuntu-latest + permissions: write-all + steps: - run: gh pr --repo "${GITHUB_REPOSITORY}" edit "${PR_NUMBER}" --remove-label "approved-for-ci-run" - create-branch: - # Create a local branch for an `approved-for-ci-run` labelled PR to run CI pipeline in it. - - runs-on: [ ubuntu-latest ] + create-or-update-pr-for-ci-run: + # Create local PR for an `approved-for-ci-run` labelled PR to run CI pipeline in it. if: | github.event.action == 'labeled' && contains(github.event.pull_request.labels.*.name, 'approved-for-ci-run') + runs-on: ubuntu-latest + permissions: write-all + steps: - run: gh pr --repo "${GITHUB_REPOSITORY}" edit "${PR_NUMBER}" --remove-label "approved-for-ci-run" @@ -53,3 +60,16 @@ jobs: - run: git checkout -b "ci-run/pr-${PR_NUMBER}" - run: git push --force origin "ci-run/pr-${PR_NUMBER}" + + - name: Create a Pull Request for CI run (if required) + run: | + HEAD="ci-run/pr-${PR_NUMBER}" + + ALREADY_CREATED=$(gh pr --repo "${GITHUB_REPOSITORY}" list --head "${HEAD}" --base main --json number --jq '.[].number') + if [ -z "${ALREADY_CREATED}" ]; then + gh pr --repo "${GITHUB_REPOSITORY}" create --title "[DO NOT MERGE] CI run for PR #${PR_NUMBER}" \ + --body "Ref #${PR_NUMBER}" \ + --head "${HEAD}" \ + --base main \ + --draft + fi diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 920882517b..d03f8c4365 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -5,7 +5,6 @@ on: branches: - main - release - - ci-run/pr-* pull_request: defaults: diff --git a/.github/workflows/neon_extra_builds.yml b/.github/workflows/neon_extra_builds.yml index a21ddb0414..f4e9e27e2b 100644 --- a/.github/workflows/neon_extra_builds.yml +++ b/.github/workflows/neon_extra_builds.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - ci-run/pr-* pull_request: defaults: