Repository navigation
167 lines (149 loc) · 5.24 KB
/
Copy pathuser_notification_handler.yml
File metadata and controls
167 lines (149 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: User Notification Handler
# Reusable workflow for user notifications (email extraction and sending)
# Called by the orchestrator for failure notifications
on:
workflow_call:
inputs:
pr_number:
required: false
type: string
pr_username:
required: false
type: string
pr_title:
required: false
type: string
is_automerge_web:
required: true
type: boolean
action_type:
required: true
type: string
description: 'Action type: "extract_email" or "send_email"'
failure_reason:
required: false
type: string
description: 'Reason for failure (if sending failure email)'
outputs:
extracted_email:
description: 'The extracted email address (encrypted)'
value: ${{ jobs.extract_email.outputs.email }}
permissions:
contents: read
issues: write
pull-requests: write
jobs:
extract_email:
name: Extract User Email
runs-on: ubuntu-latest
outputs:
email: ${{ steps.set_email_output.outputs.EMAIL }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install "."
- name: Find PR author email for non-web submissions
if: ${{ !inputs.is_automerge_web }}
uses: evvanErb/get-github-email-by-username-action@v2.0
id: getemail
with:
github-username: ${{ inputs.pr_username }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update email for non-web submissions
if: ${{ !inputs.is_automerge_web }}
id: non_automerge_web
run: |
EMAIL=${{ steps.getemail.outputs.email }}
echo "::add-mask::$EMAIL"
echo "EMAIL=$EMAIL" >> $GITHUB_ENV
- name: Check if PR title provided
if: inputs.is_automerge_web
id: get_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -z "${{ inputs.pr_title }}" ]; then
echo "Fetching PR title because it wasn't provided"
PR_TITLE=$(gh pr view ${{ inputs.pr_number }} --repo ${{ github.repository }} --json title -q .title)
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
else
echo "PR_TITLE=${{ inputs.pr_title }}" >> $GITHUB_ENV
fi
- name: Update email for automerge-web (find email from uid)
if: inputs.is_automerge_web
id: automerge_web
env:
BSC_DATABASESECRET: ${{ secrets.BSC_DATABASESECRET }}
run: |
BS_UID="$(echo $PR_TITLE | sed -E 's/.*\(user:([^)]+)\).*/\1/')"
EMAIL=$(python -c "
import os
from brainscore_core.submission.database import email_from_uid
from brainscore_core.submission.endpoints import UserManager
db_secret = os.getenv('BSC_DATABASESECRET')
user_manager = UserManager(db_secret=db_secret)
print(email_from_uid($BS_UID))
")
echo "::add-mask::$EMAIL"
echo "EMAIL=$EMAIL" >> $GITHUB_ENV
- name: Encrypt and set job-level output for email
id: set_email_output
run: |
ENCRYPTED_EMAIL=$(echo -n $EMAIL | openssl enc -aes-256-cbc -a -A -salt -pass pass:${{ secrets.EMAIL_ENCRYPTION_KEY }})
echo "EMAIL=$ENCRYPTED_EMAIL" >> $GITHUB_OUTPUT
- name: Write email to file
if: inputs.action_type == 'send_email'
run: echo "$EMAIL" > email.txt
- name: Upload email as artifact
if: inputs.action_type == 'send_email'
uses: actions/upload-artifact@v4
with:
name: email-artifact
path: email.txt
notify_user:
name: Notify User of Failure
runs-on: ubuntu-latest
needs: extract_email
if: inputs.action_type == 'send_email'
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download email artifact
uses: actions/download-artifact@v4
with:
name: email-artifact
- name: Send email notification
env:
GMAIL_USERNAME: ${{ secrets.GMAIL_USERNAME }}
GMAIL_PASSWORD: ${{ secrets.GMAIL_PASSWORD }}
run: |
python brainscore_language/submission/actions_helpers.py send_failure_email \
$(cat email.txt) \
${{ inputs.pr_number }} \
"${{ inputs.failure_reason }}" \
$GMAIL_USERNAME \
$GMAIL_PASSWORD
- name: Add failure-notified label to PR
if: inputs.pr_number != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ inputs.pr_number }}
run: gh issue edit "$NUMBER" --add-label "failure-notified"