From 5a88c0943e2888b1a640406535a3b7e666edc555 Mon Sep 17 00:00:00 2001 From: Eric Giguere Date: Thu, 18 Apr 2024 13:01:56 -0400 Subject: [PATCH] Kron action open issues instead of email (local fork) --- .github/workflows/weekly.yml | 52 ++++++++++------------------------- tools/report_failing_tests.py | 45 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 tools/report_failing_tests.py diff --git a/.github/workflows/weekly.yml b/.github/workflows/weekly.yml index e0dfc7a..f6d79aa 100644 --- a/.github/workflows/weekly.yml +++ b/.github/workflows/weekly.yml @@ -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='qutip-admin@googlegroups.com' " >> $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! diff --git a/tools/report_failing_tests.py b/tools/report_failing_tests.py new file mode 100644 index 0000000..10cae55 --- /dev/null +++ b/tools/report_failing_tests.py @@ -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())