Skip to content

Commit f526a74

Browse files
committed
Use PRs when importing engine sources
This change brings in the logic for PR create/update on engine sources import the same way how it is done for ODBC in duckdb#96.
1 parent 13b39f8 commit f526a74

File tree

2 files changed

+145
-22
lines changed

2 files changed

+145
-22
lines changed

.github/workflows/Java.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,39 @@ jobs:
312312
- name: Test
313313
shell: bash
314314
run: (cd jdbccts && make DUCKDB_JAR=../build/release/duckdb_jdbc.jar test)
315+
316+
java-merge-vendoring-pr:
317+
name: Merge vendoring PR
318+
if: ${{ github.repository == 'duckdb/duckdb-java' && github.event_name == 'pull_request' && github.head_ref == format('vendoring-{0}', github.ref_name) }}
319+
needs:
320+
- java-linux-aarch64
321+
- java-linux-amd64
322+
- java-windows-amd64
323+
- java-osx-universal
324+
runs-on: ubuntu-latest
325+
steps:
326+
- uses: actions/checkout@v4
327+
with:
328+
fetch-depth: 0
329+
330+
- name: Merge vendoring PR
331+
id: merge_vendoring_pr
332+
env:
333+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
334+
run: |
335+
# echo "Merging PR number: ${{ github.event.pull_request.number }} with message: ${{ github.event.pull_request.title }}"
336+
gh pr merge vendoring-${{ github.ref_name }} \
337+
--rebase \
338+
--subject "${{ github.event.pull_request.title }}" \
339+
--body ""
340+
341+
- name: Update vendoring branch
342+
id: update_vendoring_branch
343+
if: ${{ steps.merge_vendoring_pr.outcome == 'success' }}
344+
run: |
345+
# Delete vendoring-${{ github.ref_name }} branch and re-create it for future PRs
346+
git push --delete origin vendoring-${{ github.ref_name }}
347+
git checkout --track origin/main
348+
git pull --ff-only
349+
git branch vendoring-${{ github.ref_name }}
350+
git push origin vendoring-${{ github.ref_name }}

.github/workflows/Vendor.yml

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,141 @@ on:
1717

1818
jobs:
1919
vendor:
20-
runs-on: ubuntu-latest
21-
outputs:
22-
did_vendor: ${{ steps.vendor.outputs.vendor }}
23-
2420
name: "Update Vendored Sources"
25-
if: github.repository == 'duckdb/duckdb-java'
21+
if: ${{ github.repository == 'duckdb/duckdb-java' }}
22+
runs-on: ubuntu-latest
2623

2724
steps:
28-
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
id: setup_python
28+
with:
29+
python-version: '3.12'
30+
31+
- name: Checkout
32+
id: checkout
33+
uses: actions/checkout@v4
2934
with:
3035
fetch-depth: 0
31-
token: ${{ secrets.PAT_TOKEN }}
3236

33-
- uses: actions/checkout@v4
37+
- name: Checkout engine
38+
uses: actions/checkout@v4
39+
id: checkout_engine
3440
with:
3541
repository: duckdb/duckdb
3642
path: .git/duckdb
3743
fetch-depth: 0
3844

39-
- name: Get commit SHA
45+
- name: Checkout engine rev
46+
id: checkout_engine_rev
4047
if: ${{ inputs.duckdb-sha != '' }}
48+
working-directory: .git/duckdb
4149
run: |
42-
cd .git/duckdb && git checkout ${{ inputs.duckdb-sha }}
43-
44-
- uses: actions/setup-python@v5
45-
with:
46-
python-version: '3.12'
50+
echo "Checking out engine ref: ${{ inputs.duckdb-sha }} on branch: ${{ github.ref_name }}"
51+
git checkout ${{ inputs.duckdb-sha }}
4752
4853
- name: Vendor sources
54+
if: ${{ steps.checkout_engine_rev.outcome == 'success' }}
4955
id: vendor
5056
run: |
51-
export REV=$(cd .git/duckdb && git rev-parse --short HEAD && cd ../..)
52-
echo "Updating vendored DuckDB sources to $REV"
57+
REV=$(cd .git/duckdb && git rev-parse --short HEAD && cd ../..)
58+
echo "Updating vendored DuckDB sources to ${REV}"
5359
git config --global user.email "[email protected]"
5460
git config --global user.name "DuckDB Labs GitHub Bot"
61+
# Vendoring branch must exist, it may or may not already have
62+
# a pending PR on it, we are rebasing it anyway
63+
git checkout vendoring-${{ github.ref_name }}
64+
git rebase ${{ github.ref_name }}
65+
# Call the vendoring script in the engine
5566
git rm -rf src/duckdb
5667
python vendor.py --duckdb .git/duckdb
5768
git add src/duckdb CMakeLists.txt
69+
# Clean up
5870
rm -rf .git/duckdb
59-
git commit -m "Update vendored DuckDB sources to $REV"
60-
git push --dry-run
71+
# Export vendor revision for use in later steps
72+
echo "vendor_rev=${REV}" >> "${GITHUB_OUTPUT}"
73+
74+
- name: Commit and push the changes
75+
id: commit_and_push
76+
if: ${{ steps.vendor.outcome == 'success' }}
77+
run: |
78+
MSG="Update vendored DuckDB sources to ${{ steps.vendor.outputs.vendor_rev }}"
79+
git commit -m "${MSG}"
6180
# Check if ahead of upstream branch
6281
# If yes, set a step output
63-
if [ $(git rev-list HEAD...origin/main --count) -gt 0 ]; then
82+
git push -f --dry-run origin vendoring-${{ github.ref_name }}
83+
if [ $(git rev-list HEAD...origin/${{ github.ref_name }} --count) -gt 0 ]; then
84+
git push -f origin vendoring-${{ github.ref_name }}
6485
# Avoid set-output, it's deprecated
65-
echo "vendor=ok" >> "$GITHUB_OUTPUT"
86+
echo "push_performed=true" >> "${GITHUB_OUTPUT}"
87+
echo "commit_msg=${MSG}" >> "${GITHUB_OUTPUT}"
88+
fi
89+
90+
- name: Check PR exists
91+
id: check_pr_exists
92+
if: ${{ steps.commit_and_push.outcome == 'success' }}
93+
env:
94+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
run: |
96+
PR_NUM=$(gh pr list --head vendoring-${{ github.ref_name }} --json number --jq '.[].number')
97+
if [ -z "${PR_NUM}" ]; then
98+
echo "No PR exists for branch vendoring-${{ github.ref_name }}"
99+
echo "pr_exists=false" >> "${GITHUB_OUTPUT}"
100+
else
101+
echo "PR found for branch vendoring-${{ github.ref_name }}, number: ${PR_NUM}"
102+
echo "pr_exists=true" >> "${GITHUB_OUTPUT}"
103+
echo "pr_num=${PR_NUM}" >> "${GITHUB_OUTPUT}"
66104
fi
67105
68-
- if: steps.vendor.outputs.vendor != '' && github.event_name != 'pull_request'
106+
- name: Prepare PR message
107+
id: prepare_pr_message
108+
if: ${{ steps.check_pr_exists.outcome == 'success' }}
109+
run: |
110+
DATE="$(date +"%Y-%m-%d %H:%M:%S")"
111+
CHANGE_LABEL="duckdb/duckdb#${{ steps.vendor.outputs.vendor_rev }}"
112+
CHANGE_URL="https://github.com/duckdb/duckdb/commit/${{ steps.vendor.outputs.vendor_rev }}"
113+
MSG=" - [${CHANGE_LABEL}](${CHANGE_URL}) imported at ${DATE}"
114+
echo "PR message: ${MSG}"
115+
echo "pr_msg=${MSG}" >> "${GITHUB_OUTPUT}"
116+
117+
- name: Create PR
118+
id: create_pr
119+
if: ${{ steps.prepare_pr_message.outcome == 'success' && steps.check_pr_exists.outputs.pr_exists == 'false' }}
120+
env:
121+
# We cannot use default workflow's GITHUB_TOKEN here, because
122+
# it is restricted to not trigger 'pull_request' event that
123+
# we need to dispatch the testing workflow.
124+
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
125+
run: |
126+
# Write multiline PR msg to a body.txt file
127+
echo "Changes:" > body.txt
128+
echo "${{ steps.prepare_pr_message.outputs.pr_msg }}" >> body.txt
129+
# Remove empty lines
130+
sed -i '/^$/d' body.txt
131+
gh pr create \
132+
--head "vendoring-${{ github.ref_name }}" \
133+
--base "${{ github.ref_name }}" \
134+
--title "${{ steps.commit_and_push.outputs.commit_msg }}" \
135+
--body-file body.txt
136+
137+
- name: Update PR
138+
id: update_pr
139+
if: ${{ steps.prepare_pr_message.outcome == 'success' && steps.check_pr_exists.outputs.pr_exists == 'true' }}
140+
env:
141+
# We cannot use default workflow's GITHUB_TOKEN here, because
142+
# it is restricted to not trigger 'pull_request' event that
143+
# we need to dispatch the testing workflow.
144+
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
69145
run: |
70-
git push -u origin HEAD
146+
# Write existing PR body text to a file
147+
gh pr view vendoring-${{ github.ref_name }} --json body --jq '.body' > body.txt
148+
# Append change description
149+
echo "${{ steps.prepare_pr_message.outputs.pr_msg }}" >> body.txt
150+
# Remove empty lines
151+
sed -i '/^$/d' body.txt
152+
gh pr edit ${{ steps.check_pr_exists.outputs.pr_num }} \
153+
--title "${{ steps.commit_and_push.outputs.commit_msg }}" \
154+
--body-file body.txt
155+
# Close and re-open the PR to trigger the tests
156+
gh pr close ${{ steps.check_pr_exists.outputs.pr_num }}
157+
gh pr reopen ${{ steps.check_pr_exists.outputs.pr_num }}

0 commit comments

Comments
 (0)