-
-
Notifications
You must be signed in to change notification settings - Fork 7
129 lines (112 loc) · 4.95 KB
/
ci.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
name: PyBaMM Twitter bot
on:
push:
pull_request:
schedule:
- cron: '0 7,19 * * *'
jobs:
style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Check style
run: |
python -m pip install --upgrade pip
python -m pip install flake8
flake8 --max-line-length=89
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
needs: style
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise will fail to push refs to dest repo
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel coverage
pip install -r requirements.txt
- name: Tweet
if: matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/main' && github.event_name == 'schedule'
run: |
cd bot
python -m twitter_api.tweet_plot
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git pull origin main
git commit -m "Update config, data - [skip ci]" -a
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
ACCESS_SECRET: ${{ secrets.ACCESS_SECRET }}
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
- name: Sync last seen ID
if: matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/main'
run: |
cd bot
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git pull origin main --rebase
python -m twitter_api.sync_last_seen_id
git commit --allow-empty -m "Update last_seen_id - skip ci" -a
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
ACCESS_SECRET: ${{ secrets.ACCESS_SECRET }}
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
- name: Push changes
if: matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/main'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Run macos unittests for PRs not from a fork
if: (matrix.os == 'macos-latest' && github.event.pull_request.head.repo.full_name == github.repository) || (matrix.os == 'macos-latest' && github.event_name == 'schedule') || (matrix.os == 'macos-latest' && github.event_name == 'push')
run: |
python -m unittest discover -v test/
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
ACCESS_SECRET: ${{ secrets.ACCESS_SECRET }}
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
- name: Run macos unittests for PRs from a fork
if: matrix.os == 'macos-latest' && github.event.pull_request.head.repo.full_name != github.repository && github.event_name != 'schedule' && github.event_name != 'push'
run: |
python -m unittest discover -v ./test/without_keys/
- name: Run ubuntu unittests and generate coverage report for PRs not from a fork
if: (matrix.os == 'ubuntu-latest' && github.event.pull_request.head.repo.full_name == github.repository) || (matrix.os == 'ubuntu-latest' && github.event_name == 'schedule') || (matrix.os == 'ubuntu-latest' && github.event_name == 'push')
run: |
echo "COVERAGE_PROCESS_START=$PWD/.coveragerc" >> $GITHUB_ENV
echo "PYTHONPATH=$PYTHONPATH::$PWD" >> $GITHUB_ENV
coverage run --concurrency=multiprocessing -m unittest -v
coverage combine
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
ACCESS_SECRET: ${{ secrets.ACCESS_SECRET }}
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
- name: Run ubuntu unittests and generate coverage report for PRs from a fork
if: matrix.os == 'ubuntu-latest' && github.event.pull_request.head.repo.full_name != github.repository && github.event_name != 'schedule' && github.event_name != 'push'
run: |
echo "COVERAGE_PROCESS_START=$PWD/.coveragerc" >> $GITHUB_ENV
echo "PYTHONPATH=$PYTHONPATH::$PWD" >> $GITHUB_ENV
coverage run --concurrency=multiprocessing -m unittest discover test/without_keys -v
coverage combine
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}