Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions/checkout-4
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch authored Oct 24, 2023
2 parents 1de2b49 + 2fe5b60 commit 8c09128
Show file tree
Hide file tree
Showing 80 changed files with 2,111 additions and 2,398 deletions.
212 changes: 122 additions & 90 deletions .github/workflows/dependabot-merger.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Merge Dependabot PRs

on:
schedule:
- cron: "0 9 * * 1" # Run this workflow every Monday at 9:00
Expand All @@ -7,120 +8,151 @@ on:
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: master

- name: Authenticate GitHub CLI
run: echo "${{ secrets.DEPENDABOT_MERGER_PAT }}" | gh auth login --with-token

- name: Set Git user identity
steps:
- name: Get current on-call
id: on-call
run: |
git config user.email "[email protected]"
git config user.name "Dependabot Merger Bot"
now=$(date -u +%Y-%m-%dT%H:%M:%SZ)
end_time=$(date -u -d '+24 hour' +%Y-%m-%dT%H:%M:%SZ)
- name: Get current date and time
id: datetime
run: echo "date=$(date +'%m-%d-%Y-%H-%M')" >> $GITHUB_OUTPUT
oncall=$(curl --request GET \
--url "https://api.pagerduty.com/oncalls?since=$now&until=$end_time&schedule_ids[]=PQLHTOP" \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header "Authorization: Token token=${{ secrets.PAGERDUTY_TOKEN }}" \
--header 'Content-Type: application/json' )
- name: Create new branch based on date and time
run: |
NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
git checkout -b $NEW_BRANCH
git push origin $NEW_BRANCH
- name: Get list of PRs from dependabot
id: pr_list
run: |
PR_LIST=$(gh pr list --json number,author,headRefName --jq '.[] | select( .author.is_bot == true and .author.login == "app/dependabot" ) | "\(.number) \(.headRefName)"')
PR_LIST=$(echo "$PR_LIST" | tr -d '\r')
if [ -z "$PR_LIST" ]; then
echo "No PRs from dependabot found."
exit 0
fi
engineer_name=$(echo "$oncall" | jq -r '.oncalls[0].user.summary')
PR_COUNT=$(echo "$PR_LIST" | wc -l)
echo "$PR_COUNT PR's to be merged."
declare -A engineer_to_slackid
engineer_to_slackid=(
["Nipun Singh"]="U02AMC70R6E"
["Jagadeesh Karicherla"]="U038BDE0XUZ"
["Gabe De Luna"]="U02MDA0PHK5"
["Ernest Cho"]="UCV77QDSL"
["Nidhi Dixit"]="U02GDFBP88N"
)
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "prs<<$EOF" >> $GITHUB_OUTPUT
echo "$PR_LIST" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
slack_id=${engineer_to_slackid["$engineer_name"]}
echo "oncall_slack_id=$slack_id" >> $GITHUB_OUTPUT
- name: Merge PRs into new branch
run: |
NEW_BRANCH="dependabot-test-${{ steps.datetime.outputs.date }}"
git checkout $NEW_BRANCH
PR_LIST="${{ steps.pr_list.outputs.prs }}"
while IFS= read -r line; do
IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
echo "Merging PR #$PR_NUMBER from branch $BRANCH_NAME into $NEW_BRANCH..."
git fetch origin $BRANCH_NAME
git merge --no-commit --allow-unrelated-histories --strategy-option=theirs origin/$BRANCH_NAME
echo "Pushing changes to $NEW_BRANCH..."
git commit -m "Merged PR #$PR_NUMBER into $NEW_BRANCH"
git push origin $NEW_BRANCH
done <<< "$PR_LIST"
- name: Create PR
uses: actions/github-script@v6
id: create-pr
with:
script: |
const uniqueBranchName = 'dependabot-combined-prs-' + Date.now().toString();
const pulls = await github.paginate('GET /repos/:owner/:repo/pulls', {
owner: context.repo.owner,
repo: context.repo.repo
});
let branchesAndPRStrings = [];
let baseBranch = null;
let baseBranchSHA = null;
for (const pull of pulls) {
const branch = pull['head']['ref'];
if (branch.startsWith('dependabot/')) {
console.log('Branch matched prefix. Adding to array: ' + branch);
const prString = '#' + pull['number'] + ' ' + pull['title'];
branchesAndPRStrings.push({ branch, prString });
baseBranch = pull['base']['ref'];
baseBranchSHA = pull['base']['sha'];
}
}
if (branchesAndPRStrings.length == 0) {
core.setFailed('There are no open dependabot PRs.');
return;
}
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/heads/' + uniqueBranchName,
sha: baseBranchSHA
});
} catch (error) {
console.log(error);
core.setFailed('Failed to create combined branch');
return;
}
- name: Merge process status
run: |
echo "Merging process completed successfully!"
echo "New branch name: dependabot-test-${{ steps.datetime.outputs.date }}"
let combinedPRs = [];
let mergeFailedPRs = [];
for(const { branch, prString } of branchesAndPRStrings) {
try {
await github.rest.repos.merge({
owner: context.repo.owner,
repo: context.repo.repo,
base: uniqueBranchName,
head: branch,
});
console.log('Merged branch ' + branch);
combinedPRs.push(prString);
} catch (error) {
console.log('Failed to merge branch ' + branch);
mergeFailedPRs.push(prString);
}
}
- name: Generate PR links
id: pr_links
run: |
PR_LIST="${{ steps.pr_list.outputs.prs }}"
PR_LINKS=""
while IFS= read -r line; do
IFS=' ' read -r PR_NUMBER BRANCH_NAME <<< "$line"
PR_URL="https://github.com/${GITHUB_REPOSITORY}/pull/$PR_NUMBER"
PR_LINKS+="\n• <$PR_URL|#${PR_NUMBER}: ${BRANCH_NAME}>"
done <<< "$PR_LIST"
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "pr_links<<$EOF" >> $GITHUB_OUTPUT
echo "$PR_LINKS" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
console.log('Creating combined PR');
const combinedPRsString = combinedPRs.join('\n');
let body = '✅ This PR was created by the Merge Dependabot PRs action by combining the following dependabot PRs:\n' + combinedPRsString;
if(mergeFailedPRs.length > 0) {
const mergeFailedPRsString = mergeFailedPRs.join('\n');
body += '\n\n⚠️ The following dependabot PRs were left out due to merge conflicts:\n' + mergeFailedPRsString
}
let response = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Combined Dependabot PR',
head: uniqueBranchName,
base: baseBranch,
body: body
});
console.log('Created combined PR: ' + response.data.html_url);
core.setOutput('pr_url', response.data.html_url);
core.setOutput('pr_list', combinedPRsString);
- name: Post to a Slack channel
uses: slackapi/[email protected]
id: slack
with:
channel-id: "C03RTLRKJQP"
payload: |
{
"blocks": [
"text": "iOS: New Dependabot PR Awaiting Review",
"blocks": [
{
"type": "header",
"text": {
"type": "header",
"text": {
"type": "plain_text",
"text": "⚡️ New iOS Dependabot Testing Branch",
"text":"📱🔧 iOS: New Dependabot PR Awaiting Review",
"emoji": true
}
}
},
{
"type": "section",
"text": {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Included PRs:*${{ steps.pr_links.outputs.pr_links }}"
}
"text": "*Included PRs:*\n${{ toJSON(steps.create-pr.outputs.pr_list) }}\n\n\nCurrent On-Call: *<${{ steps.on-call.outputs.oncall_slack_id }}>*"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Checkout Test Branch",
"emoji": true
},
"value": "branch-button",
"url": "https://github.com/${{ github.repository }}/tree/dependabot-test-${{ steps.datetime.outputs.date }}",
"action_id": "link-action"
}
]
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":github-pull-request-open: View Combined PR",
"emoji": true
},
"value": "pr-button",
"url": "${{ steps.create-pr.outputs.pr_url }}",
"action_id": "link-action",
"style": "primary"
}
]
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
issues: write

steps:
- uses: actions/stale@v5
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.STALE_PERSONAL_ACCESS_TOKEN }}
days-before-issue-stale: 60
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/sync-readme-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Update Version History on ReadMe

on:
release:
types: [published]

jobs:
update-changelog:
runs-on: ubuntu-latest

steps:
- name: Format and publish release notes to version history doc
id: update
run: |
# Get release name, body, and date from the release event
release_name="${{ github.event.release.tag_name }}"
release_body="${{ github.event.release.body }}"
release_date=$(date -d "${{ github.event.release.published_at }}" +"%Y-%B-%d")
# Format release notes
formatted_notes="## v$release_name\n\n**($release_date)**\n\n$release_body"
# Get existing version history page
existing_content=$(curl --request GET \
--url https://dash.readme.com/api/v1/docs/ios-version-history \
--header 'accept: application/json' \
--header "authorization: Basic ${{ secrets.readme_api_key_base64 }}" \
| jq -r '.body')
# Prepend new release notes to existing content
new_content=$(echo -e "$formatted_notes\n\n$existing_content")
payload=$(jq -n --arg nc "$new_content" '{"body": $nc}')

# Update version history page with new release notes
curl --request PUT \
--url https://dash.readme.com/api/v1/docs/ios-version-history \
--header 'accept: application/json' \
--header "authorization: Basic ${{ secrets.readme_api_key_base64 }}" \
--header 'content-type: application/json' \
--data "$payload"

- name: Announce New Release in Slack
uses: slackapi/[email protected]
with:
channel-id: "CDFGXRM9S"
payload: |
{
"text": "New Release: Branch iOS SDK v${{ github.event.release.tag_name }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":rocket: New Release: Branch iOS SDK v${{ github.event.release.tag_name }}",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":star: *What's New*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ${{ toJSON(github.event.release.body) }}
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":git: GitHub Release",
"emoji": true
},
"value": "github",
"action_id": "github",
"url": "${{ github.event.release.html_url }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_SDK_BOT_TOKEN }}

Loading

0 comments on commit 8c09128

Please sign in to comment.