diff --git a/.github/workflows/manual-run.yml b/.github/workflows/manual-run.yml index 07903b7..2ead9e4 100644 --- a/.github/workflows/manual-run.yml +++ b/.github/workflows/manual-run.yml @@ -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 diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..4fa74f9 --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -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"}}' diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 93652de..5d8027f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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