Skip to content

Commit

Permalink
Kron action open issues instead of email (local fork)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Giguere committed Apr 18, 2024
1 parent ab6a5e1 commit 5a88c09
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
52 changes: 14 additions & 38 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -35,7 +37,7 @@ jobs:
case-name: [defaults]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: conda-incubator/setup-miniconda@v2
with:
Expand Down Expand Up @@ -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!
45 changes: 45 additions & 0 deletions tools/report_failing_tests.py
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())

0 comments on commit 5a88c09

Please sign in to comment.