Skip to content

Commit 85a6279

Browse files
committed
ci: Correctly detect branch protection
1 parent 4e4e83c commit 85a6279

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

.github/workflows/fledge.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@ jobs:
7272
packages: cynkra/fledge
7373
cache-version: fledge-1
7474

75+
- name: Count rulesets
76+
# Assume that branch is protected if ruleset exists
77+
id: rulesets
78+
env:
79+
GH_TOKEN: ${{ github.token }}
80+
run: |
81+
n_rulesets=$(gh api repos/${{ github.repository }}/rulesets -q length)
82+
echo "count=${n_rulesets}" >> $GITHUB_OUTPUT
83+
shell: bash
84+
7585
- name: Switch to branch if branch protection is enabled
76-
if: github.ref_protected == 'true' || inputs.pr == 'true'
86+
if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0
7787
run: |
7888
git checkout -b fledge
7989
git push -f -u origin HEAD
@@ -83,14 +93,14 @@ jobs:
8393
env:
8494
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
8595
run: |
86-
check_default_branch <- ("${{ github.ref_protected == 'true' || inputs.pr == 'true' }}" != "true")
96+
check_default_branch <- ("${{ github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 }}" != "true")
8797
if (fledge::bump_version(which = "dev", no_change_behavior = "noop", check_default_branch = check_default_branch)) {
8898
fledge::finalize_version(push = TRUE)
8999
}
90100
shell: Rscript {0}
91101

92102
- name: Create and merge PR if branch protection is enabled
93-
if: github.ref_protected == 'true' || inputs.pr == 'true'
103+
if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0
94104
env:
95105
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96106
run: |

0 commit comments

Comments
 (0)