-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (131 loc) · 4.88 KB
/
ci-cd.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# This workflow will install Python dependencies, run tests, and lint with a small matrix of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: "CI & CD"
# Controls when the workflow will run
on:
push:
branches: [ "master", "development" ]
pull_request:
branches: [ "master", "development" ]
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
setup:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.setup-matrix.outputs.os }}
python-version: ${{ steps.setup-matrix.outputs.python-version }}
steps:
- name: Determine event type and set matrix
id: setup-matrix
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "os=['ubuntu-latest']" >> "$GITHUB_OUTPUT"
echo "python-version=['3.9']" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" == "pull_request" ]; then
echo "os=['ubuntu-latest','macos-latest','windows-latest']" >> "$GITHUB_OUTPUT"
echo "python-version=['3.9','3.12']" >> "$GITHUB_OUTPUT"
fi
CI:
needs: setup
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.setup.outputs.os) }}
python-version: ${{ fromJSON(needs.setup.outputs.python-version) }}
include:
- os: ubuntu-latest
python-version: "3.9"
representative: True
exclude:
- os: macos-latest
python-version: '3.x'
defaults:
run:
shell: bash
steps:
- name: Check-out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: snok/install-poetry@v1
# - name: Install gfortran
# uses: fortran-lang/setup-fortran@v1
# if: matrix.os == 'macos-latest'
- name: Install package
run: poetry install --with dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
echo "Linting errors in hikari/tests:"
poetry run flake8 ./hikari --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 ./tests --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
echo "Linting warnings in hikari/tests:"
poetry run flake8 ./hikari --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
poetry run flake8 ./tests --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
- name: Request rapid hikari tests only
run: echo "HIKARI_TESTS_RAPID=True" >> $GITHUB_ENV
- name: Test with pytest
run: poetry run pytest tests/ --cov=hikari --cov-report=xml
continue-on-error: true
- name: Use Codecov to track coverage
uses: codecov/codecov-action@v4
if: ${{ matrix.representative }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./coverage.xml # coverage report
- name: Build documentation
run: poetry run make html --directory docs/
if: ${{ matrix.representative }}
CD:
# Only run this job if the "CI" job passes
needs: CI
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
# Set up operating system
runs-on: ubuntu-latest
# Define job steps
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Check-out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.CONTINUOUS_DEPLOYMENT_KEY }}
- name: Use Python Semantic Release to prepare release
id: release
uses: python-semantic-release/python-semantic-release@v9
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: steps.release.outputs.released == 'true'
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_HIKARI_API_TOKEN }}
- name: Test install from TestPyPI
run: |
pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
hikari
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: steps.release.outputs.released == 'true'
with:
password: ${{ secrets.PYPI_HIKARI_API_TOKEN }}
- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/publish-action@v9
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}