From 6d612acd806861d7633cc76a214062a8f44b6b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Thu, 21 Nov 2024 06:44:07 +0100 Subject: [PATCH] ci: Correctly detect branch protection (#678) --- .github/workflows/fledge.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/fledge.yaml b/.github/workflows/fledge.yaml index 02e9101f4..b197fb35a 100644 --- a/.github/workflows/fledge.yaml +++ b/.github/workflows/fledge.yaml @@ -72,8 +72,18 @@ jobs: packages: cynkra/fledge cache-version: fledge-1 + - name: Count rulesets + # Assume that branch is protected if ruleset exists + id: rulesets + env: + GH_TOKEN: ${{ github.token }} + run: | + n_rulesets=$(gh api repos/${{ github.repository }}/rulesets -q length) + echo "count=${n_rulesets}" >> $GITHUB_OUTPUT + shell: bash + - name: Switch to branch if branch protection is enabled - if: github.ref_protected == 'true' || inputs.pr == 'true' + if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 run: | git checkout -b fledge git push -f -u origin HEAD @@ -83,14 +93,14 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} run: | - check_default_branch <- ("${{ github.ref_protected == 'true' || inputs.pr == 'true' }}" != "true") + check_default_branch <- ("${{ github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 }}" != "true") if (fledge::bump_version(which = "dev", no_change_behavior = "noop", check_default_branch = check_default_branch)) { fledge::finalize_version(push = TRUE) } shell: Rscript {0} - name: Create and merge PR if branch protection is enabled - if: github.ref_protected == 'true' || inputs.pr == 'true' + if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: |