|
| 1 | +name: TypeScript Client Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + id-token: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + publish: |
| 14 | + name: Publish to npm |
| 15 | + runs-on: ubuntu-latest |
| 16 | + defaults: |
| 17 | + run: |
| 18 | + working-directory: src/client/acontext-ts |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: '20' |
| 27 | + registry-url: 'https://registry.npmjs.org' |
| 28 | + cache: 'npm' |
| 29 | + cache-dependency-path: src/client/acontext-ts/package-lock.json |
| 30 | + env: |
| 31 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: | |
| 35 | + npm ci |
| 36 | + # Install peer dependencies for Node.js environment |
| 37 | + npm install --no-save node-fetch@^3.3.2 form-data@^4.0.0 || true |
| 38 | +
|
| 39 | + - name: Run lint |
| 40 | + run: npm run lint |
| 41 | + |
| 42 | + - name: Build |
| 43 | + run: npm run build |
| 44 | + |
| 45 | + - name: Start containers |
| 46 | + working-directory: src/server |
| 47 | + run: | |
| 48 | + cp .env.example .env |
| 49 | + cp core/config.yaml.example core/config.yaml |
| 50 | +
|
| 51 | + docker compose up acontext-server-pg acontext-server-redis acontext-server-rabbitmq acontext-server-seaweedfs-setup acontext-server-seaweedfs acontext-server-api -d |
| 52 | +
|
| 53 | + - name: Wait for API to be ready |
| 54 | + run: | |
| 55 | + timeout=120 |
| 56 | + elapsed=0 |
| 57 | + while [ $elapsed -lt $timeout ]; do |
| 58 | + if curl -f http://localhost:8029/health > /dev/null 2>&1; then |
| 59 | + echo "API is ready" |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | + echo "Waiting for API to be ready... ($elapsed/$timeout seconds)" |
| 63 | + sleep 5 |
| 64 | + elapsed=$((elapsed + 5)) |
| 65 | + done |
| 66 | + echo "API did not become ready in time" |
| 67 | + exit 1 |
| 68 | +
|
| 69 | + - name: Run tests |
| 70 | + run: npm test |
| 71 | + env: |
| 72 | + CI: true |
| 73 | + ACONTEXT_API_KEY: sk-ac-your-root-api-bearer-token |
| 74 | + ACONTEXT_BASE_URL: http://localhost:8029/api/v1 |
| 75 | + |
| 76 | + - name: Extract version from package.json |
| 77 | + id: version |
| 78 | + run: | |
| 79 | + VERSION=$(node -p "require('./package.json').version") |
| 80 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 81 | +
|
| 82 | + - name: Check if version exists |
| 83 | + id: check_version |
| 84 | + run: | |
| 85 | + VERSION="${{ steps.version.outputs.version }}" |
| 86 | + if npm view acontext@$VERSION version > /dev/null 2>&1; then |
| 87 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 88 | + echo "Version $VERSION already exists on npm" |
| 89 | + else |
| 90 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 91 | + echo "Version $VERSION does not exist on npm" |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Publish to npm |
| 95 | + if: steps.check_version.outputs.exists == 'false' |
| 96 | + run: npm publish --access public |
| 97 | + |
| 98 | + - name: Stop containers |
| 99 | + working-directory: src/server |
| 100 | + if: ${{ always() }} |
| 101 | + run: | |
| 102 | + docker compose down |
| 103 | +
|
0 commit comments