Skip to content

Commit

Permalink
datadog test (#66)
Browse files Browse the repository at this point in the history
* chore: refactor workflows to use a common shared workflow

* chore: adds test run to datadog when the api key is defined

* chore: warn if DD_API_KEY is not defined.

* chore: try the `--ddtrace-patch-all` flag

* style: line endings
  • Loading branch information
m-mcgowan authored Jul 31, 2023
1 parent b52e7bb commit d5075d5
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 119 deletions.
64 changes: 5 additions & 59 deletions .github/workflows/manual-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,8 @@ on: workflow_dispatch

jobs:
build:

runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.8, 3.9]

steps:
- name: Send building notification
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"building"}}'
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
make flake8
# flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503,E501 --show-source --statistics
- name: Lint Docs with Pydocstyle
run: |
make docstyle
# pydocstyle notecard/ examples/
- name: Send running tests notification
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"running_tests"}}'
- name: Test with pytest
run: |
make test
- name: Check if the job has succeeded
if: ${{ success() }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"success"}}'
- name: Check if the job has failed
if: ${{ failure() }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"tests_failed"}}'
uses: ./.github/workflows/python-ci.yml
secrets: inherit
with:
notehub_notify: false
coveralls: false
104 changes: 104 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Reusable workflow to run the python CI, which covers
# Optional notificiation to notehub (requires secrets NOTEHUB_SESSION_TOKEN, NOTEHUB_DEVICE_ID and NOTEHUB_PRODUCT_UID)
# Python installation and dependencies
# Linting (flake8 and docstyle)
# Testing and coverage with pytest
# Optionally publish coverage to coveralls (requires secrets.GITHUB_TOKEN)
# Reports test coverage to DataDog if secrets.DD_API_KEY is defined.

on:
workflow_call:
secrets:
NOTEHUB_SESSION_TOKEN:
NOTEHUB_PRODUCT_UID:
NOTECARD_DEVICE_ID:
inputs:
coveralls:
type: boolean
required: false
default: false
notehub_notify:
type: boolean
required: false
default: false

jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

env:
DD_API_KEY: ${{ secrets.DD_API_KEY }}

steps:
- name: Send building notification
if: ${{ inputs.notehub_notify }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"building"}}'
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U flake8 pytest coveralls ddtrace
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
make flake8
- name: Lint Docs with Pydocstyle
run: |
make docstyle
- name: Send running tests notification
if: ${{ inputs.notehub_notify }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"running_tests"}}'
- name: Check DD API Key
if: ${{ !env.DD_API_KEY }}
run: |
echo Test run will NOT be collected by DD
- name: Test with pytest
env:
DD_CIVISIBILITY_AGENTLESS_ENABLED: ${{ !!env.DD_API_KEY }}
DD_SERVICE: note-python
DD_ENV: ci
run: |
coverage run -m pytest --ddtrace --ddtrace-patch-all
- name: Publish to Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ inputs.coveralls }}
run: |
coveralls --service=github
- name: Check if the job has succeeded
if: ${{ success() && inputs.notehub_notify }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"success"}}'
- name: Check if the job has failed
if: ${{ failure() && inputs.notehub_notify }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"tests_failed"}}'
66 changes: 6 additions & 60 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,12 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Send building notification
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"building"}}'
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest coveralls
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
make flake8
- name: Lint Docs with Pydocstyle
run: |
make docstyle
- name: Send running tests notification
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"running_tests"}}'
- name: Test with pytest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coverage run -m pytest
coveralls --service=github
- name: Check if the job has succeeded
if: ${{ success() }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"success"}}'
- name: Check if the job has failed
if: ${{ failure() }}
run: |
curl --request POST \
--url 'https://api.notefile.net/?product=${{ secrets.NOTEHUB_PRODUCT_UID }}&device=${{ secrets.NOTECARD_DEVICE_ID }}' \
--header 'Content-Type: application/json' \
--header 'X-Session-Token: ${{ secrets.NOTEHUB_SESSION_TOKEN }}' \
--data '{"req":"note.add","file":"build_results.qi","body":{"result":"tests_failed"}}'
uses: ./.github/workflows/python-ci.yml
secrets: inherit
with:
notehub_notify: true
coveralls: true

0 comments on commit d5075d5

Please sign in to comment.