|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + validate: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + version: ${{ steps.version.outputs.version }} |
| 16 | + tag: ${{ steps.version.outputs.tag }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - uses: actions/setup-python@v5 |
| 20 | + with: |
| 21 | + python-version: "3.11" |
| 22 | + - id: version |
| 23 | + run: | |
| 24 | + VERSION="${GITHUB_REF_NAME#v}" |
| 25 | + PACKAGE_VERSION="$(python - <<'PY' |
| 26 | + import runpy |
| 27 | + print(runpy.run_path("chatmock/version.py")["__version__"]) |
| 28 | + PY |
| 29 | + )" |
| 30 | + if [ "$VERSION" != "$PACKAGE_VERSION" ]; then |
| 31 | + echo "Tag version $VERSION does not match package version $PACKAGE_VERSION" >&2 |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 35 | + echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" |
| 36 | + - uses: astral-sh/setup-uv@v5 |
| 37 | + - run: uv pip install --system . |
| 38 | + - run: python -m unittest discover -s tests |
| 39 | + |
| 40 | + build-python: |
| 41 | + needs: validate |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + - uses: actions/setup-python@v5 |
| 46 | + with: |
| 47 | + python-version: "3.11" |
| 48 | + - uses: astral-sh/setup-uv@v5 |
| 49 | + - run: uv build |
| 50 | + - uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: python-dist |
| 53 | + path: dist/* |
| 54 | + |
| 55 | + publish-pypi: |
| 56 | + needs: |
| 57 | + - validate |
| 58 | + - build-python |
| 59 | + runs-on: ubuntu-latest |
| 60 | + permissions: |
| 61 | + id-token: write |
| 62 | + steps: |
| 63 | + - uses: actions/download-artifact@v4 |
| 64 | + with: |
| 65 | + name: python-dist |
| 66 | + path: dist |
| 67 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 68 | + with: |
| 69 | + packages-dir: dist |
| 70 | + |
| 71 | + build-windows: |
| 72 | + needs: validate |
| 73 | + runs-on: windows-latest |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v4 |
| 76 | + - uses: actions/setup-python@v5 |
| 77 | + with: |
| 78 | + python-version: "3.11" |
| 79 | + - run: python -m pip install --upgrade pip |
| 80 | + - run: python -m pip install ".[gui]" |
| 81 | + - run: python build.py --name ChatMock |
| 82 | + - run: Compress-Archive -Path dist/ChatMock -DestinationPath dist/ChatMock-windows.zip |
| 83 | + shell: pwsh |
| 84 | + - uses: actions/upload-artifact@v4 |
| 85 | + with: |
| 86 | + name: windows-gui |
| 87 | + path: dist/ChatMock-windows.zip |
| 88 | + |
| 89 | + build-macos: |
| 90 | + needs: validate |
| 91 | + runs-on: macos-latest |
| 92 | + env: |
| 93 | + APPLE_CERTIFICATE_P12_BASE64: ${{ secrets.APPLE_CERTIFICATE_P12_BASE64 }} |
| 94 | + APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} |
| 95 | + APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }} |
| 96 | + APPLE_ID: ${{ secrets.APPLE_ID }} |
| 97 | + APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} |
| 98 | + APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v4 |
| 101 | + - uses: actions/setup-python@v5 |
| 102 | + with: |
| 103 | + python-version: "3.11" |
| 104 | + - run: python -m pip install --upgrade pip |
| 105 | + - run: python -m pip install ".[gui]" |
| 106 | + - run: | |
| 107 | + security create-keychain -p "$RUNNER_TEMP" build.keychain |
| 108 | + security default-keychain -s build.keychain |
| 109 | + security unlock-keychain -p "$RUNNER_TEMP" build.keychain |
| 110 | + security set-keychain-settings -lut 21600 build.keychain |
| 111 | + python - <<'PY' |
| 112 | + import base64 |
| 113 | + import os |
| 114 | + from pathlib import Path |
| 115 | + data = os.environ["APPLE_CERTIFICATE_P12_BASE64"] |
| 116 | + Path(os.environ["RUNNER_TEMP"], "chatmock-signing.p12").write_bytes(base64.b64decode(data)) |
| 117 | + PY |
| 118 | + security import "$RUNNER_TEMP/chatmock-signing.p12" -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/security |
| 119 | + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$RUNNER_TEMP" build.keychain |
| 120 | + - run: python build.py --name ChatMock |
| 121 | + - run: codesign --force --deep --options runtime --sign "$APPLE_SIGNING_IDENTITY" dist/ChatMock.app |
| 122 | + - run: codesign --verify --deep --strict dist/ChatMock.app |
| 123 | + - run: python build.py --name ChatMock --dmg-only |
| 124 | + - run: codesign --force --sign "$APPLE_SIGNING_IDENTITY" dist/ChatMock.dmg |
| 125 | + - run: codesign --verify --strict dist/ChatMock.dmg |
| 126 | + - run: xcrun notarytool submit dist/ChatMock.dmg --apple-id "$APPLE_ID" --password "$APPLE_APP_SPECIFIC_PASSWORD" --team-id "$APPLE_TEAM_ID" --wait |
| 127 | + - run: xcrun stapler staple dist/ChatMock.dmg |
| 128 | + - run: xcrun stapler validate dist/ChatMock.dmg |
| 129 | + - uses: actions/upload-artifact@v4 |
| 130 | + with: |
| 131 | + name: macos-gui |
| 132 | + path: dist/ChatMock.dmg |
| 133 | + |
| 134 | + docker: |
| 135 | + needs: validate |
| 136 | + runs-on: ubuntu-latest |
| 137 | + steps: |
| 138 | + - uses: actions/checkout@v4 |
| 139 | + - uses: docker/setup-qemu-action@v3 |
| 140 | + - uses: docker/setup-buildx-action@v3 |
| 141 | + - uses: docker/login-action@v3 |
| 142 | + with: |
| 143 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 144 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 145 | + - id: meta |
| 146 | + uses: docker/metadata-action@v5 |
| 147 | + with: |
| 148 | + images: storagetime/chatmock |
| 149 | + tags: | |
| 150 | + type=raw,value=latest |
| 151 | + type=raw,value=${{ needs.validate.outputs.tag }} |
| 152 | + type=raw,value=${{ needs.validate.outputs.version }} |
| 153 | + - uses: docker/build-push-action@v6 |
| 154 | + with: |
| 155 | + context: . |
| 156 | + platforms: linux/amd64,linux/arm64 |
| 157 | + push: true |
| 158 | + tags: ${{ steps.meta.outputs.tags }} |
| 159 | + labels: ${{ steps.meta.outputs.labels }} |
| 160 | + |
| 161 | + homebrew: |
| 162 | + needs: validate |
| 163 | + runs-on: ubuntu-latest |
| 164 | + steps: |
| 165 | + - run: | |
| 166 | + ARCHIVE_URL="https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${GITHUB_REF_NAME}.tar.gz" |
| 167 | + SHA256="$(curl -fsSL "$ARCHIVE_URL" | shasum -a 256 | awk '{print $1}')" |
| 168 | + git clone "https://x-access-token:${{ secrets.HOMEBREW_TAP_TOKEN }}@github.com/RayBytes/homebrew-chatmock.git" tap |
| 169 | + cd tap |
| 170 | + cat <<EOF > chatmock.rb |
| 171 | + class Chatmock < Formula |
| 172 | + include Language::Python::Virtualenv |
| 173 | +
|
| 174 | + desc "OpenAI & Ollama compatible API powered by your ChatGPT plan" |
| 175 | + homepage "https://github.com/RayBytes/ChatMock" |
| 176 | + url "${ARCHIVE_URL}" |
| 177 | + sha256 "${SHA256}" |
| 178 | + license "MIT" |
| 179 | + head "https://github.com/RayBytes/ChatMock.git", branch: "main" |
| 180 | +
|
| 181 | + depends_on "python@3.11" |
| 182 | +
|
| 183 | + def install |
| 184 | + virtualenv_create(libexec, "python3.11") |
| 185 | + system libexec/"bin/pip", "install", "." |
| 186 | + bin.install_symlink libexec/"bin/chatmock" |
| 187 | + end |
| 188 | +
|
| 189 | + def caveats |
| 190 | + <<~EOS |
| 191 | + To get started with ChatMock: |
| 192 | + chatmock login |
| 193 | + chatmock serve |
| 194 | + EOS |
| 195 | + end |
| 196 | +
|
| 197 | + test do |
| 198 | + output = shell_output("#{bin}/chatmock --help 2>&1") |
| 199 | + assert_match "ChatMock", output |
| 200 | + end |
| 201 | + end |
| 202 | + EOF |
| 203 | + git config user.name "github-actions[bot]" |
| 204 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 205 | + git add chatmock.rb |
| 206 | + git commit -m "chatmock ${GITHUB_REF_NAME}" || exit 0 |
| 207 | + git push |
| 208 | +
|
| 209 | + release-assets: |
| 210 | + needs: |
| 211 | + - validate |
| 212 | + - build-python |
| 213 | + - build-windows |
| 214 | + - build-macos |
| 215 | + - publish-pypi |
| 216 | + - docker |
| 217 | + - homebrew |
| 218 | + runs-on: ubuntu-latest |
| 219 | + steps: |
| 220 | + - uses: actions/download-artifact@v4 |
| 221 | + with: |
| 222 | + path: release-artifacts |
| 223 | + - run: find release-artifacts -type f | sort |
| 224 | + - uses: softprops/action-gh-release@v2 |
| 225 | + with: |
| 226 | + files: | |
| 227 | + release-artifacts/python-dist/* |
| 228 | + release-artifacts/windows-gui/* |
| 229 | + release-artifacts/macos-gui/* |
0 commit comments