1
1
name : " Combine Dependabot PRs"
2
2
on :
3
3
workflow_dispatch :
4
+ inputs :
5
+ target_branch :
6
+ description : Target branch to create a release/PR to
7
+ type : string
8
+ required : true
9
+ default : develop
10
+ branch_name :
11
+ description : Name of the branch to combine PRs into
12
+ type : string
13
+ required : true
14
+ default : combined-prs-branch
4
15
5
16
jobs :
6
17
combine-prs :
@@ -10,16 +21,79 @@ jobs:
10
21
with :
11
22
fetch-depth : 0
12
23
token : " ${{ secrets.RENKUBOT_GITHUB_TOKEN }}"
24
+ - name : Set up Python
25
+ uses : actions/setup-python@v4
26
+ with :
27
+ python-version : 3.11
28
+ - name : Install dependencies
29
+ env :
30
+ POETRY_VIRTUALENVS_CREATE : " false"
31
+ shell : bash
32
+ run : |
33
+ python -m pip install --upgrade pip
34
+ python -m pip install poetry
35
+ - name : Set Git config
36
+ shell : bash
37
+ run : |
38
+ git config --global --add user.name "Renku Bot"
39
+ git config --global --add user.email "[email protected] "
13
40
- name : Setup local branch and merge tool
14
41
run : |
15
- git branch --track dependabot-updates origin/dependabot-updates
42
+ git branch --track "${{ inputs.branch_name }}" " origin/${{ inputs.branch_name }}" || git checkout "${{ inputs.branch_name }}"
16
43
echo "poetry.lock merge=ours" >> .git/info/attributes
17
44
git config merge.ours.driver true
18
- - uses : github/combine-prs@main
45
+ git merge --no-edit develop
46
+ - name : Merge PRs
47
+ id : merge_prs
48
+ env :
49
+ POETRY_VIRTUALENVS_CREATE : " false"
50
+ run : |
51
+ repo="https://api.github.com/repos/${{ github.repository }}"
52
+ dependabot_pulls=($(curl -s "$repo/pulls?state=open" | jq -r ".[] | select((.head.ref | test(\"dependabot/\"))) | \"\(.head.ref),\(.number)\""))
53
+
54
+ pr_body="# Combined PRs\n✅ The following pull requests have been successfully combined on this PR:\n"
55
+ failed=()
56
+
57
+ for branch in "${dependabot_pulls[@]}"; do
58
+ branch_arr=(${branch//,/ })
59
+ echo "Merging branch ${branch_arr[0]}"
60
+
61
+ if git merge --no-edit "origin/${branch_arr[0]}"; then
62
+ pr_body="$pr_body\n- #${branch_arr[1]}"
63
+ else
64
+ failed+=(${branch_arr[1]})
65
+ fi
66
+ done
67
+
68
+ if (( ${#failed[@]} )); then
69
+ pr_body="$pr_body\n\nFailed to combine:\n"
70
+
71
+ for fail in "${failed[@]}"; do
72
+ pr_body="$pr_body\n- #$fail"
73
+ done
74
+ fi
75
+ poetry lock
76
+ git add -A
77
+ git commit -m "update lock file" --no-verify
78
+ git push
79
+ echo "pr_body=$pr_body" >> $GITHUB_OUTPUT
80
+ - name : Create Pull Request
81
+ uses : actions/github-script@v6
19
82
with :
20
- branch_prefix : " dependabot"
21
- ci_required : false
22
- ignore_label : " nocombine"
23
- open_pr : true
24
- github_token : " ${{ secrets.RENKUBOT_GITHUB_TOKEN }}"
25
- pr_title : " chore: combined dependency update"
83
+ token : ${{ secrets.RENKUBOT_GITHUB_TOKEN }}
84
+ script : |
85
+ const { repo, owner } = context.repo;
86
+ const result = await github.rest.pulls.create({
87
+ title: 'chore: combined dependency update',
88
+ owner,
89
+ repo,
90
+ head: '${{ inputs.branch_name }}',
91
+ base: '${{ github.event.inputs.target_branch }}',
92
+ body: '${{ steps.merge_prs.outputs.pr_body }}'
93
+ });
94
+ github.rest.issues.addLabels({
95
+ owner,
96
+ repo,
97
+ issue_number: result.data.number,
98
+ labels: ['dependencies', 'automated pr']
99
+ });
0 commit comments