Skip to content

Commit

Permalink
ci: Correctly detect branch protection (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Nov 21, 2024
1 parent 6bb1310 commit 6d612ac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/fledge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down

0 comments on commit 6d612ac

Please sign in to comment.