Skip to content

Commit 0272594

Browse files
authored
chore: fix combined PR action to work with poetry lock (#3430)
1 parent 9f16b0a commit 0272594

File tree

1 file changed

+82
-8
lines changed

1 file changed

+82
-8
lines changed
Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
name: "Combine Dependabot PRs"
22
on:
33
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
415

516
jobs:
617
combine-prs:
@@ -10,16 +21,79 @@ jobs:
1021
with:
1122
fetch-depth: 0
1223
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]"
1340
- name: Setup local branch and merge tool
1441
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 }}"
1643
echo "poetry.lock merge=ours" >> .git/info/attributes
1744
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
1982
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

Comments
 (0)