Skip to content

Commit 5f462ac

Browse files
committed
ci: Add fledge workflow
1 parent 511afc8 commit 5f462ac

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

.github/workflows/fledge.yaml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: fledge
2+
3+
on:
4+
# for manual triggers
5+
workflow_dispatch:
6+
inputs:
7+
pr:
8+
description: "Create PR"
9+
required: false
10+
type: boolean
11+
default: false
12+
# daily run
13+
schedule:
14+
- cron: "30 0 * * *"
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
check_fork:
22+
runs-on: ubuntu-latest
23+
outputs:
24+
is_forked: ${{ steps.check.outputs.is_forked }}
25+
steps:
26+
- name: Check if the repo is forked
27+
id: check
28+
env:
29+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: |
31+
is_forked=$(gh api repos/${{ github.repository }} | jq .fork)
32+
echo "is_forked=${is_forked}" >> $GITHUB_OUTPUT
33+
shell: bash
34+
35+
fledge:
36+
runs-on: ubuntu-latest
37+
needs: check_fork
38+
if: needs.check_fork.outputs.is_forked == 'false'
39+
permissions:
40+
contents: write
41+
pull-requests: write
42+
actions: write
43+
env:
44+
FLEDGE_GHA_CI: true
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Configure Git identity
51+
run: |
52+
env | sort
53+
git config --local user.name "$GITHUB_ACTOR"
54+
git config --local user.email "[email protected]"
55+
shell: bash
56+
57+
- name: Update apt
58+
run: |
59+
sudo apt-get update
60+
shell: bash
61+
62+
- uses: r-lib/actions/setup-r@v2
63+
with:
64+
install-r: false
65+
use-public-rspm: true
66+
67+
- uses: r-lib/actions/setup-r-dependencies@v2
68+
env:
69+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
70+
with:
71+
pak-version: devel
72+
packages: cynkra/fledge
73+
cache-version: fledge-1
74+
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+
85+
- name: Switch to branch if branch protection is enabled
86+
if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0
87+
run: |
88+
git checkout -b fledge
89+
git push -f -u origin HEAD
90+
shell: bash
91+
92+
- name: Bump version
93+
env:
94+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
95+
run: |
96+
check_default_branch <- ("${{ github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 }}" != "true")
97+
if (fledge::bump_version(which = "dev", no_change_behavior = "noop", check_default_branch = check_default_branch)) {
98+
fledge::finalize_version(push = TRUE)
99+
}
100+
shell: Rscript {0}
101+
102+
- name: Create and merge PR if branch protection is enabled
103+
if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0
104+
env:
105+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
run: |
107+
set -x
108+
gh pr create --base main --head fledge --fill-first
109+
gh workflow run rcc -f ref=$(git rev-parse HEAD)
110+
gh pr merge --merge --auto
111+
shell: bash
112+
113+
- name: Check release
114+
env:
115+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
116+
run: |
117+
fledge:::release_after_cran_built_binaries()
118+
shell: Rscript {0}

0 commit comments

Comments
 (0)