-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (117 loc) · 3.86 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
name: CI
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
jobs:
lint:
name: >-
Lint the codebase 🧹 with ruff
runs-on: ubuntu-latest
steps:
- name: Checkout the codebase 📥
uses: actions/checkout@v3
- name: Set up the pixi environment 🌟
uses: prefix-dev/[email protected]
with:
environments: dev
locked: false
- name: Run code linting with ruff check 🔍
run: pixi run -e dev ruff-check
- name: Format the code with ruff format 🎨
run: pixi run -e dev format
test:
name: >-
Run tests 🧪 and upload coverage report 📊
runs-on: ubuntu-latest
steps:
- name: Checkout the codebase 📥
uses: actions/checkout@v3
- name: Set up the pixi environment 🌟
uses: prefix-dev/[email protected]
with:
environments: dev
locked: false
- name: Execute tests 🧪
run: pixi run -e dev test-reports
- name: Upload the coverage report 📊
uses: actions/upload-artifact@v3
with:
name: test-reports
path: reports/
version-check:
name: >-
Check if the version has changed 🔄
runs-on: ubuntu-latest
outputs:
version-changed: ${{ steps.version-metadata.outputs.changed }}
new-version: ${{ steps.version-metadata.outputs.newVersion }}
steps:
- name: Checkout the codebase 📥
uses: actions/checkout@v3
- name: Retrieve the current version 🕵️♂️
id: get-version
run: |
echo "current_version=$(grep -Po '(?<=^__version__ = ")[^"]*' src/keyrings_artifacts/_version.py)" >> $GITHUB_ENV
- name: Fetch the previous version from TestPyPI 🏷️
id: get-previous-version
run: |
package_name=$(grep -Po '(?<=^name = ")[^"]*' pyproject.toml)
previous_version=$(curl -s https://test.pypi.org/pypi/$package_name/json | jq -r '.releases | keys | .[-1]')
echo "previous_version=$previous_version" >> $GITHUB_ENV
- name: Compare the current and previous versions 🔄
id: version-metadata
run: |
if [ "$current_version" != "$previous_version" ]; then
echo "::set-output name=changed::true"
echo "::set-output name=newVersion::$current_version"
else
echo "::set-output name=changed::false"
fi
build:
name: >-
Build the Python 🐍 package 📦
runs-on: ubuntu-latest
needs: version-check
if: needs.version-check.outputs.version-changed == 'true'
steps:
- name: Checkout the codebase 📥
uses: actions/checkout@v3
- name: Set up the pixi environment 🌟
uses: prefix-dev/[email protected]
with:
environments: dev
locked: false
- name: Build the package 📦
run: pixi run -e dev build
- name: Store the distribution packages 📦
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
publish-to-testpypi:
name: >-
Publish the Python 🐍 distribution 📦 to TestPyPI
needs:
- version-check
- build
runs-on: ubuntu-latest
if: needs.version-check.outputs.version-changed == 'true'
environment:
name: testpypi
url: https://test.pypi.org/p/keyrings.artifacts
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the distribution packages 📦
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish the distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/