-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reusable notification workflow (#665)
* Create user_notification_system.yml * add email function to helpers * add failure notification when checks don't pass * Update score_new_plugins.yml * switch from Failure to False * change failure to false * add failure label after email notification sent * [still testing] notified failure check and removal * addition and check of failure-notified label * change to GITHUB_TOKEN --------- Co-authored-by: Martin Schrimpf <[email protected]>
- Loading branch information
1 parent
46bcf59
commit 031a447
Showing
4 changed files
with
369 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,30 +64,27 @@ jobs: | |
id: scoringneeded | ||
run: | | ||
echo "RUN_SCORING=$(jq -r '.run_score' <<< ${{ steps.getpluginfo.outputs.PLUGIN_INFO }})" >> $GITHUB_OUTPUT | ||
- name: Find PR author email for non-web submissions | ||
if: "!contains(github.event.pull_request.labels.*.name, 'automerge-web') && steps.scoringneeded.outputs.RUN_SCORING == 'True'" | ||
uses: evvanErb/[email protected] | ||
id: getemail | ||
with: | ||
github-username: ${{github.event.pull_request.user.login}} | ||
token: ${{ secrets.GITHUB_TOKEN }} # Including token enables most reliable way to get a user's email | ||
- name: Update PLUGIN_INFO for non-web submissions | ||
if: "!contains(github.event.pull_request.labels.*.name, 'automerge-web') && steps.scoringneeded.outputs.RUN_SCORING == 'True'" | ||
id: non_automerge_web | ||
- name: Check for automerge-web label | ||
id: check_label | ||
run: | | ||
echo "The PR author email is ${{ steps.getemail.outputs.email }}" | ||
echo "PLUGIN_INFO=$(<<<${{ steps.getpluginfo.outputs.PLUGIN_INFO }} tr -d "'" | jq -c '. + {email: "${{ steps.getemail.outputs.email }}"}')" >> $GITHUB_ENV | ||
- name: Update PLUGIN_INFO for automerge-web (find uid, public v. private, and bs email) | ||
if: contains(github.event.pull_request.labels.*.name, 'automerge-web') && steps.scoringneeded.outputs.RUN_SCORING == 'True' | ||
id: automerge_web | ||
LABELS_JSON="${{ toJSON(github.event.pull_request.labels.*.name) }}" | ||
if echo "$LABELS_JSON" | grep -q "automerge-web"; then | ||
echo "has_automerge_web=true" >> $GITHUB_ENV | ||
else | ||
echo "has_automerge_web=false" >> $GITHUB_ENV | ||
fi | ||
- name: Update PLUGIN_INFO based on label | ||
run: | | ||
BS_UID="$(echo '${{ github.event.pull_request.title }}' | sed -E 's/.*\(user:([^)]+)\).*/\1/')" | ||
BS_PUBLIC="$(echo '${{ github.event.pull_request.title }}' | sed -E 's/.*\(public:([^)]+)\).*/\1/')" | ||
USER_EMAIL=$(python -c "from brainscore_core.submission.database import email_from_uid; from brainscore_core.submission.endpoints import UserManager; user_manager=UserManager(db_secret='${{ secrets.BSC_DATABASESECRET }}'); print(email_from_uid($BS_UID))") | ||
echo "::add-mask::$USER_EMAIL" # Mask the USER_EMAIL | ||
echo "PLUGIN_INFO=$(<<<${{ steps.getpluginfo.outputs.PLUGIN_INFO }} tr -d "'" | jq -c ". + {user_id: \"$BS_UID\", public: \"$BS_PUBLIC\", email: \"$USER_EMAIL\"}")" >> $GITHUB_ENV | ||
if [[ "$has_automerge_web" == "true" ]]; then | ||
BS_UID="$(echo '${{ github.event.pull_request.title }}' | sed -E 's/.*\(user:([^)]+)\).*/\1/')" | ||
BS_PUBLIC="$(echo '${{ github.event.pull_request.title }}' | sed -E 's/.*\(public:([^)]+)\).*/\1/')" | ||
PLUGIN_INFO=$(echo ${{ steps.getpluginfo.outputs.PLUGIN_INFO }} | tr -d "'" | jq -c ". + {user_id: \"$BS_UID\", public: \"$BS_PUBLIC\"}") | ||
echo "PLUGIN_INFO=${PLUGIN_INFO}" >> $GITHUB_ENV | ||
else | ||
echo "PLUGIN_INFO=$(echo ${{ steps.getpluginfo.outputs.PLUGIN_INFO }} | tr -d "'")" >> $GITHUB_ENV | ||
fi | ||
- name: Write PLUGIN_INFO to a json file | ||
run: | | ||
|
@@ -98,12 +95,64 @@ jobs: | |
with: | ||
name: plugin-info | ||
path: plugin-info.json | ||
|
||
extract_email: | ||
name: Extracts email for both PRs and web submissions | ||
uses: ./.github/workflows/user_notification_system.yml | ||
needs: process_submission | ||
if: ${{ needs.process_submission.outputs.RUN_SCORING == 'True' }} | ||
with: | ||
pr_username: ${{github.event.pull_request.user.login}} | ||
pr_title: ${{ github.event.pull_request.title }} | ||
is_automerge_web: ${{ contains(github.event.pull_request.labels.*.name, 'automerge-web') }} | ||
action_type: 'extract_email' | ||
secrets: inherit | ||
|
||
update_plugin_info: | ||
name: Updates PLUGIN_INFO with various fields (domain, competition, model_type, email) | ||
runs-on: ubuntu-latest | ||
needs: extract_email | ||
steps: | ||
- name: Download PLUGIN_INFO artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: plugin-info | ||
path: artifact-directory | ||
|
||
- name: Set PLUGIN_INFO as an environment variable | ||
run: | | ||
PLUGIN_INFO=$(cat artifact-directory/plugin-info.json) | ||
echo "PLUGIN_INFO=${PLUGIN_INFO}" >> $GITHUB_ENV | ||
- name: Decrypt and mask user email | ||
run: | | ||
DECRYPTED_EMAIL=$(echo "${{ needs.extract_email.outputs.extracted_email }}" | openssl enc -aes-256-cbc -a -d -salt -pass pass:${{ secrets.EMAIL_ENCRYPTION_KEY }}) | ||
echo "::add-mask::$DECRYPTED_EMAIL" | ||
echo "USER_EMAIL=${DECRYPTED_EMAIL}" >> $GITHUB_ENV | ||
- name: Update PLUGIN_INFO | ||
run: | | ||
PLUGIN_JSON=$(echo "$PLUGIN_INFO" | jq -c '. + {domain: "vision", competition: "None", model_type: "Brain_Model"}') | ||
echo "PLUGIN_INFO=$PLUGIN_JSON" >> $GITHUB_ENV | ||
PLUGIN_JSON=$(echo "$PLUGIN_JSON" | jq -c --arg email "$USER_EMAIL" '. + {email: $email}') | ||
echo "PLUGIN_INFO=$PLUGIN_JSON" >> $GITHUB_ENV | ||
echo "Updated PLUGIN_INFO: $PLUGIN_JSON" | ||
- name: Write PLUGIN_INFO to a json file | ||
run: | | ||
echo "$PLUGIN_INFO" > plugin-info.json | ||
- name: Upload PLUGIN_INFO as an artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: plugin-info | ||
path: plugin-info.json | ||
|
||
run_scoring: | ||
name: Score plugins | ||
runs-on: ubuntu-latest | ||
needs: [process_submission] | ||
needs: [process_submission, extract_email, update_plugin_info] | ||
if: needs.process_submission.outputs.RUN_SCORING == 'True' | ||
env: | ||
JENKINS_USER: ${{ secrets.JENKINS_USER }} | ||
|
@@ -121,12 +170,8 @@ jobs: | |
run: | | ||
PLUGIN_INFO=$(cat artifact-directory/plugin-info.json) | ||
USER_EMAIL=$(echo "$PLUGIN_INFO" | jq -r '.email') | ||
echo "::add-mask::$USER_EMAIL" # add a mask when bringing email back from artifact | ||
echo "::add-mask::$USER_EMAIL" # readd a mask when bringing email back from artifact | ||
echo "PLUGIN_INFO=${PLUGIN_INFO}" >> $GITHUB_ENV | ||
- name: Add domain, public, competition, and model_type to PLUGIN_INFO | ||
run: | | ||
echo "PLUGIN_INFO=$(<<<$PLUGIN_INFO tr -d "'" | jq -c '. + {domain: "vision", competition: "None", model_type: "Brain_Model"}')" >> $GITHUB_ENV | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
@@ -144,3 +189,4 @@ jobs: | |
- name: Run scoring | ||
run: | | ||
python -c 'from brainscore_core.submission.endpoints import call_jenkins; call_jenkins('\''${{ env.PLUGIN_INFO }}'\'')' | ||
Oops, something went wrong.