|
17 | 17 |
|
18 | 18 | jobs:
|
19 | 19 | vendor:
|
20 |
| - runs-on: ubuntu-latest |
21 |
| - outputs: |
22 |
| - did_vendor: ${{ steps.vendor.outputs.vendor }} |
23 |
| - |
24 | 20 | name: "Update Vendored Sources"
|
25 |
| - if: github.repository == 'duckdb/duckdb-java' |
| 21 | + if: ${{ github.repository == 'duckdb/duckdb-java' }} |
| 22 | + runs-on: ubuntu-latest |
26 | 23 |
|
27 | 24 | 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 |
29 | 34 | with:
|
30 | 35 | fetch-depth: 0
|
31 |
| - token: ${{ secrets.PAT_TOKEN }} |
32 | 36 |
|
33 |
| - - uses: actions/checkout@v4 |
| 37 | + - name: Checkout engine |
| 38 | + uses: actions/checkout@v4 |
| 39 | + id: checkout_engine |
34 | 40 | with:
|
35 | 41 | repository: duckdb/duckdb
|
36 | 42 | path: .git/duckdb
|
37 | 43 | fetch-depth: 0
|
38 | 44 |
|
39 |
| - - name: Get commit SHA |
| 45 | + - name: Checkout engine rev |
| 46 | + id: checkout_engine_rev |
40 | 47 | if: ${{ inputs.duckdb-sha != '' }}
|
| 48 | + working-directory: .git/duckdb |
41 | 49 | 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 }} |
47 | 52 |
|
48 | 53 | - name: Vendor sources
|
| 54 | + if: ${{ steps.checkout_engine_rev.outcome == 'success' }} |
49 | 55 | id: vendor
|
50 | 56 | 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}" |
53 | 59 | git config --global user.email "[email protected]"
|
54 | 60 | 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 |
55 | 66 | git rm -rf src/duckdb
|
56 | 67 | python vendor.py --duckdb .git/duckdb
|
57 | 68 | git add src/duckdb CMakeLists.txt
|
| 69 | + # Clean up |
58 | 70 | 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}" |
61 | 80 | # Check if ahead of upstream branch
|
62 | 81 | # 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 }} |
64 | 85 | # 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}" |
66 | 104 | fi
|
67 | 105 |
|
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 }} |
69 | 145 | 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