-
Notifications
You must be signed in to change notification settings - Fork 4
137 lines (122 loc) · 4.49 KB
/
Copy pathrelease-and-homebrew.yml
File metadata and controls
137 lines (122 loc) · 4.49 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
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