Skip to content

Add code and message to the Notion API error message #267

Add code and message to the Notion API error message

Add code and message to the Notion API error message #267

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: CI Script - Python Lint and tests
on:
pull_request:
branches:
- 'develop'
- 'master'
env:
TBTT_GITHUB_ACCESS_TOKEN: tbtt_github_token
TBTT_SLACK_BOT_USER_TOKEN: tbtt_slack_bot_user_token
TBTT_SLACK_SIGNING_SECRET: tbtt_slack_signing_secret
TBTT_SLACK_USER_TOKEN: tbtt_slack_user_token
TBTT_GITHUB_WEBHOOK_SECRET: tbtt_github_webhook_secret
TBTT_OVH_APP_KEY: a
TBTT_OVH_APP_SECRET: b
TBTT_OVH_CONSUMER_KEY: c
TBTT_GODP_AUTH_TOKEN: d
TBTT_NOTION_API_KEY: e
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run lint script
run: |
./scripts/lint.sh
shell: bash
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run pytest
run: |
pytest -m "not staging_env" --cov=. --cov-report=xml
shell: bash
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report-${{ github.run_id }}
path: coverage.xml
retention-days: 1
coverage:
runs-on: ubuntu-latest
needs: tests
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Download coverage report
uses: actions/download-artifact@v3
with:
name: coverage-report-${{ github.run_id }}
- name: Install dependencies
run: pip install diff-cover
- name: Generate diff-coverage report
if: github.event_name == 'pull_request'
run: |
diff-cover coverage.xml --compare-branch=origin/${{ github.base_ref }} --markdown-report diff-cover-report.md --exclude test*.py --fail-under=50 --expand-coverage-report
echo "DIFF_COVER_EXIT_STATUS=$?" >> $GITHUB_ENV
shell: bash
- name: Delete previous diff-cover reports
uses: actions/github-script@v6
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
for (const comment of comments) {
if (comment.user.login === 'github-actions[bot]' && comment.body.includes('# Diff Coverage')) {
console.log(`Deleting comment with ID: ${comment.id}`);
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id
});
}
}
env:
GITHUB_TOKEN: ${{ secrets.DIFF_COVER_COMMENT }}
- name: Post diff-cover report to PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const comment = fs.readFileSync('diff-cover-report.md', 'utf8');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
});
- name: Fail job if coverage is below threshold
if: github.event_name == 'pull_request'
run: |
if [[ "${{ env.DIFF_COVER_EXIT_STATUS }}" -ne 0 ]]; then
echo "Coverage below threshold; failing the job."
exit 1
fi
shell: bash