forked from python-semantic-release/python-semantic-release
-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (173 loc) · 5.94 KB
/
main.yml
File metadata and controls
202 lines (173 loc) · 5.94 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
name: Test & Release
on:
push:
branches:
- master
- main
- "pre/*"
jobs:
test:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }} tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[test]
python -m pip install pytest-github-actions-annotate-failures
- name: pytest on Linux
id: tests-linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
python -m pytest \
-vv \
-nauto \
--cov=semantic_release \
--cov-context=test \
--cov-report=term-missing \
--cov-fail-under=80 \
--junit-xml=tests/reports/pytest-results.xml
- name: pytest on windows
id: tests-win
if: ${{ matrix.os == 'windows-latest' }}
# env:
# Required for GitPython to work on Windows because of getpass.getuser()
# USERNAME: "runneradmin"
# Because GHA is currently broken on Windows to pass these varables, we do it manually
run: |
$env:USERNAME = "runneradmin"
python -m pytest `
-vv `
-nauto `
`--cov=semantic_release `
`--cov-context=test `
`--cov-report=term-missing `
`--cov-fail-under=80 `
`--junit-xml=tests/reports/pytest-results.xml
- name: Report | Upload Linux Test Results
uses: mikepenz/action-junit-report@v4.3.1
if: ${{ always() && steps.tests-linux.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
- name: Report | Upload Windows Test Results
uses: mikepenz/action-junit-report@v4.3.1
if: ${{ always() && steps.tests-win.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install mypy & dev packages
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install ".[dev, mypy]"
- name: ruff
run: |
python -m ruff check . \
--config pyproject.toml \
--output-format=full \
--exit-non-zero-on-fix
- name: mypy
run: |
python -m mypy --ignore-missing-imports semantic_release
beautify:
name: Beautify
runs-on: ubuntu-latest
concurrency: push
needs: [test, lint]
outputs:
new_sha: ${{ steps.sha.outputs.SHA }}
permissions:
id-token: write
contents: write
steps:
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Ruff
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install ".[dev]"
- name: Format
run: |
python -m ruff format .
- name: Commit and push changes
uses: github-actions-x/commit@v2.9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "style: beautify ${{ github.sha }}"
name: github-actions
email: action@github.com
- name: Get new SHA
id: sha
run: |
new_sha=$(git rev-parse HEAD)
echo "SHA=$new_sha" >> $GITHUB_OUTPUT
release:
name: Semantic Release
runs-on: ubuntu-latest
concurrency: push
needs: [test, lint, beautify]
if: github.repository == 'python-semantic-release/python-semantic-release'
environment:
name: pypi
url: https://pypi.org/project/python-semantic-release/
permissions:
# https://docs.github.com/en/rest/overview/permissions-required-for-github-apps?apiVersion=2022-11-28#metadata
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Python Semantic Release
id: release
uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
root_options: "-vv"
# see https://docs.pypi.org/trusted-publishers/
- name: Publish package distributions to PyPI
id: pypi-publish
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
- name: Publish package distributions to GitHub Releases
id: github-release
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: steps.release.outputs.released == 'true'
uses: python-semantic-release/upload-to-gh-release@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}