|
| 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 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + - master |
| 16 | + paths: |
| 17 | + - ".github/workflows/fledge.yaml" |
| 18 | + # daily run |
| 19 | + schedule: |
| 20 | + - cron: "30 0 * * *" |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }} |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + check_news: |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + outputs: |
| 30 | + should_run: ${{ steps.check.outputs.should_run }} |
| 31 | + steps: |
| 32 | + # Fetch NEWS.md via API instead of full checkout for speed |
| 33 | + - name: Check if not forked and NEWS.md mentions fledge |
| 34 | + id: check |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + run: | |
| 38 | + set -euxo pipefail |
| 39 | +
|
| 40 | + # Check if repo is not forked |
| 41 | + is_forked=$(gh api repos/${{ github.repository }} | jq .fork) |
| 42 | + if [ "$is_forked" == "true" ]; then |
| 43 | + echo "Repository is a fork. Skipping fledge workflow." |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + # Special case: duckdb and igraph |
| 48 | + if [[ "${{ github.repository }}" == 'krlmlr/duckdb-r' ]]; then |
| 49 | + echo "Repository is krlmlr/duckdb-r. Skipping fledge workflow." |
| 50 | + exit 0 |
| 51 | + fi |
| 52 | +
|
| 53 | + if [[ "${{ github.repository }}" == 'krlmlr/rigraph' ]]; then |
| 54 | + echo "Repository is krlmlr/rigraph. Skipping fledge workflow." |
| 55 | + exit 0 |
| 56 | + fi |
| 57 | +
|
| 58 | + # Fetch NEWS.md content via API without full checkout |
| 59 | + gh api repos/${{ github.repository }}/contents/NEWS.md --jq .content 2>/dev/null | base64 -d > /tmp/news.md || true |
| 60 | +
|
| 61 | + if [ ! -s /tmp/news.md ]; then |
| 62 | + echo "NEWS.md not found. Skipping fledge workflow." |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | +
|
| 66 | + # Read first line of NEWS.md and check if it mentions fledge |
| 67 | + news_content=$(head -n 1 /tmp/news.md) |
| 68 | + if ! [[ "$news_content" == *"fledge"* ]]; then |
| 69 | + echo "NEWS.md does not mention fledge. Skipping fledge workflow." |
| 70 | + exit 0 |
| 71 | + fi |
| 72 | +
|
| 73 | + echo "should_run=true" >> $GITHUB_OUTPUT |
| 74 | + shell: bash |
| 75 | + |
| 76 | + fledge: |
| 77 | + runs-on: ubuntu-24.04 |
| 78 | + needs: check_news |
| 79 | + if: needs.check_news.outputs.should_run == 'true' |
| 80 | + permissions: |
| 81 | + contents: write |
| 82 | + pull-requests: write |
| 83 | + actions: write |
| 84 | + env: |
| 85 | + FLEDGE_GHA_CI: true |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v6 |
| 88 | + with: |
| 89 | + fetch-depth: 0 |
| 90 | + fetch-tags: true |
| 91 | + |
| 92 | + - uses: ./.github/workflows/git-identity |
| 93 | + |
| 94 | + - name: Update apt |
| 95 | + run: | |
| 96 | + sudo apt-get update |
| 97 | + shell: bash |
| 98 | + |
| 99 | + - uses: ./.github/workflows/install |
| 100 | + with: |
| 101 | + pak-version: devel |
| 102 | + packages: cynkra/fledge |
| 103 | + cache-version: fledge-1 |
| 104 | + |
| 105 | + - name: Count rulesets |
| 106 | + # Assume that branch is protected if ruleset exists |
| 107 | + id: rulesets |
| 108 | + env: |
| 109 | + GH_TOKEN: ${{ github.token }} |
| 110 | + run: | |
| 111 | + n_rulesets=$(gh api repos/${{ github.repository }}/rulesets -q length) |
| 112 | + echo "count=${n_rulesets}" >> $GITHUB_OUTPUT |
| 113 | + shell: bash |
| 114 | + |
| 115 | + - name: Switch to branch if branch protection is enabled |
| 116 | + if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 |
| 117 | + run: | |
| 118 | + git checkout -b fledge |
| 119 | + git push -f -u origin HEAD |
| 120 | + shell: bash |
| 121 | + |
| 122 | + - name: Bump version |
| 123 | + env: |
| 124 | + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + run: | |
| 126 | + check_default_branch <- ("${{ github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 }}" != "true") |
| 127 | + if (fledge::bump_version(which = "dev", no_change_behavior = "noop", check_default_branch = check_default_branch)) { |
| 128 | + fledge::finalize_version(push = TRUE) |
| 129 | + } |
| 130 | + shell: Rscript {0} |
| 131 | + |
| 132 | + - name: Create and merge PR if branch protection is enabled |
| 133 | + if: github.ref_protected == 'true' || inputs.pr == 'true' || steps.rulesets.outputs.count > 0 |
| 134 | + env: |
| 135 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + run: | |
| 137 | + set -ex |
| 138 | + if [ -n "$(git diff main --numstat)" ]; then |
| 139 | + gh pr create --base main --head fledge --fill-first |
| 140 | + gh workflow run rcc -f ref=$(git rev-parse HEAD) |
| 141 | + gh pr merge --squash --auto |
| 142 | + else |
| 143 | + echo "No changes." |
| 144 | + fi |
| 145 | + shell: bash |
| 146 | + |
| 147 | + - name: Check release |
| 148 | + env: |
| 149 | + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 150 | + run: | |
| 151 | + fledge:::release_after_cran_built_binaries() |
| 152 | + shell: Rscript {0} |
0 commit comments