11name : Merge Dependabot PRs
22on :
33 schedule :
4- - cron : ' 0 9 * * 1' # Run this workflow every Monday at 9:00
4+ - cron : " 0 9 * * 1" # Run this workflow every Monday at 9:00
55 workflow_dispatch :
66
77jobs :
88 merge :
99 runs-on : ubuntu-latest
1010 steps :
1111 - name : Check out code
12- uses : actions/checkout@v2
12+ uses : actions/checkout@v3
1313 with :
1414 ref : master
1515
2323
2424 - name : Get current date and time
2525 id : datetime
26- run : echo "::set-output name= date:: $(date +'%m-%d-%Y-%H-%M')"
26+ run : echo "date= $(date +'%m-%d-%Y-%H-%M')" >> $GITHUB_OUTPUT
2727
2828 - name : Create new branch based on date and time
29- id : create_new_branch
3029 run : |
3130 NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
3231 git checkout -b $NEW_BRANCH
@@ -36,21 +35,25 @@ jobs:
3635 id : pr_list
3736 run : |
3837 PR_LIST=$(gh pr list --json number,headRefName --jq '.[] | "\(.number) \(.headRefName)"' | grep dependabot)
38+ PR_LIST=$(echo "$PR_LIST" | tr -d '\r')
3939 if [ -z "$PR_LIST" ]; then
4040 echo "No PRs from dependabot found."
4141 exit 0
4242 fi
43- echo "::set-output name=numbers::$PR_LIST"
43+
4444 PR_COUNT=$(echo "$PR_LIST" | wc -l)
45- echo "$PR_COUNT PR's to be merged: $PR_LIST"
45+ echo "$PR_COUNT PR's to be merged."
46+
47+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
48+ echo "prs<<$EOF" >> $GITHUB_OUTPUT
49+ echo "$PR_LIST" >> $GITHUB_OUTPUT
50+ echo "$EOF" >> $GITHUB_OUTPUT
4651
4752 - name : Merge PRs into new branch
4853 run : |
4954 NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
5055 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"
56+ PR_LIST="${{ steps.pr_list.outputs.prs }}"
5457 while IFS= read -r line; do
5558 IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
5659 echo "Merging PR #$PR_NUMBER from branch $BRANCH_NAME into $NEW_BRANCH..."
6568 run : |
6669 echo "Merging process completed successfully!"
6770 echo "New branch name: dependabot-test-${{ steps.datetime.outputs.date }}"
71+
72+ - name : Generate PR links
73+ id : pr_links
74+ run : |
75+ PR_LIST="${{ steps.pr_list.outputs.prs }}"
76+ PR_LINKS=""
77+ while IFS= read -r line; do
78+ IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
79+ PR_URL="https://github.com/${GITHUB_REPOSITORY}/pull/$PR_NUMBER"
80+ PR_LINKS+="\n• <$PR_URL|#${PR_NUMBER}: ${BRANCH_NAME}>"
81+ done <<< "$PR_LIST"
82+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
83+ echo "pr_links<<$EOF" >> $GITHUB_OUTPUT
84+ echo "$PR_LINKS" >> $GITHUB_OUTPUT
85+ echo "$EOF" >> $GITHUB_OUTPUT
86+
87+ - name : Post to a Slack channel
88+ 89+ with :
90+ channel-id : " C03RTLRKJQP"
91+ payload : |
92+ {
93+ "blocks": [
94+ {
95+ "type": "header",
96+ "text": {
97+ "type": "plain_text",
98+ "text": "⚡️ New iOS Dependabot Testing Branch",
99+ "emoji": true
100+ }
101+ },
102+ {
103+ "type": "section",
104+ "text": {
105+ "type": "mrkdwn",
106+ "text": "*Included PRs:*${{ steps.pr_links.outputs.pr_links }}"
107+ }
108+ },
109+ {
110+ "type": "actions",
111+ "elements": [
112+ {
113+ "type": "button",
114+ "text": {
115+ "type": "plain_text",
116+ "text": "Checkout Test Branch",
117+ "emoji": true
118+ },
119+ "value": "branch-button",
120+ "url": "https://github.com/${{ github.repository }}/tree/dependabot-test-${{ steps.datetime.outputs.date }}",
121+ "action_id": "link-action"
122+ }
123+ ]
124+ }
125+ ]
126+ }
127+ env :
128+ SLACK_BOT_TOKEN : ${{ secrets.SLACK_SDK_BOT_TOKEN }}
0 commit comments