11name : Merge Dependabot PRs
22on :
33 schedule :
4- - cron : ' 0 12 * * 5 ' # Run this workflow every Friday at 12 :00
4+ - cron : ' 0 9 * * 1 ' # Run this workflow every Monday at 9 :00
55 workflow_dispatch :
66
77jobs :
@@ -10,26 +10,58 @@ jobs:
1010 steps :
1111 - name : Check out code
1212 uses : actions/checkout@v2
13+ with :
14+ ref : master
1315
1416 - name : Authenticate GitHub CLI
1517 run : echo "${{ secrets.DEPENDABOT_MERGER_PAT }}" | gh auth login --with-token
1618
17- - name : Ensure test branch is up to date with master
19+ - name : Set Git user identity
1820 run : |
19- git checkout master
20- git pull
21- git checkout dependabot-test-branch
22- git merge master
21+ git config user.email "[email protected] " 22+ git config user.name "Dependabot Merger Bot"
23+
24+ - name : Get current date and time
25+ id : datetime
26+ run : echo "::set-output name=date::$(date +'%m-%d-%Y-%H-%M')"
27+
28+ - name : Create new branch based on date and time
29+ id : create_new_branch
30+ run : |
31+ NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
32+ git checkout -b $NEW_BRANCH
33+ git push origin $NEW_BRANCH
2334
2435 - name : Get list of PRs from dependabot
2536 id : pr_list
2637 run : |
27- echo "::set-output name=numbers::$(gh pr list --author 'dependabot[bot]' --state open --json number --jq '.[] .number')"
28-
29- - name : Merge PRs into test branch
38+ PR_LIST=$(gh pr list --json number,headRefName --jq '.[] | "\(.number) \(.headRefName)"' | grep dependabot)
39+ if [ -z "$PR_LIST" ]; then
40+ echo "No PRs from dependabot found."
41+ exit 0
42+ fi
43+ echo "::set-output name=numbers::$PR_LIST"
44+ PR_COUNT=$(echo "$PR_LIST" | wc -l)
45+ echo "$PR_COUNT PR's to be merged: $PR_LIST"
46+
47+ - name : Merge PRs into new branch
48+ run : |
49+ NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
50+ git checkout $NEW_BRANCH
51+ PR_LIST=$(gh pr list --json number,headRefName --jq '.[] | "\(.number) \(.headRefName)"' | grep dependabot)
52+ PR_LIST=$(echo "$PR_LIST" | tr -d '\r')
53+ echo "::set-output name=numbers::$PR_LIST"
54+ while IFS= read -r line; do
55+ IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
56+ echo "Merging PR #$PR_NUMBER from branch $BRANCH_NAME into $NEW_BRANCH..."
57+ git fetch origin $BRANCH_NAME
58+ git merge --no-commit --allow-unrelated-histories --strategy-option=theirs origin/$BRANCH_NAME
59+ echo "Pushing changes to $NEW_BRANCH..."
60+ git commit -m "Merged PR #$PR_NUMBER into $NEW_BRANCH"
61+ git push origin $NEW_BRANCH
62+ done <<< "$PR_LIST"
63+
64+ - name : Merge process status
3065 run : |
31- IFS=' ' read -r -a array <<< "${{ steps.pr_list.outputs.numbers }}"
32- for PR_NUMBER in "${array[@]}"
33- do
34- gh pr merge $PR_NUMBER --merge --repo ${{ github.repository }} --branch dependabot-test-branch
35- done
66+ echo "Merging process completed successfully!"
67+ echo "New branch name: dependabot-test-${{ steps.datetime.outputs.date }}"
0 commit comments