Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Correctly detect branch protection #130

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/dep-suggests-matrix.json

This file was deleted.

1 change: 0 additions & 1 deletion .github/versions-matrix.json

This file was deleted.

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