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