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