ci: add publish workflow triggered on v* tags
Swadhin Biswas committed 7 months ago
6c673bf
1 parent 241bf5b
commit 6c673bf
1 file changed
+310 -0
Showing 1 changed file+310-0
▼.github/workflows/publish.yml
+310-0
| @@ -0,0 +1,310 @@ | ||
1 | +name: Publish | |
2 | + | |
3 | +on: | |
4 | + push: | |
5 | + tags: | |
6 | + - "v*" | |
7 | + | |
8 | +permissions: | |
9 | + contents: write | |
10 | + id-token: write | |
11 | + | |
12 | +jobs: | |
13 | + # ── Run all tests first ───────────────────────────────────────────── | |
14 | + test-python: | |
15 | + name: Test Python | |
16 | + runs-on: ubuntu-latest | |
17 | + defaults: | |
18 | + run: | |
19 | + working-directory: PYTHON | |
20 | + steps: | |
21 | + - uses: actions/checkout@v4 | |
22 | + - uses: astral-sh/setup-uv@v4 | |
23 | + with: | |
24 | + version: "latest" | |
25 | + - uses: actions/setup-python@v5 | |
26 | + with: | |
27 | + python-version: "3.12" | |
28 | + - run: uv sync | |
29 | + - run: uv run pytest -v | |
30 | + | |
31 | + test-js: | |
32 | + name: Test JavaScript | |
33 | + runs-on: ubuntu-latest | |
34 | + defaults: | |
35 | + run: | |
36 | + working-directory: JS | |
37 | + steps: | |
38 | + - uses: actions/checkout@v4 | |
39 | + - uses: actions/setup-node@v4 | |
40 | + with: | |
41 | + node-version: "20" | |
42 | + cache: "npm" | |
43 | + cache-dependency-path: JS/package-lock.json | |
44 | + - run: npm ci || npm install | |
45 | + - run: npm run build | |
46 | + - run: npm test | |
47 | + | |
48 | + test-rust: | |
49 | + name: Test Rust | |
50 | + runs-on: ubuntu-latest | |
51 | + defaults: | |
52 | + run: | |
53 | + working-directory: RUST | |
54 | + steps: | |
55 | + - uses: actions/checkout@v4 | |
56 | + - uses: dtolnay/rust-toolchain@stable | |
57 | + - uses: actions/cache@v4 | |
58 | + with: | |
59 | + path: | | |
60 | + ~/.cargo/bin/ | |
61 | + ~/.cargo/registry/index/ | |
62 | + ~/.cargo/registry/cache/ | |
63 | + ~/.cargo/git/db/ | |
64 | + RUST/target/ | |
65 | + key: cargo-${{ runner.os }}-${{ hashFiles('RUST/Cargo.lock', 'RUST/Cargo.toml') }} | |
66 | + restore-keys: cargo-${{ runner.os }}- | |
67 | + - run: cargo build --verbose | |
68 | + - run: cargo test --verbose | |
69 | + | |
70 | + test-go: | |
71 | + name: Test Go | |
72 | + runs-on: ubuntu-latest | |
73 | + defaults: | |
74 | + run: | |
75 | + working-directory: GO | |
76 | + steps: | |
77 | + - uses: actions/checkout@v4 | |
78 | + - uses: actions/setup-go@v5 | |
79 | + with: | |
80 | + go-version: "1.21" | |
81 | + cache-dependency-path: GO/go.sum | |
82 | + - run: go mod download | |
83 | + - run: go build ./... | |
84 | + - run: go test -v ./cortexa/ | |
85 | + | |
86 | + test-zig: | |
87 | + name: Test Zig | |
88 | + runs-on: ubuntu-latest | |
89 | + defaults: | |
90 | + run: | |
91 | + working-directory: ZIG | |
92 | + steps: | |
93 | + - uses: actions/checkout@v4 | |
94 | + - uses: mlugg/setup-zig@v2 | |
95 | + with: | |
96 | + version: "0.14.0" | |
97 | + - run: zig build | |
98 | + - run: zig build test | |
99 | + | |
100 | + test-lua: | |
101 | + name: Test Lua | |
102 | + runs-on: ubuntu-latest | |
103 | + defaults: | |
104 | + run: | |
105 | + working-directory: LUA | |
106 | + steps: | |
107 | + - uses: actions/checkout@v4 | |
108 | + - name: Install Lua and LuaFileSystem | |
109 | + run: | | |
110 | + sudo apt-get update -qq | |
111 | + sudo apt-get install -y -qq lua5.4 liblua5.4-dev luarocks | |
112 | + sudo luarocks install luafilesystem | |
113 | + - run: lua test.lua | |
114 | + | |
115 | + test-elixir: | |
116 | + name: Test Elixir | |
117 | + runs-on: ubuntu-latest | |
118 | + defaults: | |
119 | + run: | |
120 | + working-directory: ELIXIR | |
121 | + steps: | |
122 | + - uses: actions/checkout@v4 | |
123 | + - uses: erlef/setup-beam@v1 | |
124 | + with: | |
125 | + elixir-version: "1.16" | |
126 | + otp-version: "26" | |
127 | + - run: | | |
128 | + mix local.hex --force | |
129 | + mix local.rebar --force | |
130 | + mix deps.get | |
131 | + - run: mix compile --warnings-as-errors | |
132 | + - run: mix test --trace | |
133 | + | |
134 | + # ── Publish Python to PyPI ────────────────────────────────────────── | |
135 | + publish-python: | |
136 | + name: Publish Python to PyPI | |
137 | + needs: [test-python, test-js, test-rust, test-go, test-zig, test-lua, test-elixir] | |
138 | + runs-on: ubuntu-latest | |
139 | + environment: pypi | |
140 | + defaults: | |
141 | + run: | |
142 | + working-directory: PYTHON | |
143 | + steps: | |
144 | + - uses: actions/checkout@v4 | |
145 | + | |
146 | + - uses: astral-sh/setup-uv@v4 | |
147 | + with: | |
148 | + version: "latest" | |
149 | + | |
150 | + - uses: actions/setup-python@v5 | |
151 | + with: | |
152 | + python-version: "3.12" | |
153 | + | |
154 | + - name: Build package | |
155 | + run: uv build | |
156 | + | |
157 | + - name: Publish to PyPI | |
158 | + env: | |
159 | + UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
160 | + run: uv publish | |
161 | + | |
162 | + # ── Publish JavaScript to npm ─────────────────────────────────────── | |
163 | + publish-js: | |
164 | + name: Publish JavaScript to npm | |
165 | + needs: [test-python, test-js, test-rust, test-go, test-zig, test-lua, test-elixir] | |
166 | + runs-on: ubuntu-latest | |
167 | + environment: npm | |
168 | + defaults: | |
169 | + run: | |
170 | + working-directory: JS | |
171 | + steps: | |
172 | + - uses: actions/checkout@v4 | |
173 | + | |
174 | + - uses: actions/setup-node@v4 | |
175 | + with: | |
176 | + node-version: "20" | |
177 | + registry-url: "https://registry.npmjs.org" | |
178 | + cache: "npm" | |
179 | + cache-dependency-path: JS/package-lock.json | |
180 | + | |
181 | + - name: Install dependencies | |
182 | + run: npm ci || npm install | |
183 | + | |
184 | + - name: Build | |
185 | + run: npm run build | |
186 | + | |
187 | + - name: Publish to npm | |
188 | + run: npm publish --access public | |
189 | + env: | |
190 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
191 | + | |
192 | + # ── Publish Rust to crates.io ─────────────────────────────────────── | |
193 | + publish-rust: | |
194 | + name: Publish Rust to crates.io | |
195 | + needs: [test-python, test-js, test-rust, test-go, test-zig, test-lua, test-elixir] | |
196 | + runs-on: ubuntu-latest | |
197 | + environment: crates | |
198 | + defaults: | |
199 | + run: | |
200 | + working-directory: RUST | |
201 | + steps: | |
202 | + - uses: actions/checkout@v4 | |
203 | + | |
204 | + - uses: dtolnay/rust-toolchain@stable | |
205 | + | |
206 | + - name: Publish to crates.io | |
207 | + run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
208 | + | |
209 | + # ── Publish Lua to LuaRocks ───────────────────────────────────────── | |
210 | + publish-lua: | |
211 | + name: Publish Lua to LuaRocks | |
212 | + needs: [test-python, test-js, test-rust, test-go, test-zig, test-lua, test-elixir] | |
213 | + runs-on: ubuntu-latest | |
214 | + environment: luarocks | |
215 | + defaults: | |
216 | + run: | |
217 | + working-directory: LUA | |
218 | + steps: | |
219 | + - uses: actions/checkout@v4 | |
220 | + | |
221 | + - name: Install Lua and LuaRocks | |
222 | + run: | | |
223 | + sudo apt-get update -qq | |
224 | + sudo apt-get install -y -qq lua5.4 luarocks | |
225 | + | |
226 | + - name: Publish to LuaRocks | |
227 | + env: | |
228 | + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} | |
229 | + run: luarocks upload contexa-0.1.1-1.rockspec --api-key="$LUAROCKS_API_KEY" | |
230 | + | |
231 | + # ── Publish Elixir to Hex.pm ──────────────────────────────────────── | |
232 | + publish-elixir: | |
233 | + name: Publish Elixir to Hex.pm | |
234 | + needs: [test-python, test-js, test-rust, test-go, test-zig, test-lua, test-elixir] | |
235 | + runs-on: ubuntu-latest | |
236 | + environment: hex | |
237 | + defaults: | |
238 | + run: | |
239 | + working-directory: ELIXIR | |
240 | + steps: | |
241 | + - uses: actions/checkout@v4 | |
242 | + | |
243 | + - uses: erlef/setup-beam@v1 | |
244 | + with: | |
245 | + elixir-version: "1.16" | |
246 | + otp-version: "26" | |
247 | + | |
248 | + - name: Install dependencies | |
249 | + run: | | |
250 | + mix local.hex --force | |
251 | + mix local.rebar --force | |
252 | + mix deps.get | |
253 | + | |
254 | + - name: Publish to Hex.pm | |
255 | + env: | |
256 | + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} | |
257 | + run: mix hex.publish --yes | |
258 | + | |
259 | + # ── Create GitHub Release (for Go / Zig / all) ───────────────────── | |
260 | + create-release: | |
261 | + name: Create GitHub Release | |
262 | + needs: [test-python, test-js, test-rust, test-go, test-zig, test-lua, test-elixir] | |
263 | + runs-on: ubuntu-latest | |
264 | + steps: | |
265 | + - uses: actions/checkout@v4 | |
266 | + with: | |
267 | + fetch-depth: 0 | |
268 | + | |
269 | + - name: Extract version from tag | |
270 | + id: version | |
271 | + run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" | |
272 | + | |
273 | + - name: Generate release notes | |
274 | + id: notes | |
275 | + run: | | |
276 | + TAG="${{ steps.version.outputs.version }}" | |
277 | + { | |
278 | + echo "notes<<EOF" | |
279 | + echo "## contexa $TAG" | |
280 | + echo "" | |
281 | + echo "Git-inspired context management for LLM agents — COMMIT, BRANCH, MERGE, and CONTEXT operations over a persistent versioned memory workspace." | |
282 | + echo "" | |
283 | + echo "### Install" | |
284 | + echo "" | |
285 | + echo "| Language | Command |" | |
286 | + echo "|----------|---------|" | |
287 | + echo "| Python | \`pip install contexa\` |" | |
288 | + echo "| JS/TS | \`npm install contexa\` |" | |
289 | + echo "| Rust | \`cargo add contexa\` |" | |
290 | + echo "| Go | \`go get github.com/swadhinbiswas/contexa/GO/cortexa@$TAG\` |" | |
291 | + echo "| Lua | \`luarocks install contexa\` |" | |
292 | + echo "| Elixir | \`{:contexa, \"~> 0.1.1\"}\` in mix.exs |" | |
293 | + echo "| Zig | Add dependency via \`build.zig.zon\` (see README) |" | |
294 | + echo "" | |
295 | + echo "### Changes" | |
296 | + echo "" | |
297 | + git log --pretty=format:"- %s (%h)" $(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)..HEAD | |
298 | + echo "" | |
299 | + echo "EOF" | |
300 | + } >> "$GITHUB_OUTPUT" | |
301 | + | |
302 | + - name: Create GitHub Release | |
303 | + uses: softprops/action-gh-release@v2 | |
304 | + with: | |
305 | + tag_name: ${{ steps.version.outputs.version }} | |
306 | + name: "contexa ${{ steps.version.outputs.version }}" | |
307 | + body: ${{ steps.notes.outputs.notes }} | |
308 | + draft: false | |
309 | + prerelease: ${{ contains(steps.version.outputs.version, '-') }} | |
310 | + generate_release_notes: false | |
0 | 311 | |