Reputation: 1
Currently I have this dependabot + github actions workflow to create pull requests and auto merge them using action. It works fine the only problem is i get two commits for every pull request in main branch. How can I simplify this workflow?
.github/dependabot.yml
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/src"
schedule:
interval: "daily"
labels:
- "automerge"
- "dependencies"
# Configuration for npm
- package-ecosystem: "npm"
directory: "/src"
schedule:
interval: "daily"
labels:
- "automerge"
- "dependencies"
.github/workflows/auto-merge-dependabot.yml
name: Dependabot auto-merge
on:
pull_request:
types:
- opened
- labeled
- synchronize
permissions:
contents: write
pull-requests: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Verify Dependabot
run: |
if [[ "${{ github.event.sender.type }}" != "Bot" || "${{ github.event.sender.login }}" != "dependabot[bot]" ]]; then
echo "This PR is not from Dependabot."
exit 1
fi
- name: Enable auto-merge for Dependabot PRs
if: contains(github.event.pull_request.labels.*.name, 'automerge')
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Upvotes: 0
Views: 111
Reputation: 13
You can simply simply squash-and-merge instead.
- name: Enable auto-merge for Dependabot PRs
if: contains(github.event.pull_request.labels.*.name, 'automerge')
run: gh pr merge --squash --auto "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Upvotes: 0