From efa9e0473a13663d3ad7e71e50487197c190d883 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 18 Apr 2024 09:20:01 -0400 Subject: [PATCH] wip: Add support for sending email on instance created, started or stopped App password created using https://myaccount.google.com/apppasswords --- .github/ISSUE_TEMPLATE/request.yml | 7 ++++ .github/workflows/control-instance.yml | 52 ++++++++++++++++++++++++++ .github/workflows/create-instance.yml | 28 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/request.yml b/.github/ISSUE_TEMPLATE/request.yml index 9932f04b..3f481273 100644 --- a/.github/ISSUE_TEMPLATE/request.yml +++ b/.github/ISSUE_TEMPLATE/request.yml @@ -33,3 +33,10 @@ body: description: Briefly describe how you will be using the instance. validations: required: false + + - type: input + attributes: + label: Email + description: Email to use for notifications. + validations: + required: true diff --git a/.github/workflows/control-instance.yml b/.github/workflows/control-instance.yml index eec2e996..9555b5ce 100644 --- a/.github/workflows/control-instance.yml +++ b/.github/workflows/control-instance.yml @@ -20,6 +20,30 @@ jobs: env: NUMBER: ${{ github.event.issue.number }} + - name: Extract email + id: extract + run: | + email=$( + echo ${{ toJSON(steps.parse.outputs.data) }} | + jq -r ".email.text" + ) + echo "email=$email" >> $GITHUB_OUTPUT + + - name: Send mail + uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0 + with: + server_address: smtp.gmail.com + server_port: 465 + secure: true + username: ${{secrets.MAIL_USERNAME}} + password: ${{secrets.MAIL_PASSWORD}} + from: MorphoCloudPortal + to: ${{ steps.extract.outputs.email }} + subject: + "[MorphoCloudPortal] Instance ${{ github.event.issue.number }} + started" + body: Instance ${{ github.event.issue.number }} started + stop: runs-on: self-hosted if: @@ -30,3 +54,31 @@ jobs: echo Stopping instance associated with issue $NUMBER env: NUMBER: ${{ github.event.issue.number }} + + - name: Issue Forms Body Parser + id: parse + uses: zentered/issue-forms-body-parser@v2.0.0 + + - name: Extract email + id: extract + run: | + email=$( + echo ${{ toJSON(steps.parse.outputs.data) }} | + jq -r ".email.text" + ) + echo "email=$email" >> $GITHUB_OUTPUT + + - name: Send mail + uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0 + with: + server_address: smtp.gmail.com + server_port: 465 + secure: true + username: ${{secrets.MAIL_USERNAME}} + password: ${{secrets.MAIL_PASSWORD}} + from: MorphoCloudPortal + to: ${{ steps.extract.outputs.email }} + subject: + "[MorphoCloudPortal] Instance ${{ github.event.issue.number }} + stopped" + body: Instance ${{ github.event.issue.number }} stopped diff --git a/.github/workflows/create-instance.yml b/.github/workflows/create-instance.yml index 65cf5939..42ae4d4d 100644 --- a/.github/workflows/create-instance.yml +++ b/.github/workflows/create-instance.yml @@ -17,3 +17,31 @@ jobs: echo Creating instance associated with issue $NUMBER env: NUMBER: ${{ github.event.issue.number }} + + - name: Issue Forms Body Parser + id: parse + uses: zentered/issue-forms-body-parser@v2.0.0 + + - name: Extract email + id: extract + run: | + email=$( + echo ${{ toJSON(steps.parse.outputs.data) }} | + jq -r ".email.text" + ) + echo "email=$email" >> $GITHUB_OUTPUT + + - name: Send mail + uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0 + with: + server_address: smtp.gmail.com + server_port: 465 + secure: true + username: ${{secrets.MAIL_USERNAME}} + password: ${{secrets.MAIL_PASSWORD}} + from: MorphoCloudPortal + to: ${{ steps.extract.outputs.email }} + subject: + "[MorphoCloudPortal] Instance ${{ github.event.issue.number }} + created" + body: Instance ${{ github.event.issue.number }} created