-
Notifications
You must be signed in to change notification settings - Fork 192
229 lines (214 loc) · 7.55 KB
/
release.yml
File metadata and controls
229 lines (214 loc) · 7.55 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
validate:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- id: version
run: |
VERSION="${GITHUB_REF_NAME#v}"
PACKAGE_VERSION="$(python - <<'PY'
import runpy
print(runpy.run_path("chatmock/version.py")["__version__"])
PY
)"
if [ "$VERSION" != "$PACKAGE_VERSION" ]; then
echo "Tag version $VERSION does not match package version $PACKAGE_VERSION" >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
- uses: astral-sh/setup-uv@v5
- run: uv pip install --system .
- run: python -m unittest discover -s tests
build-python:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: astral-sh/setup-uv@v5
- run: uv build
- uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/*
publish-pypi:
needs:
- validate
- build-python
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: python-dist
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
build-windows:
needs: validate
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: python -m pip install --upgrade pip
- run: python -m pip install ".[gui]"
- run: python build.py --name ChatMock
- run: Compress-Archive -Path dist/ChatMock -DestinationPath dist/ChatMock-windows.zip
shell: pwsh
- uses: actions/upload-artifact@v4
with:
name: windows-gui
path: dist/ChatMock-windows.zip
build-macos:
needs: validate
runs-on: macos-latest
env:
APPLE_CERTIFICATE_P12_BASE64: ${{ secrets.APPLE_CERTIFICATE_P12_BASE64 }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: python -m pip install --upgrade pip
- run: python -m pip install ".[gui]"
- run: |
security create-keychain -p "$RUNNER_TEMP" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$RUNNER_TEMP" build.keychain
security set-keychain-settings -lut 21600 build.keychain
python - <<'PY'
import base64
import os
from pathlib import Path
data = os.environ["APPLE_CERTIFICATE_P12_BASE64"]
Path(os.environ["RUNNER_TEMP"], "chatmock-signing.p12").write_bytes(base64.b64decode(data))
PY
security import "$RUNNER_TEMP/chatmock-signing.p12" -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/security
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$RUNNER_TEMP" build.keychain
- run: python build.py --name ChatMock
- run: codesign --force --deep --options runtime --sign "$APPLE_SIGNING_IDENTITY" dist/ChatMock.app
- run: codesign --verify --deep --strict dist/ChatMock.app
- run: python build.py --name ChatMock --dmg-only
- run: codesign --force --sign "$APPLE_SIGNING_IDENTITY" dist/ChatMock.dmg
- run: codesign --verify --strict dist/ChatMock.dmg
- run: xcrun notarytool submit dist/ChatMock.dmg --apple-id "$APPLE_ID" --password "$APPLE_APP_SPECIFIC_PASSWORD" --team-id "$APPLE_TEAM_ID" --wait
- run: xcrun stapler staple dist/ChatMock.dmg
- run: xcrun stapler validate dist/ChatMock.dmg
- uses: actions/upload-artifact@v4
with:
name: macos-gui
path: dist/ChatMock.dmg
docker:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: storagetime/chatmock
tags: |
type=raw,value=latest
type=raw,value=${{ needs.validate.outputs.tag }}
type=raw,value=${{ needs.validate.outputs.version }}
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
homebrew:
needs: validate
runs-on: ubuntu-latest
steps:
- run: |
ARCHIVE_URL="https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${GITHUB_REF_NAME}.tar.gz"
SHA256="$(curl -fsSL "$ARCHIVE_URL" | shasum -a 256 | awk '{print $1}')"
git clone "https://x-access-token:${{ secrets.HOMEBREW_TAP_TOKEN }}@github.com/RayBytes/homebrew-chatmock.git" tap
cd tap
cat <<EOF > chatmock.rb
class Chatmock < Formula
include Language::Python::Virtualenv
desc "OpenAI & Ollama compatible API powered by your ChatGPT plan"
homepage "https://github.com/RayBytes/ChatMock"
url "${ARCHIVE_URL}"
sha256 "${SHA256}"
license "MIT"
head "https://github.com/RayBytes/ChatMock.git", branch: "main"
depends_on "python@3.11"
def install
virtualenv_create(libexec, "python3.11")
system libexec/"bin/pip", "install", "."
bin.install_symlink libexec/"bin/chatmock"
end
def caveats
<<~EOS
To get started with ChatMock:
chatmock login
chatmock serve
EOS
end
test do
output = shell_output("#{bin}/chatmock --help 2>&1")
assert_match "ChatMock", output
end
end
EOF
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add chatmock.rb
git commit -m "chatmock ${GITHUB_REF_NAME}" || exit 0
git push
release-assets:
needs:
- validate
- build-python
- build-windows
- build-macos
- publish-pypi
- docker
- homebrew
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: release-artifacts
- run: find release-artifacts -type f | sort
- uses: softprops/action-gh-release@v2
with:
files: |
release-artifacts/python-dist/*
release-artifacts/windows-gui/*
release-artifacts/macos-gui/*