Skip to content

Commit 3b8be5c

Browse files
authored
Merge pull request #12 from Floe-Labs/ci/npm-publish-and-cost-map-guard
ci: npm publish workflow + cost-map drift guard
2 parents 10f3d35 + b911fd2 commit 3b8be5c

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ jobs:
2828
- name: Ruff
2929
run: ruff check .
3030

31+
cost-map-sync:
32+
# The LiteLLM cost map is vendored in two places — the Python package
33+
# (src/floe_guard/cost_map.json) and the JS package (js/src/cost_map.json).
34+
# They must stay byte-identical; fail loudly if they drift so any refresh
35+
# updates both.
36+
runs-on: ubuntu-latest
37+
timeout-minutes: 5
38+
steps:
39+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
40+
with:
41+
persist-credentials: false
42+
- name: Python and JS cost maps must match
43+
# -q keeps the failure concise (the map is ~700 lines); the message says
44+
# what to do rather than dumping the whole diff.
45+
run: |
46+
diff -q src/floe_guard/cost_map.json js/src/cost_map.json \
47+
|| { echo "::error::cost_map.json drifted between src/floe_guard/ and js/src/ — re-sync the two copies."; exit 1; }
48+
3149
test:
3250
runs-on: ubuntu-latest
3351
timeout-minutes: 10

.github/workflows/publish-npm.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
branches: [main]
6+
# The npm package lives in js/; only publish when it (or this workflow) changes.
7+
paths:
8+
- 'js/**'
9+
- '.github/workflows/publish-npm.yml'
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: publish-npm-${{ github.ref }}
14+
cancel-in-progress: false
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
publish:
21+
if: github.ref == 'refs/heads/main'
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 15
24+
defaults:
25+
run:
26+
working-directory: js
27+
steps:
28+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
29+
with:
30+
persist-credentials: false
31+
32+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
33+
with:
34+
# Node 22: current LTS, comfortably covers the JS toolchain (Vite/Vitest).
35+
node-version: '22'
36+
registry-url: 'https://registry.npmjs.org'
37+
38+
- name: Install dependencies
39+
run: npm ci
40+
41+
- name: Build
42+
run: npm run build
43+
44+
- name: Test
45+
run: npm test --if-present
46+
47+
- name: Check if version is already published
48+
id: check
49+
run: |
50+
set -euo pipefail
51+
PKG_NAME=$(node -p "require('./package.json').name")
52+
PKG_VERSION=$(node -p "require('./package.json').version")
53+
echo "name=$PKG_NAME" >> "$GITHUB_OUTPUT"
54+
echo "version=$PKG_VERSION" >> "$GITHUB_OUTPUT"
55+
if npm view "$PKG_NAME@$PKG_VERSION" version > /dev/null 2>npm_view.err; then
56+
echo "$PKG_NAME@$PKG_VERSION already published on npm, skipping."
57+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
58+
elif grep -q 'E404' npm_view.err; then
59+
echo "$PKG_NAME@$PKG_VERSION not found on npm, will publish."
60+
echo "should_publish=true" >> "$GITHUB_OUTPUT"
61+
else
62+
echo "npm view failed unexpectedly; aborting publish check." >&2
63+
cat npm_view.err >&2
64+
exit 1
65+
fi
66+
67+
- name: Publish
68+
if: steps.check.outputs.should_publish == 'true'
69+
run: npm publish --access public
70+
env:
71+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)