Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions .github/workflows/cherryPick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ jobs:
if: ${{ inputs.PULL_REQUEST_URL != '' }}
id: getCPMergeCommit
run: |
read -r MERGE_COMMIT_SHA MERGE_ACTOR <<< "$(gh pr view ${{ inputs.PULL_REQUEST_URL }} --json mergeCommit,author --jq '"\(.mergeCommit.oid) \(.author.login)"')"
echo "MERGE_COMMIT_SHA=$MERGE_COMMIT_SHA" >> "$GITHUB_OUTPUT"
echo "MERGE_ACTOR=$MERGE_ACTOR" >> "$GITHUB_OUTPUT"
read -r MERGE_COMMIT_SHA MERGE_ACTOR PR_AUTHOR <<< "$(gh pr view ${{ inputs.PULL_REQUEST_URL }} --json mergeCommit,mergedBy,author --jq '"\(.mergeCommit.oid) \(.mergedBy.login) \(.author.login)"')"
{
echo "MERGE_COMMIT_SHA=$MERGE_COMMIT_SHA"
echo "MERGE_ACTOR=$MERGE_ACTOR"
echo "PR_AUTHOR=$PR_AUTHOR"
} >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

Expand Down Expand Up @@ -255,6 +258,50 @@ jobs:
env:
GITHUB_TOKEN: ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}

- name: Resolve Slack mentions for merge actor and CP initiator
if: steps.cherryPick.outputs.HAS_CONFLICTS == 'true'
id: resolveSlack
run: |
# Match Slack IDs to Github IDs using the whitelist
WHITELIST=$(gh api repos/Expensify/Salt/contents/www/files/www-whitelist.php \
--jq '.content' | base64 -d 2>/dev/null || true)

resolve_slack_id() {
local github_user="$1"
if [ -n "$WHITELIST" ] && [ -n "$github_user" ]; then
echo "$WHITELIST" \
| grep -F -A 10 "'github' => '$github_user'" \
Comment on lines +272 to +273

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that this will only work if the slack handle is defined after the github key in the whitelist (which it is now), but it could easily break if someone changes the whitelist.
I don't think there's any plan to though, and it would be an easy fix anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good spot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for this is to change grep -F -A 10 to grep -F -B 10 -A 10 so it searches both before and after the github key match. This makes the lookup order-independent. I've posted the diff in a PR comment — I can't push it directly due to the workflow scope limitation on the token.

| grep -oP -m 1 "'slack'\s*=>\s*'\K[^']+" || true
fi
}

PR_AUTHOR="${{ steps.getCPMergeCommit.outputs.PR_AUTHOR }}"
MERGER="${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }}"
CP_INITIATOR="${{ github.actor }}"

PR_AUTHOR_SLACK=$(resolve_slack_id "$PR_AUTHOR")
MERGER_SLACK=$(resolve_slack_id "$MERGER")
CP_SLACK=$(resolve_slack_id "$CP_INITIATOR")

# Collect unique, successfully resolved Slack IDs; fall back to @appdeployers if none resolve
MENTIONS=""
SEEN=""
for sid in $PR_AUTHOR_SLACK $MERGER_SLACK $CP_SLACK; do
pattern=" $sid "
if [ -n "$sid" ] && [[ ! " $SEEN " =~ $pattern ]]; then
MENTIONS="${MENTIONS:+$MENTIONS / }<@$sid>"
SEEN="$SEEN $sid"
fi
done

if [ -z "$MENTIONS" ]; then
echo "SLACK_MENTION=<!subteam^S4TJJ3PSL>" >> "$GITHUB_OUTPUT"
else
echo "SLACK_MENTION=$MENTIONS" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

- name: Announce CP conflict in #deployer
if: steps.cherryPick.outputs.HAS_CONFLICTS == 'true'
uses: 8398a7/action-slack@1750b5085f3ec60384090fb7c52965ef822e869e
Expand All @@ -265,7 +312,7 @@ jobs:
channel: '#deployer',
attachments: [{
color: "#DB4545",
pretext: `<!subteam^S4TJJ3PSL>`,
pretext: `${{ steps.resolveSlack.outputs.SLACK_MENTION }}`,
text: "🚨 Cherry-pick to ${{ inputs.TARGET }} has conflicts and requires manual resolution.\nOriginal PR: ${{ inputs.PULL_REQUEST_URL }}\nConflict PR: ${{ steps.createPullRequest.outputs.PR_URL }}"
}]
}
Expand All @@ -276,9 +323,7 @@ jobs:
- name: Add assignees to conflict PRs
if: steps.cherryPick.outputs.HAS_CONFLICTS == 'true'
run: |
gh pr edit --add-assignee "${{ github.actor }},${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }}"
ORIGINAL_PR_AUTHOR="$(gh pr view ${{ inputs.PULL_REQUEST_URL }} --json author --jq .author.login)"
gh pr edit --add-assignee "$ORIGINAL_PR_AUTHOR"
gh pr edit --add-assignee "${{ github.actor }},${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }},${{ steps.getCPMergeCommit.outputs.PR_AUTHOR }}"
env:
GITHUB_TOKEN: ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}
# In cases when the original PR author is outside the org, the `gh pr edit` command will fail. But we don't want to fail the workflow in that case.
Expand Down
Loading