-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (128 loc) · 4.35 KB
/
main.yml
File metadata and controls
144 lines (128 loc) · 4.35 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
name: "CI and Release"
on:
push:
branches:
- "*"
pull_request:
jobs:
config:
uses: ./.github/workflows/config.yml
setup:
needs: config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
with:
python-version: ${{ needs.config.outputs.python-version }}
format:
needs: [ config, setup ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
with:
python-version: ${{ needs.config.outputs.python-version }}
- uses: ./.github/actions/code-quality
with:
check-type: "format"
source-dir: ${{ needs.config.outputs.source-dir }}
lint:
needs: [ config, setup ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
with:
python-version: ${{ needs.config.outputs.python-version }}
- uses: ./.github/actions/code-quality
with:
check-type: "lint"
source-dir: ${{ needs.config.outputs.source-dir }}
type-check:
needs: [ config, setup ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
with:
python-version: ${{ needs.config.outputs.python-version }}
- uses: ./.github/actions/code-quality
with:
check-type: "type-check"
source-dir: ${{ needs.config.outputs.source-dir }}
test:
needs: [ config, setup ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
with:
python-version: ${{ needs.config.outputs.python-version }}
- name: Run Tests
run: uv run pytest
release:
needs: [ config, setup, format, lint, type-check, test ]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup-env
with:
python-version: ${{ needs.config.outputs.python-version }}
- name: Read version from pyproject.toml
id: get_version
run: |
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Check if release exists
run: |
RELEASE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.VERSION }})
if [ "$RELEASE_EXISTS" == "404" ]; then
echo "CREATE_RELEASE=true" >> $GITHUB_ENV
else
echo "CREATE_RELEASE=false" >> $GITHUB_ENV
fi
- name: Find Previous Release
if: env.CREATE_RELEASE == 'true'
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
echo "PREV_TAG=${PREV_TAG}" >> $GITHUB_ENV
fi
- name: Generate Compare URL
if: env.CREATE_RELEASE == 'true'
run: |
if [ -n "${{ env.PREV_TAG }}" ]; then
echo "URL=${{ github.server_url }}/${{ github.repository }}/compare/${{ env.PREV_TAG }}...${{ env.VERSION }}" >> $GITHUB_ENV
else
echo "URL=${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.VERSION }}" >> $GITHUB_ENV
fi
- name: Generate Changelog
if: env.CREATE_RELEASE == 'true'
run: |
chmod +x .github/generate_changelog.sh
source .github/generate_changelog.sh
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
if [ -n "${{ env.PREV_TAG }}" ]; then
generate_categorized_changelog "${{ env.PREV_TAG }}" >> $GITHUB_ENV
else
generate_categorized_changelog >> $GITHUB_ENV
fi
echo "EOF" >> $GITHUB_ENV
- name: Create Release
if: env.CREATE_RELEASE == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSION }}
name: ${{ env.VERSION }}
body: |
${{ env.CHANGELOG }}
**Full Changelog**: ${{ env.URL }}
draft: false
prerelease: false
target_commitish: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}