-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kron action open issues instead of email (local fork)
- Loading branch information
Eric Giguere
committed
Apr 18, 2024
1 parent
ab6a5e1
commit 5a88c09
Showing
2 changed files
with
59 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,11 @@ on: | |
|
||
workflow_dispatch: | ||
inputs: | ||
email: | ||
description: "Destination email on failure (optional):" | ||
default: "None" | ||
open_issue: | ||
description: 'Open issue on failure' | ||
required: false | ||
default: "False" | ||
|
||
|
||
defaults: | ||
run: | ||
|
@@ -35,7 +37,7 @@ jobs: | |
case-name: [defaults] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
|
@@ -85,39 +87,13 @@ jobs: | |
if: failure() | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check destination | ||
id: dest_email | ||
- uses: actions/checkout@v3 | ||
- name: Open Issue on Failure | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
run: | | ||
if [[ -z "${{ inputs.email }}" ]]; then | ||
# Trigerred by schedule | ||
echo "destination='[email protected]' " >> $GITHUB_OUTPUT; | ||
elif [[ "${{ inputs.email }}" != "None" ]]; then | ||
# Trigerred manually with email entered | ||
echo "destination=${{ inputs.email }}" >> $GITHUB_OUTPUT; | ||
else | ||
# Trigerred manually without email entered | ||
echo "destination=" >> $GITHUB_OUTPUT; | ||
if [[ -z "${{ inputs.open_issue }}" ]] || [[ "${{ inputs.open_issue }}" != "False" ]]; | ||
then | ||
pip install requests argparse datetime | ||
python tools/report_failing_tests.py $GITHUB_TOKEN | ||
fi | ||
- name: Send Email on Failure | ||
# No email sent if trigerred manually and no address is provided. | ||
if: ${{ steps.dest_email.outputs.destination }} != "" | ||
|
||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
# Required mail server address if not connection_url: | ||
server_address: smtp-mail.outlook.com | ||
server_port: 587 | ||
secure: False | ||
# Optional (recommended) mail server username: | ||
username: ${{ secrets.OUTLOOK_ADR }} | ||
# Optional (recommended) mail server password: | ||
password: ${{ secrets.OUTLOOK_PWD }} | ||
# Required mail subject: | ||
subject: Qutip-jax weekly test failed! | ||
# Required recipients' addresses: | ||
to: ${{ steps.dest_email.outputs.destination }} | ||
# Required sender full name (address can be skipped): | ||
from: QuTiP-Jax | ||
# Optional plain body: | ||
body: Qutip-jax weekly test failed! |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import requests | ||
import json | ||
import sys | ||
import argparse | ||
from datetime import date | ||
|
||
def open_issue(token): | ||
url = "https://api.github.com/repos/ericgig/qutip-jax/issues" | ||
data = json.dumps({ | ||
"title": f"Automated tests failed on {date.today()}", | ||
"labels": ["bug"], | ||
"body": "Scheduled test failed!" | ||
}) | ||
|
||
headers = { | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization" : f"token {token}", | ||
} | ||
|
||
post_request = requests.post(url=url, data=data, headers=headers) | ||
|
||
if post_request.status_code == 201: | ||
print("Success") | ||
|
||
else: | ||
print( | ||
"Fail:", | ||
post_request.status_code, | ||
post_request.reason, | ||
post_request.content | ||
) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="""Open an issue on failed tests.""" | ||
) | ||
parser.add_argument("token") | ||
args = parser.parse_args() | ||
print(args.token) | ||
open_issue(args.token) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |