forked from MathieuLamiot/TechTeamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (127 loc) · 4.43 KB
/
ci-on_pr_main_bash.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# 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 git+https://github.com/MathieuLamiot/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