Skip to content

Add support for book front covers #1506

Add support for book front covers

Add support for book front covers #1506

name: On PR opened/updated (check)
on:
# _target is required
pull_request_target:
# default: opened, synchronize, reopened
workflow_dispatch:
inputs:
pr_number:
description: 'PR number'
required: true
jobs:
conflicts_with_target:
if: github.repository == 'JabRef/jabref'
name: Conflicts with target branch
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
show-progress: 'false'
- name: Check PR mergeability
id: check_mergeable
run: |
set -ex
echo "Checking PR [#$PR_NUMBER](https://github.com/JabRef/jabref/pull/$PR_NUMBER)" >> $GITHUB_STEP_SUMMARY
# Retry a few times until mergeable != UNKNOWN
# See https://github.com/cli/cli/discussions/8020#discussioncomment-7057040 for details
for i in 1 2 3 4 5; do
MERGEABLE=$(gh pr view "$PR_NUMBER" --json mergeable --template '{{.mergeable}}')
echo "Attempt $i: $MERGEABLE"
if [ "$MERGEABLE" != "UNKNOWN" ]; then
break
fi
sleep 5
done
echo "Result: $MERGEABLE" >> $GITHUB_STEP_SUMMARY
if [ "$MERGEABLE" == "CONFLICTING" ]; then
echo "❌ Merge conflicts"
echo "❌ Merge conflicts" >> $GITHUB_STEP_SUMMARY
gh issue edit $PR_NUMBER --remove-label "status: ready-for-review" --add-label "status: changes-required"
# "workflow dispatch" does not trigger subsequent "on completion" runs.
# Therefore, we emulate ghprcomment here
if [ "$EVENT" = "workflow_dispatch" ]; then
HAS_CONFLICT_COMMENT=$(
gh api graphql -f query="
query {
repository(owner: \"JabRef\", name: \"JabRef\") {
pullRequest(number: $PR_NUMBER) {
comments(last: 20) {
nodes { body }
}
}
}
}
" \
| jq -r '.data.repository.pullRequest.comments.nodes[].body' \
| grep -q "Conflicts with target branch" \
&& echo "true" \
|| echo "false"
)
if [ -n "$HAS_CONFLICT_COMMENT" ]; then
echo "Already commented about conflicts."
# When triggered by another workflow, success is also if there is a merge conflict
exit 0;
fi
echo "Commenting on PR..."
cat > body.txt <<EOF
Your pull request conflicts with the target branch.
Please [merge `upstream/main`](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork#syncing-a-fork-branch-from-the-command-line) with your code. For a step-by-step guide to resolve merge conflicts, see <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line>.
<!-- ghprcomment
On PR opened/updated (check)
Conflicts with target branch
-->
EOF
gh issue comment "$PR_NUMBER" --body-file body.txt
echo "Commented on PR" >> $GITHUB_STEP_SUMMARY
# When triggered by another workflow, success is also if there is a merge conflict
exit 0;
fi;
exit 1
fi
echo "✅ No merge conflicts"
echo "✅ No merge conflicts" >> $GITHUB_STEP_SUMMARY
env:
EVENT: ${{ github.event_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}