Skip to content

进一步收紧账号列表列宽\n\n- 调整,SPACE 列继续收窄以减少终端留白\n- 更新,README 与 release notes 对… #15

进一步收紧账号列表列宽\n\n- 调整,SPACE 列继续收窄以减少终端留白\n- 更新,README 与 release notes 对…

进一步收紧账号列表列宽\n\n- 调整,SPACE 列继续收窄以减少终端留白\n- 更新,README 与 release notes 对… #15

name: Release And Homebrew
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release metadata
id: meta
shell: bash
run: |
VERSION="${GITHUB_REF_NAME}"
NOTES_FILE="docs/releases/${VERSION}.md"
if [ ! -f "${NOTES_FILE}" ]; then
NOTES_FILE="$(mktemp)"
{
echo "# ${GITHUB_REPOSITORY##*/} ${VERSION}"
echo
echo "Automated release generated from tag ${VERSION}."
} > "${NOTES_FILE}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "notes_file=${NOTES_FILE}" >> "$GITHUB_OUTPUT"
- name: Create or update release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
VERSION="${{ steps.meta.outputs.version }}"
NOTES_FILE="${{ steps.meta.outputs.notes_file }}"
ASSET_PATH="docs/images/overview.png"
if gh release view "${VERSION}" >/dev/null 2>&1; then
gh release edit "${VERSION}" --title "${GITHUB_REPOSITORY##*/} ${VERSION}" --notes-file "${NOTES_FILE}"
else
if [ -f "${ASSET_PATH}" ]; then
gh release create "${VERSION}" "${ASSET_PATH}#overview.png" --title "${GITHUB_REPOSITORY##*/} ${VERSION}" --notes-file "${NOTES_FILE}"
else
gh release create "${VERSION}" --title "${GITHUB_REPOSITORY##*/} ${VERSION}" --notes-file "${NOTES_FILE}"
fi
fi
update-homebrew:
needs: release
runs-on: ubuntu-latest
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
steps:
- name: Check tap token
shell: bash
run: |
if [ -z "${HOMEBREW_TAP_TOKEN}" ]; then
echo "HOMEBREW_TAP_TOKEN is not configured. Skipping tap sync."
exit 0
fi
- name: Checkout source repo
uses: actions/checkout@v4
- name: Compute tarball SHA256
id: sha
shell: bash
run: |
VERSION="${GITHUB_REF_NAME}"
curl -L -s "https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${VERSION}.tar.gz" -o "/tmp/${VERSION}.tar.gz"
SHA256="$(sha256sum "/tmp/${VERSION}.tar.gz" | awk '{print $1}')"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "sha256=${SHA256}" >> "$GITHUB_OUTPUT"
- name: Checkout tap repository
uses: actions/checkout@v4
with:
repository: mileson/homebrew-cjfcodexswitcher
token: ${{ env.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Update formula
shell: bash
run: |
VERSION="${{ steps.sha.outputs.version }}"
SHA256="${{ steps.sha.outputs.sha256 }}"
cat > tap/Formula/cjfcodexswitcher.rb <<EOF
class Cjfcodexswitcher < Formula
desc "Codex account switcher with live quota view and agent-friendly CLI"
homepage "https://github.com/${GITHUB_REPOSITORY}"
url "https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${VERSION}.tar.gz"
version "${VERSION#v}"
sha256 "${SHA256}"
license "MIT"
depends_on "python@3.12"
def install
python = Formula["python@3.12"].opt_bin/"python3.12"
venv = libexec/"venv"
system python, "-m", "venv", venv
system venv/"bin/python", "-m", "ensurepip", "--upgrade"
system venv/"bin/pip", "install", "--upgrade", "pip", "setuptools", "wheel"
system venv/"bin/pip", "install", buildpath
bin.install_symlink venv/"bin/codex-switcher"
bin.install_symlink venv/"bin/csw"
end
test do
output = shell_output("#{bin}/codex-switcher --help")
assert_match "Codex", output
end
end
EOF
- name: Commit and push formula
shell: bash
run: |
cd tap
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git diff --quiet; then
echo "No formula changes."
exit 0
fi
git add Formula/cjfcodexswitcher.rb
git commit -m "Update formula to ${GITHUB_REF_NAME}"
git push