forked from sirkirby/unifi-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (168 loc) · 5.39 KB
/
Copy pathrelease-api.yml
File metadata and controls
195 lines (168 loc) · 5.39 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
name: "API: Release (test → PyPI + GHCR in parallel → GitHub Release)"
# Triggered on api/v* tags. The release is atomic:
#
# test ──┬── publish-pypi ──┐
# └── publish-docker ┴── github-release
#
# Both publishes must succeed before the GitHub Release is created — a tag
# without a green PyPI + GHCR pair is not "released."
#
# This pattern supersedes per-package "test" + "docker" + "publish" workflows
# that fan out independently. Apply the same shape when reworking the MCP
# server release flows.
#
# One-time PyPI prerequisite: register `unifi-api-server` as a pending publisher
# at https://pypi.org/manage/account/publishing/ with:
# Owner: sirkirby
# Repository: unifi-mcp
# Workflow: release-api.yml
# Environment: pypi
on:
push:
tags:
- 'api/v*'
permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/unifi-api-server
jobs:
# ----------------------------------------------------------------------- 1
test:
name: Run unifi-api-server tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install workspace
run: uv sync --all-packages
- name: Run tests
run: uv run --package unifi-api-server pytest apps/api/tests -n auto -q
# ----------------------------------------------------------------------- 2a
publish-pypi:
name: Build wheel + publish to PyPI
needs: test
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/unifi-api-server
permissions:
id-token: write # OIDC for PyPI trusted publishing
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Build wheel
run: uv build --package unifi-api-server --wheel
- name: Upload wheel artifact (for github-release job)
uses: actions/upload-artifact@v7
with:
name: wheel
path: dist/*.whl
- name: Publish to PyPI via OIDC
uses: pypa/gh-action-pypi-publish@release/v1
# ----------------------------------------------------------------------- 2b
publish-docker:
name: Build + push Docker image
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
fetch-tags: true
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
with:
platforms: linux/amd64,linux/arm64
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Derive version + image tag list from git tag
id: version
env:
REF_NAME: ${{ github.ref_name }}
IMAGE_REF: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
run: |
# api/v0.1.0 -> 0.1.0 -> tags: 0.1.0, latest
# api/v0.1.0-rc.1 -> 0.1.0-rc.1 -> tags: 0.1.0-rc.1 (no `latest` for pre-releases)
VERSION="${REF_NAME#api/v}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
if echo "${VERSION}" | grep -qE -- '-(rc|alpha|beta|dev)'; then
{
echo "tags<<EOF"
echo "${IMAGE_REF}:${VERSION}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
else
{
echo "tags<<EOF"
echo "${IMAGE_REF}:${VERSION}"
echo "${IMAGE_REF}:latest"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
- name: Build and push image
uses: docker/build-push-action@v7
with:
context: .
file: apps/api/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.version.outputs.tags }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ----------------------------------------------------------------------- 3
github-release:
name: Create GitHub Release
needs: [publish-pypi, publish-docker]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/download-artifact@v8
with:
name: wheel
path: dist/
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF_NAME: ${{ github.ref_name }}
run: |
if echo "${REF_NAME}" | grep -qE -- '-(rc|alpha|beta|dev)'; then
PRERELEASE_FLAG="--prerelease"
else
PRERELEASE_FLAG=""
fi
gh release create "${REF_NAME}" \
--generate-notes \
--title "unifi-api-server ${REF_NAME}" \
${PRERELEASE_FLAG} \
dist/*.whl