-
-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (167 loc) · 6.47 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
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
name: ❯ Python audioanalyser
on:
pull_request:
branches:
- main
- "feat/*"
push:
branches:
- main
- "feat/*"
jobs:
# This job reads the version number from setup.cfg and sets it as an
# environment variable
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: ❯ Set up Python 🐍
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: ❯ Get version number from setup.cfg
id: set-version
run: |
echo "::set-output name=version::$(python -c 'import configparser; cfg = configparser.ConfigParser(); cfg.read("setup.cfg"); print(cfg.get("metadata", "version"))')"
# This job runs unit tests using pytest
pytest:
needs: version
runs-on: ubuntu-latest
steps:
# Check out the repository code
- uses: actions/checkout@v4
# Set up Python and install dependencies
- name: ❯ Set up Python and install dependencies 🐍📦
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: ❯ Install dependencies 📦
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
# python -m pip install pytest pytest-cov
# Run pytest
# - name: ❯ Run pytest 🧪
# run: pytest --cov=audioanalyser --cov-report=xml
# Upload code coverage report to Codecov
# - name: ❯ Upload code coverage report to Codecov 📊
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# This job runs flake8 to check for code style issues
lint:
needs: version
runs-on: ubuntu-latest
steps:
# Check out the repository code
- uses: actions/checkout@v4
# Set up Python and install dependencies
- name: ❯ Set up Python and install dependencies 🐍📦
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: ❯ Install flake8 📦
run: python -m pip install flake8
# Run flake8
- name: ❯ Run flake8 🔍
run: flake8
# This job builds the distribution packages, and publishes them
# to PyPI
build:
needs: [version, pytest]
runs-on: ubuntu-latest
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
VERSION: ${{ needs.version.outputs.version }}
PKG_NAME: audioanalyser
steps:
# Check out the repository code
- uses: actions/checkout@v4
- name: ❯ Set up Python 🐍
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: python
uses: actions/setup-python@v2
with:
python-version: "3.9"
# Install dependencies
- name: ❯ Install dependencies 📦
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt
# Update the version number based on the setup.cfg file
- name: Update version number from setup.cfg file 📝
id: update-version
run: |
NEW_VERSION=$(grep -E '^version =' setup.cfg | cut -d '=' -f 2 | tr -d '[:space:]')
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
shell: /bin/bash -e {0}
# Generate the changelog based on git log and template file
- name: Generate Changelog 📚
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
# Append version information to CHANGELOG.md
echo "## Release v${{ env.VERSION }} - $(date +'%Y-%m-%d')" >> ${{ github.workspace }}/CHANGELOG.md
# Copy content of template file to CHANGELOG.md
cat TEMPLATE.md >> ${{ github.workspace }}/CHANGELOG.md
# Append git log to CHANGELOG.md
echo "$(git log --pretty=format:'%s' --reverse $(git describe --tags --abbrev=0)..HEAD)" >> ${{ github.workspace }}/CHANGELOG.md
# Append empty line to CHANGELOG.md
echo "" >> ${{ github.workspace }}/CHANGELOG.md
# Build distribution packages
- name: ❯ Build distribution packages 🧰
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
python setup.py sdist bdist_wheel
# Publish distribution packages to PyPI
- name: ❯ Publish distribution packages to PyPI 🚀
id: publish
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: pypa/gh-action-pypi-publish@v1.3.1
with:
user: ${{ env.TWINE_USERNAME }}
password: ${{ env.TWINE_PASSWORD }}
packages_dir: dist
verify_metadata: true
skip_existing: true
# Append artifact links to the changelog
- name: Append Artifact Links 🔗
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
echo "" >> ${{ github.workspace }}/CHANGELOG.md
echo "## Artifacts 🎁" >> ${{ github.workspace }}/CHANGELOG.md
for filename in dist/*; do
link="$(basename $filename)"
echo "* [$link](${{ env.RELEASES_URL }}/$link)" >> ${{ github.workspace }}/CHANGELOG.md
done
env:
RELEASES_URL: https://github.com/${{ github.repository }}/releases/download/v${{ env.VERSION }}
# Create a release
- name: Create Release 🚀
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
body_path: ${{ github.workspace }}/CHANGELOG.md
draft: false
prerelease: false
- name: Upload Release Assets 📦
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
upload_url=${{ steps.create_release.outputs.upload_url }}
for file in dist/*; do
curl \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: $(file --mime-type -b $file)" \
--data-binary @$file \
"${upload_url}?name=$(basename $file)"
done