-
Notifications
You must be signed in to change notification settings - Fork 1
215 lines (181 loc) · 6.48 KB
/
release-pipeline.yml
File metadata and controls
215 lines (181 loc) · 6.48 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
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Release Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
- name: Lint with flake8
run: |
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.venv,.git,__pycache__,build,dist
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics --exclude=.venv,.git,__pycache__,build,dist
- name: Format check with black
run: poetry run black --check --exclude=\.venv --extend-exclude=main.py .
- name: Import sorting check with isort
run: poetry run isort --check --skip .venv --skip main.py .
- name: Test with pytest
run: |
if [ -d "src" ]; then
poetry run pytest --cov=src
else
echo "No src directory yet, skipping tests"
exit 0
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
semantic-release:
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.semantic-release.outputs.new_release_published }}
new_release_version: ${{ steps.semantic-release.outputs.new_release_version }}
permissions:
id-token: write
contents: write
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pip'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: poetry install
- name: Python Semantic Release
id: semantic-release
run: |
git config --global user.name "semantic-release"
git config --global user.email "semantic-release@users.noreply.github.com"
# Debug information
echo "Current git status:"
git status
echo "Current branch:"
git branch
# Run semantic release with verbose output
echo "Running semantic-release version"
VERSION_OUTPUT=$(poetry run semantic-release --verbose version)
echo "$VERSION_OUTPUT"
# Extract version information
if echo "$VERSION_OUTPUT" | grep -q "Bumping version"; then
NEW_VERSION=$(poetry run python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
echo "new_release_published=true" >> $GITHUB_OUTPUT
echo "new_release_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
# Publish the release
echo "Publishing release"
poetry run semantic-release --verbose publish
else
echo "No version bump needed"
echo "new_release_published=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker-build:
needs: semantic-release
if: needs.semantic-release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main # Make sure we get the latest changes after semantic-release
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/offendingcommit/bingo:latest
ghcr.io/offendingcommit/bingo:${{ needs.semantic-release.outputs.new_release_version }}
build-args: BUILD_ENVIRONMENT=production
helm-chart:
needs: [semantic-release, docker-build]
if: needs.semantic-release.outputs.new_release_published == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main # Make sure we get the latest changes after semantic-release
- name: Set up Helm
uses: azure/setup-helm@v1
- name: Update Helm Chart version and app version
run: |
VERSION="${{ needs.semantic-release.outputs.new_release_version }}"
# Update version and appVersion in Chart.yaml
sed -i "s/^version:.*/version: $VERSION/" helm/bingo/Chart.yaml
sed -i "s/^appVersion:.*/appVersion: $VERSION/" helm/bingo/Chart.yaml
# Update image tag in values.yaml
sed -i "s/tag:.*/tag: $VERSION/" helm/bingo/values.yaml
# Show the changes
echo "Updated Chart.yaml:"
cat helm/bingo/Chart.yaml
echo "Updated values.yaml:"
cat helm/bingo/values.yaml
- name: Lint Helm Chart
run: helm lint helm/bingo
- name: Package Helm Chart
run: |
mkdir -p dist
helm package helm/bingo --destination dist
- name: Upload Helm Chart to Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.semantic-release.outputs.new_release_version }}
files: dist/*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}