Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions .github/workflows/on-pr-bug-linked.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Inherit label and milestone from linked issue

# [impl->req~ci.port-to-other-branch.label-driven-ports~1]
# [impl->adr~single-stable-branch-with-automatic-ports~1]
# Adds "dev: into-stable" when a PR into main links an issue of type "bug" for the
# Adds "dev: send-to-black-forest" when a PR into main links an issue of type "bug" for the
# first time: at creation, or when an edit of the body adds a new issue link. A push never
# triggers this, and a link that was already there never counts again - so a maintainer's
# decision to remove (or add) the label by hand sticks.
Expand All @@ -28,7 +28,7 @@ jobs:
(github.event.action == 'opened' || github.event.changes.body)
runs-on: ubuntu-slim
steps:
- name: 'Add "dev: into-stable" for a newly linked bug'
- name: 'Add "dev: send-to-black-forest" for a newly linked bug'
env:
# PAT: a label added with GITHUB_TOKEN would not trigger the "Would merge into the other branch" check
GH_TOKEN: ${{ secrets.GH_TOKEN_JABREF_MACHINE_PR_APPROVE }}
Expand Down Expand Up @@ -68,8 +68,8 @@ jobs:
# GitHub stores the type name in lower case ("bug") while the issue template writes "Bug"
if [ "$labeled" = false ] && [ "${type,,}" = "bug" ]; then
# `gh pr edit` queries fields that need the read:org scope, which the token lacks
gh api "repos/JabRef/jabref/issues/$PR_NUMBER/labels" -f "labels[]=dev: into-stable" > /dev/null
echo "Added \`dev: into-stable\`" >> "$GITHUB_STEP_SUMMARY"
gh api "repos/JabRef/jabref/issues/$PR_NUMBER/labels" -f "labels[]=dev: send-to-black-forest" > /dev/null
echo "Added \`dev: send-to-black-forest\`" >> "$GITHUB_STEP_SUMMARY"
labeled=true
fi
done
85 changes: 45 additions & 40 deletions .github/workflows/port-to-other-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Port to other branch

# [impl->req~ci.port-to-other-branch.label-driven-ports~1]
# [impl->adr~single-stable-branch-with-automatic-ports~1]
# Keeps "main" and "stable" in sync: a PR into main labeled "dev: into-stable" is
# ported to stable once merged; a PR into stable is always ported to main once merged.
# Keeps "main" of JabRef/jabref and "black-forest" of JabRef/jabref-black-forest in sync: a PR into
# main labeled "dev: send-to-black-forest" is ported to black-forest once merged; a PR into
# black-forest is always ported to main once merged. The same file lives on both branches; the
# repository it runs in decides the direction.
# Before the merge, the port is simulated, so a conflict shows up as a failed check on the PR.
#
# pull_request_target: the port needs a push-capable token, and the PR may come from a fork.
Expand All @@ -22,11 +24,17 @@ concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_ref }}-${{ github.event.action == 'closed' && 'port' || 'check' }}"
cancel-in-progress: ${{ github.event.action != 'closed' }}

env:
# The other side of the port; the owner is always JabRef
TARGET_REPO: ${{ github.repository == 'JabRef/jabref' && 'jabref-black-forest' || 'jabref' }}
TARGET: ${{ github.repository == 'JabRef/jabref' && 'black-forest' || 'main' }}
SOURCE: ${{ github.repository == 'JabRef/jabref' && 'main' || 'black-forest' }}

jobs:
check:
# Fixed name: it is listed as a required status check, whichever branch is the target
name: Would merge into the other branch
if: github.repository == 'JabRef/jabref' && github.event.action != 'closed'
if: (github.repository == 'JabRef/jabref' || github.repository == 'JabRef/jabref-black-forest') && github.event.action != 'closed'
runs-on: ubuntu-slim
permissions:
contents: read
Expand All @@ -49,27 +57,25 @@ jobs:
PR_NUMBER=$(sed -E 's#.*/pr-([0-9]+)-.*#\1#' <<< "$QUEUE_REF")
fi
gh pr view "$PR_NUMBER" --json state,baseRefName,headRefName,headRepositoryOwner,headRepository,labels \
--jq '"state=\(.state|@sh)\nbase=\(.baseRefName|@sh)\nhead_repo=\("\(.headRepositoryOwner.login)/\(.headRepository.name)"|@sh)\nhead_ref=\(.headRefName|@sh)\ninto_stable=\(any(.labels[]; .name == "dev: into-stable"))"' > pr.env
--jq '"state=\(.state|@sh)\nbase=\(.baseRefName|@sh)\nhead_repo=\("\(.headRepositoryOwner.login)/\(.headRepository.name)"|@sh)\nhead_ref=\(.headRefName|@sh)\nlabeled=\(any(.labels[]; .name == "dev: send-to-black-forest"))"' > pr.env
# shellcheck disable=SC1091
source pr.env
port=false
# A port PR (head "port-*" in this repository - a fork branch of that name is just a branch)
# carries a change the other branch already has - never port it back.
if [ "$state" = "OPEN" ] && ! { [ "$head_repo" = "JabRef/jabref" ] && [[ "$head_ref" == port-* ]]; }; then
if [ "$base" = "stable" ] || { [ "$base" = "main" ] && [ "$into_stable" = "true" ]; }; then
if [ "$state" = "OPEN" ] && [ "$base" = "$SOURCE" ] && ! { [ "$head_repo" = "$GH_REPO" ] && [[ "$head_ref" == port-* ]]; }; then
# Into main, the label decides; everything merged into black-forest goes back to main
if [ "$base" != "main" ] || [ "$labeled" = "true" ]; then
port=true
fi
fi
target=main
[ "$base" = "main" ] && target=stable
{
echo "number=$PR_NUMBER"
echo "base=$base"
echo "target=$target"
echo "port=$port"
} >> "$GITHUB_OUTPUT"
if [ "$port" != "true" ]; then
echo "Nothing to check for #$PR_NUMBER: not a port candidate (base \`$base\`, label \`dev: into-stable\` $([ "$into_stable" = true ] && echo present || echo absent))" >> "$GITHUB_STEP_SUMMARY"
echo "Nothing to check for #$PR_NUMBER: not a port candidate (base \`$base\`, label \`dev: send-to-black-forest\` $([ "$labeled" = true ] && echo present || echo absent))" >> "$GITHUB_STEP_SUMMARY"
fi
# The base branch tip, explicitly: on merge_group the event's ref is the queued commit, which
# contains the PR - the composite action and the merge driver must come from the trusted base.
Expand All @@ -87,7 +93,6 @@ jobs:
env:
PR_NUMBER: ${{ steps.pr.outputs.number }}
BASE_REF: ${{ steps.pr.outputs.base }}
TARGET: ${{ steps.pr.outputs.target }}
HEAD_SHA: ${{ github.event.merge_group.head_sha || github.event.pull_request.head.sha }}
QUEUE_REF: ${{ github.event.merge_group.head_ref }}
GIT_AUTHOR_NAME: github-actions[bot]
Expand All @@ -96,28 +101,31 @@ jobs:
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
run: |
set -euo pipefail
if ! git ls-remote --exit-code --heads origin "$TARGET" > /dev/null; then
echo "Branch \`$TARGET\` does not exist yet - nothing to check" >> "$GITHUB_STEP_SUMMARY"
target_url="https://github.com/JabRef/$TARGET_REPO.git"
if ! git ls-remote --exit-code --heads "$target_url" "$TARGET" > /dev/null; then
echo "Branch \`$TARGET\` does not exist yet in JabRef/$TARGET_REPO - nothing to check" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
git fetch --no-tags "$target_url" "$TARGET"
target=$(git rev-parse FETCH_HEAD)
if [ -n "$QUEUE_REF" ]; then
# The queued commit merges this PR onto the previous queue entry (or the base tip), so its
# first parent bounds exactly this PR's change even when several PRs are batched.
git fetch --no-tags origin "$TARGET" "$QUEUE_REF"
git fetch --no-tags origin "$QUEUE_REF"
parent=$(git rev-parse "$HEAD_SHA^1")
else
git fetch --no-tags origin "$TARGET" "+refs/pull/$PR_NUMBER/head:refs/remotes/pr/$PR_NUMBER"
git fetch --no-tags origin "+refs/pull/$PR_NUMBER/head:refs/remotes/pr/$PR_NUMBER"
parent=$(git merge-base "origin/$BASE_REF" "$HEAD_SHA")
fi
# The PR as it lands: one commit carrying the PR's whole change (squash merge)
squash=$(git commit-tree "$HEAD_SHA^{tree}" -p "$parent" -m "Squash of #$PR_NUMBER")
git checkout -q "origin/$TARGET"
git checkout -q "$target"
if git cherry-pick --no-commit "$squash"; then
echo "✅ PR #$PR_NUMBER applies cleanly to \`$TARGET\`" >> "$GITHUB_STEP_SUMMARY"
echo "✅ PR #$PR_NUMBER applies cleanly to \`$TARGET\` of JabRef/$TARGET_REPO" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
{
echo "❌ PR #$PR_NUMBER conflicts with \`$TARGET\` in:"
echo "❌ PR #$PR_NUMBER conflicts with \`$TARGET\` of JabRef/$TARGET_REPO in:"
echo
git diff --name-only --diff-filter=U | sed 's/^/- `/; s/$/`/'
echo
Expand All @@ -126,22 +134,19 @@ jobs:
exit 1

port:
name: Port to ${{ github.event.pull_request.base.ref == 'stable' && 'main' || 'stable' }}
name: Port to ${{ github.repository == 'JabRef/jabref' && 'black-forest' || 'main' }}
permissions:
contents: write
pull-requests: write
contents: read
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved
env:
TARGET: ${{ github.event.pull_request.base.ref == 'stable' && 'main' || 'stable' }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GH_REPO: ${{ github.repository }}
if: >
github.repository == 'JabRef/jabref' &&
(github.repository == 'JabRef/jabref' || github.repository == 'JabRef/jabref-black-forest') &&
github.event.action == 'closed' &&
github.event.pull_request.merged &&
!(github.event.pull_request.head.repo.full_name == 'JabRef/jabref' && startsWith(github.event.pull_request.head.ref, 'port-')) &&
!(github.event.pull_request.head.repo.full_name == github.repository && startsWith(github.event.pull_request.head.ref, 'port-')) &&
(
github.event.pull_request.base.ref == 'stable' ||
(github.event.pull_request.base.ref == 'main' && contains(github.event.pull_request.labels.*.name, 'dev: into-stable'))
(github.repository == 'JabRef/jabref-black-forest' && github.event.pull_request.base.ref == 'black-forest') ||
(github.repository == 'JabRef/jabref' && github.event.pull_request.base.ref == 'main' && contains(github.event.pull_request.labels.*.name, 'dev: send-to-black-forest'))
)
runs-on: ubuntu-slim
steps:
Expand All @@ -151,57 +156,57 @@ jobs:
submodules: 'false'
show-progress: 'false'
- uses: ./.github/actions/changelog-cherry-pick-driver
- name: Check that ${{ env.TARGET }} exists
- name: Check that ${{ env.TARGET }} exists in JabRef/${{ env.TARGET_REPO }}
id: target
run: |
if git ls-remote --exit-code --heads origin "$TARGET" > /dev/null; then
if git ls-remote --exit-code --heads "https://github.com/JabRef/$TARGET_REPO.git" "$TARGET" > /dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "Branch \`$TARGET\` does not exist yet - nothing to port" >> "$GITHUB_STEP_SUMMARY"
echo "Branch \`$TARGET\` does not exist yet in JabRef/$TARGET_REPO - nothing to port" >> "$GITHUB_STEP_SUMMARY"
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Cherry-pick into a port PR
if: steps.target.outputs.exists == 'true'
id: port
uses: korthout/backport-action@8560fb503c275d433c56f05a2f64850093baa9f7 # v4.7.0
with:
# A PAT, so that CI runs on the port PR; the PR and its comment are authored by jabref-machine
# jabref-machine's PAT: it has to push to the other repository, and CI runs on the port PR
github_token: ${{ secrets.GH_TOKEN_JABREF_MACHINE_PR_APPROVE }}
target_branches: ${{ env.TARGET }}
# The target comes from the base branch and the label above, not from "backport <branch>" labels
label_pattern: ^()$
branch_name: port-${pull_number}-to-${target_branch}
pull_title: "[Port to ${target_branch}] ${pull_title}"
pull_description: |
Port of #${pull_number} to `${target_branch}`, see [Branching strategy](https://devdocs.jabref.org/contributing.html#branching-strategy).
Port of ${{ github.repository }}#${pull_number} to `${target_branch}`, see [Branching strategy](https://devdocs.jabref.org/contributing.html#branching-strategy).

If this PR is a draft, the cherry-pick conflicted: the conflicting files are committed with Git's conflict markers left in. Resolve the markers locally, push, and mark the PR ready.
# A PR branch usually contains merges from main; the squash commit is what gets ported
merge_commits: skip
experimental: >
{"conflict_resolution": "draft_commit_conflicts"}
{"conflict_resolution": "draft_commit_conflicts", "downstream_repo": "${{ env.TARGET_REPO }}"}
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved
- name: Auto-merge a clean port
if: steps.port.outputs.was_successful == 'true'
env:
# jabref-machine's token: "On PR labeled" only fires for labels added with a PAT
# The port PR lives in the other repository, where only the PAT has rights
GH_TOKEN: ${{ secrets.GH_TOKEN_JABREF_MACHINE_PR_APPROVE }}
APPROVE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: JabRef/${{ env.TARGET_REPO }}
CREATED: ${{ steps.port.outputs.created_pull_numbers }}
run: |
for pr in $CREATED; do
# jabref-machine cannot approve its own PR; github-actions[bot] does it instead
GH_TOKEN="$APPROVE_TOKEN" gh pr review --approve "$pr"
gh pr edit "$pr" --add-label automerge
echo "✅ Port PR #$pr opened with auto-merge" >> "$GITHUB_STEP_SUMMARY"
gh pr merge --auto --squash "$pr"
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved
echo "✅ Port PR $GH_REPO#$pr opened with auto-merge" >> "$GITHUB_STEP_SUMMARY"
done
- name: Report a conflicting port
if: steps.target.outputs.exists == 'true' && steps.port.outputs.was_successful != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN_JABREF_MACHINE_PR_APPROVE }}
GH_REPO: JabRef/${{ env.TARGET_REPO }}
CREATED: ${{ steps.port.outputs.created_pull_numbers }}
run: |
for pr in $CREATED; do
gh pr edit "$pr" --add-label "status: changes-required"
done
echo "❌ Port of #$PR_NUMBER to \`$TARGET\` conflicts - resolve it in the draft port PR ${CREATED:+#$CREATED}" | tee -a "$GITHUB_STEP_SUMMARY"
echo "❌ Port of #$PR_NUMBER to \`$TARGET\` of $GH_REPO conflicts - resolve it in the draft port PR ${CREATED:+$GH_REPO#$CREATED}" | tee -a "$GITHUB_STEP_SUMMARY"
exit 1
2 changes: 1 addition & 1 deletion .jbang/ChangelogCherryPickMergeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//JAVA 25+
//DEPS org.jspecify:jspecify:1.0.1

/// Git merge driver for `CHANGELOG.md` when a change is ported between `main` and `stable`
/// Git merge driver for `CHANGELOG.md` when a change is ported between `main` and `black-forest`
/// (see `.github/workflows/port-to-other-branch.yml`).
///
/// [impl->adr~single-stable-branch-with-automatic-ports~1]
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@

#### Testing / JUnit

- Name test classes `...Test` (singular), not `...Tests` — e.g. `JabSrvArchitectureTest`, not `JabSrvArchitectureTests`. This holds even for ArchUnit classes that bundle several `@ArchTest` rules.

Check failure on line 280 in AGENTS.md

View workflow job for this annotation

GitHub Actions / Spellling

TextLint [write-good]

"several" is a weasel word | 280:171
- In JabRef, we don't use `@DisplayName`, we typically just write method name as is. The method name itself should be comprehensive enough.
- Instead of `Files.createTempDirectory` `@TempDir` JUnit5 annotation should be used.
- If `@TempDir` is used, there is no need to clean it up
Expand Down Expand Up @@ -505,7 +505,7 @@

### Branches

- `main` is the development branch; pull requests target it. `stable` is the last release plus ported fixes; CI labels a PR `dev: into-stable` when it links a bug issue (maintainers may add or remove the label by hand) and ports it after the merge. Never add that label to a port PR (`port-<number>-to-<branch>`). See [docs/contributing.md](docs/contributing.md#branching-strategy).
- `main` is the development branch; pull requests target it. `black-forest` in JabRef/jabref-black-forest is the last release plus ported fixes; CI labels a PR `dev: send-to-black-forest` when it links a bug issue (maintainers may add or remove the label by hand) and ports it after the merge. Never add that label to a port PR (`port-<number>-to-<branch>`). See [docs/contributing.md](docs/contributing.md#branching-strategy).

### Commits

Expand Down
Loading
Loading