|
| 1 | +name: Submodule Auto PR |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + duckdb-python-sha: |
| 6 | + type: string |
| 7 | + description: The commit to build against (defaults to latest commit of current ref) |
| 8 | + required: false |
| 9 | + duckdb-sha: |
| 10 | + type: string |
| 11 | + description: The DuckDB submodule commit or ref to build against |
| 12 | + required: true |
| 13 | + auto-land: |
| 14 | + type: boolean |
| 15 | + description: Immediately merge the PR (placeholder - doesn't work) |
| 16 | + default: false |
| 17 | + secrets: |
| 18 | + DUCKDBLABS_BOT_TOKEN: |
| 19 | + description: Github token of the DuckDBLabs bot |
| 20 | + required: true |
| 21 | + |
| 22 | +defaults: |
| 23 | + run: |
| 24 | + shell: bash |
| 25 | + |
| 26 | +jobs: |
| 27 | + create_pr: |
| 28 | + name: Create PR to bump duckdb submodule to given SHA |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - name: Checkout DuckDB Python |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + ref: ${{ inputs.duckdb-python-sha }} |
| 35 | + fetch-depth: 0 |
| 36 | + submodules: true |
| 37 | + |
| 38 | + - name: Checkout or Create Needed Branch |
| 39 | + run: | |
| 40 | + git fetch --all |
| 41 | + head_sha=${{ inputs.duckdb-python-sha }} |
| 42 | + branch_name="vendoring-${{ github.ref_name }}" |
| 43 | + if [[ `git rev-parse --verify ${branch_name} 2>/dev/null` ]]; then |
| 44 | + # branch exists |
| 45 | + git checkout ${branch_name} |
| 46 | + else |
| 47 | + # new branch |
| 48 | + git checkout -b ${branch_name} |
| 49 | + fi |
| 50 | + [[ ${head_sha} ]] && git reset --hard ${head_sha} || true |
| 51 | +
|
| 52 | + - name: Checkout DuckDB at Given SHA |
| 53 | + run: | |
| 54 | + cd external/duckdb |
| 55 | + git fetch origin |
| 56 | + git checkout ${{ inputs.duckdb-sha }} |
| 57 | +
|
| 58 | + - name: Determine GH PR Command |
| 59 | + id: gh_pr_command |
| 60 | + env: |
| 61 | + GH_TOKEN: ${{ secrets.DUCKDBLABS_BOT_TOKEN }} |
| 62 | + run: | |
| 63 | + pr_url=$( gh pr list --head vendoring-${{ github.ref_name }} --state open --json url --jq '.[].url' ) |
| 64 | + if [[ $pr_url ]]; then |
| 65 | + echo "::notice::Found existing pr, will edit (${pr_url})" |
| 66 | + gh_command="edit ${pr_url}" |
| 67 | + else |
| 68 | + echo "::notice::No existing PR, will create new" |
| 69 | + gh_command="create --head vendoring-${{ github.ref_name }} --base ${{ github.ref_name }}" |
| 70 | + fi |
| 71 | + echo "subcommand=${gh_command}" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + - name: Set Git User |
| 74 | + run: | |
| 75 | + git config --global user.email "github_bot@duckdblabs.com" |
| 76 | + git config --global user.name "DuckDB Labs GitHub Bot" |
| 77 | +
|
| 78 | + - name: Create PR to Bump DuckDB Submodule |
| 79 | + env: |
| 80 | + GH_TOKEN: ${{ secrets.DUCKDBLABS_BOT_TOKEN }} |
| 81 | + run: | |
| 82 | + # First commit and push |
| 83 | + git add external/duckdb |
| 84 | + git commit -m "Bump submodule" |
| 85 | + git push --force origin vendoring-${{ github.ref_name }} |
| 86 | + # create PR msg |
| 87 | + echo "Bump duckdb submodule:" > body.txt |
| 88 | + echo "- Target branch: ${{ github.ref_name }}" >> body.txt |
| 89 | + echo "- Date: $( date +"%Y-%m-%d %H:%M:%S" )" >> body.txt |
| 90 | + echo "- DuckDB SHA: ${{ inputs.duckdb-sha }}" >> body.txt |
| 91 | + echo "- Trigger: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> body.txt |
| 92 | + subcommand="${{ steps.gh_pr_command.outputs.subcommand }}" |
| 93 | + gh pr ${subcommand} \ |
| 94 | + --title "[duckdb-labs bot] Bump DuckDB submodule" \ |
| 95 | + --body-file body.txt > output.txt 2>&1 |
| 96 | + success=$? |
| 97 | + # Show summary |
| 98 | + url=$( [[ $success ]] && gh pr view vendoring-${{ github.ref_name }} --json url --jq .url || true ) |
| 99 | + echo "## Submodule PR Summary" >> $GITHUB_STEP_SUMMARY |
| 100 | + if [[ $success ]]; then |
| 101 | + prefix=$( [[ $subcommand == edit* ]] && echo "Created" || echo "Updated" ) |
| 102 | + echo "### ${prefix} PR: [${url}](${url})" >> $GITHUB_STEP_SUMMARY |
| 103 | + else |
| 104 | + echo "### Failed to create PR" >> $GITHUB_STEP_SUMMARY |
| 105 | + fi |
| 106 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 107 | + cat output.txt >> $GITHUB_STEP_SUMMARY |
| 108 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 109 | + [[ $success ]] || exit 1 |
| 110 | +
|
| 111 | + - name: Automerge PR |
| 112 | + if: ${{ inputs.auto-land }} |
| 113 | + env: |
| 114 | + GH_TOKEN: ${{ secrets.DUCKDBLABS_BOT_TOKEN }} |
| 115 | + run: | |
| 116 | + # PLACEHOLDER: DUCKDBLABS_BOT_TOKEN DOES NOT HAVE PERMISSIONS TO MERGE PRS |
| 117 | + set -ex |
| 118 | + gh pr merge vendoring-${{ github.ref_name }} --rebase > output.txt |
| 119 | + success=$? |
| 120 | + # Show summary |
| 121 | + if [[ $success ]]; then |
| 122 | + echo "### PR merged" >> $GITHUB_STEP_SUMMARY |
| 123 | + else |
| 124 | + echo "### Failed to auto-merge PR" >> $GITHUB_STEP_SUMMARY |
| 125 | + fi |
| 126 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 127 | + cat output.txt >> $GITHUB_STEP_SUMMARY |
| 128 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments