From e790554968bbeeb4e5e9b0447ab26249c7cd3441 Mon Sep 17 00:00:00 2001 From: "chromebrew-actions[bot]" <220035932+chromebrew-actions[bot]@users.noreply.github.com> Date: Thu, 24 Jul 2025 14:11:00 -0500 Subject: [PATCH] Add draft flag to PR generation and build worflows. (#12250) Signed-off-by: Satadru Pramanik Co-authored-by: Satadru Pramanik --- .github/workflows/Build.yml | 24 +++++++++++++++++++----- .github/workflows/Generate-PR.yml | 15 +++++++++++++-- .github/workflows/No-Compile-Needed.yml | 19 +++++++++++++++++-- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 37479fef18..7387102373 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -6,8 +6,12 @@ on: with_pr: description: "Create a PR after building." required: false - type: boolean - default: 'true' + type: choice + default: 'Pull Request' + options: + - Pull Request + - Draft Pull Request + - No allow_fail: description: "Allow packages to fail building." required: false @@ -479,13 +483,14 @@ jobs: organization: chromebrew revoke_token: true - name: Create Pull Request - if: ${{ github.event.inputs.with_pr == 'true' }} + if: ${{ github.event.inputs.with_pr != 'No' }} env: CHANGED_GITHUB_CONFIG_FILES: ${{ steps.changed-files.outputs.github_all_changed_files }} CHANGED_MANIFEST_FILES: ${{ steps.changed-files.outputs.manifest_all_changed_files }} CHANGED_OTHER_FILES: ${{ steps.changed-files.outputs.other_all_changed_files }} CHANGED_PACKAGES: ${{ needs.setup.outputs.changed_packages }} GH_TOKEN: ${{ steps.get_workflow_token.outputs.token }} + PR_TYPE: ${{ github.event.inputs.with_pr }} TIMESTAMP: ${{ needs.setup.outputs.timestamp }} i686_PACKAGES: ${{ needs.setup.outputs.i686_packages }} x86_64_PACKAGES: ${{ needs.setup.outputs.x86_64_packages }} @@ -526,8 +531,17 @@ jobs: echo -e "CREW_REPO=https://github.com/chromebrew/chromebrew.git CREW_BRANCH=${{ env.BRANCH }} crew update \\" >> /tmp/pr.txt echo -e "&& yes | crew upgrade\n\`\`\`" >> /tmp/pr.txt cat /tmp/pr.txt - PR_NUMBER=$(gh pr create --reviewer chromebrew/active --title "Build: ${{ env.BRANCH }} started at ${TIMESTAMP}." -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev) + [[ $PR_TYPE == 'Draft Pull Request' ]] && export PR_DRAFT_FLAG='-d' + if [[ -z ${PR_NUMBER} ]]; then + PR_NUMBER=$(gh pr create ${PR_DRAFT_FLAG} --reviewer chromebrew/active --title "Build: ${{ env.BRANCH }} started at ${TIMESTAMP}." -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev) + else + gh pr edit -F /tmp/pr.txt + fi # Draft PRs can not be set to automerge. - gh pr merge "${PR_NUMBER}" --auto || true + if [[ PR_TYPE == 'Draft Pull Request' ]]; then + gh pr ready --undo || true + else + gh pr merge --auto || true + fi echo "PR_NUMBER is ${PR_NUMBER}" echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_ENV" diff --git a/.github/workflows/Generate-PR.yml b/.github/workflows/Generate-PR.yml index f753df637f..46813a668b 100644 --- a/.github/workflows/Generate-PR.yml +++ b/.github/workflows/Generate-PR.yml @@ -3,6 +3,11 @@ name: Generate PR on: workflow_dispatch: inputs: + draft_pr: + description: "Create a Draft PR." + required: false + type: boolean + default: 'false' branch: description: "Branch of chromebrew/chromebrew to run on, if different from this branch." required: false @@ -183,6 +188,7 @@ jobs: CHANGED_OTHER_FILES: ${{ steps.changed-files.outputs.other_all_changed_files }} CHANGED_PACKAGES: ${{ needs.setup.outputs.changed_packages }} CREW_BRANCH: ${{ inputs.branch || github.ref_name }} + DRAFT_PR: ${{ github.event.inputs.draft_pr }} GH_TOKEN: ${{ steps.get_workflow_token.outputs.token }} TIMESTAMP: ${{ needs.setup.outputs.timestamp }} i686_PACKAGES: ${{ needs.setup.outputs.i686_packages }} @@ -223,13 +229,18 @@ jobs: echo -e "CREW_REPO=https://github.com/chromebrew/chromebrew.git CREW_BRANCH=${{ env.BRANCH }} crew update \\" >> /tmp/pr.txt echo -e "&& yes | crew upgrade\n\`\`\`" >> /tmp/pr.txt cat /tmp/pr.txt + [[ $DRAFT_PR == 'true' ]] && export PR_DRAFT_FLAG='-d' PR_NUMBER=$(gh pr list -H ${CREW_BRANCH}| cut -f1) if [[ -z ${PR_NUMBER} ]]; then - PR_NUMBER=$(gh pr create --reviewer chromebrew/active --title "${{ env.BRANCH }} at ${TIMESTAMP}." -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev) + PR_NUMBER=$(gh pr create ${PR_DRAFT_FLAG} --reviewer chromebrew/active --title "${{ env.BRANCH }} at ${TIMESTAMP}." -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev) else gh pr edit -F /tmp/pr.txt fi # Draft PRs can not be set to automerge. - gh pr merge "${PR_NUMBER}" --auto || true + if [[ $DRAFT_PR == 'true' ]]; then + gh pr ready --undo || true + else + gh pr merge --auto || true + fi echo "PR_NUMBER is ${PR_NUMBER}" echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_ENV" diff --git a/.github/workflows/No-Compile-Needed.yml b/.github/workflows/No-Compile-Needed.yml index ed748eddc8..3a8edfad8e 100644 --- a/.github/workflows/No-Compile-Needed.yml +++ b/.github/workflows/No-Compile-Needed.yml @@ -3,6 +3,11 @@ name: No-Compile-Needed on: workflow_dispatch: inputs: + draft_pr: + description: "Create a Draft PR." + required: false + type: boolean + default: 'false' branch: description: "Branch of chromebrew/chromebrew to run on, if different from this branch." required: false @@ -357,6 +362,7 @@ jobs: CHANGED_MANIFEST_FILES: ${{ steps.changed-files.outputs.manifest_all_changed_files }} CHANGED_OTHER_FILES: ${{ steps.changed-files.outputs.other_all_changed_files }} CHANGED_PACKAGES: ${{ needs.setup.outputs.changed_packages }} + DRAFT_PR: ${{ github.event.inputs.draft_pr }} GH_TOKEN: ${{ steps.get_workflow_token.outputs.token }} TIMESTAMP: ${{ needs.setup.outputs.timestamp }} i686_PACKAGES: ${{ needs.setup.outputs.i686_packages }} @@ -398,8 +404,17 @@ jobs: echo -e "CREW_REPO=https://github.com/chromebrew/chromebrew.git CREW_BRANCH=${{ env.BRANCH }} crew update \\" >> /tmp/pr.txt echo -e "&& yes | crew upgrade\n\`\`\`" >> /tmp/pr.txt cat /tmp/pr.txt - PR_NUMBER=$(gh pr create --reviewer chromebrew/active --title "Build: ${{ env.BRANCH }} started at ${TIMESTAMP}." -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev) + [[ $DRAFT_PR == 'true' ]] && export PR_DRAFT_FLAG='-d' + if [[ -z ${PR_NUMBER} ]]; then + PR_NUMBER=$(gh pr create ${PR_DRAFT_FLAG} --reviewer chromebrew/active --title "Build: ${{ env.BRANCH }} started at ${TIMESTAMP}." -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev) + else + gh pr edit -F /tmp/pr.txt + fi # Draft PRs can not be set to automerge. - gh pr merge "${PR_NUMBER}" --auto || true + if [[ $DRAFT_PR == 'true' ]]; then + gh pr ready --undo || true + else + gh pr merge --auto || true + fi echo "PR_NUMBER is ${PR_NUMBER}" echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_ENV"