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,18 +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)
4545 echo "$PR_COUNT PR's to be merged."
4646
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
51+
4752 - name : Merge PRs into new branch
4853 run : |
4954 NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
5055 git checkout $NEW_BRANCH
56+ PR_LIST="${{ steps.pr_list.outputs.prs }}"
5157 while IFS= read -r line; do
5258 IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
5359 echo "Merging PR #$PR_NUMBER from branch $BRANCH_NAME into $NEW_BRANCH..."
5662 echo "Pushing changes to $NEW_BRANCH..."
5763 git commit -m "Merged PR #$PR_NUMBER into $NEW_BRANCH"
5864 git push origin $NEW_BRANCH
59- done <<< "${{ steps.pr_list.outputs.numbers }} "
65+ done <<< "$PR_LIST "
6066
6167 - name : Merge process status
6268 run : |
@@ -66,46 +72,55 @@ jobs:
6672 - name : Generate PR links
6773 id : pr_links
6874 run : |
75+ PR_LIST="${{ steps.pr_list.outputs.prs }}"
6976 PR_LINKS=""
7077 while IFS= read -r line; do
7178 IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
7279 PR_URL="https://github.com/${GITHUB_REPOSITORY}/pull/$PR_NUMBER"
7380 PR_LINKS+="\n• <$PR_URL|#${PR_NUMBER}: ${BRANCH_NAME}>"
74- done <<< "${{ steps.pr_list.outputs.numbers }}"
75-
76- echo "::set-output name=pr_links::$PR_LINKS"
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
7786
7887 - name : Post to a Slack channel
79888089 with :
81- channel-id : ' C04E69NEDAT '
90+ channel-id : " C03RTLRKJQP "
8291 payload : |
8392 {
8493 "blocks": [
8594 {
8695 "type": "header",
8796 "text": {
8897 "type": "plain_text",
89- "text": "New iOS Dependabot Testing Branch",
98+ "text": "⚡️ New iOS Dependabot Testing Branch",
9099 "emoji": true
91100 }
92101 },
93- {
94- "type": "divider"
95- },
96102 {
97103 "type": "section",
98104 "text": {
99105 "type": "mrkdwn",
100- "text": "*Testing Branch: *<https://github.com/${GITHUB_REPOSITORY}/tree/dependabot-test-${{ steps.datetime .outputs.date }}|dependabot-test-${{ steps.datetime.outputs.date }}> "
106+ "text": "*Included PRs:*${{ steps.pr_links .outputs.pr_links }}"
101107 }
102108 },
103109 {
104- "type": "section",
105- "text": {
106- "type": "mrkdwn",
107- "text": "'${{ steps.pr_links.outputs.pr_links }}'"
108- }
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+ ]
109124 }
110125 ]
111126 }
0 commit comments