Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions .github/workflows/publish-typescript-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
name: Build & publish TypeScript SDK to npm

on:
push:
branches:
- main
paths:
- "typescript-sdk/**"
- ".github/workflows/publish-typescript-sdk.yml"
release:
types: [published]
workflow_dispatch:

permissions:
contents: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: typescript-sdk

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: typescript-sdk/package-lock.json

- name: Install dependencies
run: npm ci

- name: Run TypeScript compilation
run: npm run build

- name: Run tests
run: npm run test:run

- name: Run test coverage
run: npm run test:coverage

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: exospherehost/exospherehost
files: typescript-sdk/coverage/lcov.info
flags: typescript-sdk-unittests
name: typescript-sdk-coverage-report
fail_ci_if_error: true

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: typescript-sdk-test-results
path: typescript-sdk/coverage/
retention-days: 30

publish:
runs-on: ubuntu-latest
needs: test
defaults:
run:
working-directory: typescript-sdk
if: github.repository == 'exospherehost/exospherehost'

steps:
Comment on lines +65 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent double publishing; gate publish job to push events only.

Currently runs on release events too (and release job also publishes), risking duplicate publish failures.

   publish:
@@
-    if: github.repository == 'exospherehost/exospherehost'
+    if: github.event_name == 'push' && github.repository == 'exospherehost/exospherehost'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
publish:
runs-on: ubuntu-latest
needs: test
defaults:
run:
working-directory: typescript-sdk
if: github.repository == 'exospherehost/exospherehost'
steps:
publish:
runs-on: ubuntu-latest
needs: test
defaults:
run:
working-directory: typescript-sdk
if: github.event_name == 'push' && github.repository == 'exospherehost/exospherehost'
steps:
🤖 Prompt for AI Agents
In .github/workflows/publish-typescript-sdk.yml around lines 66 to 74, the
publish job is currently gated only by the repository name and thus runs on
release events as well, causing duplicate publish attempts; change the job-level
if condition to only run on push events for this repository (e.g., require
github.event_name == 'push' in addition to the repository check) so the publish
job is skipped for release events and only executes on push events to
exospherehost/exospherehost.

- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: typescript-sdk/package-lock.json
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build package
run: npm run build

- name: Check version for beta indicator
run: |
VERSION=$(node -p "require('./package.json').version")
if [[ "$VERSION" == *"b"* ]]; then
echo "Version $VERSION contains beta indicator - publishing to npm with beta tag"
echo "NPM_TAG=beta" >> $GITHUB_ENV
else
echo "Version $VERSION does not contain beta indicator - publishing to npm with latest tag"
echo "NPM_TAG=latest" >> $GITHUB_ENV
fi
Comment on lines +91 to +100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix beta tag detection; matching any “b” is unsafe.

Use prerelease detection consistent with semver -beta.N (after version.js refactor).

-      - name: Check version for beta indicator
+      - name: Determine npm tag from semver prerelease
         run: |
-          VERSION=$(node -p "require('./package.json').version")
-          if [[ "$VERSION" == *"b"* ]]; then
-            echo "Version $VERSION contains beta indicator - publishing to npm with beta tag"
-            echo "NPM_TAG=beta" >> $GITHUB_ENV
-          else
-            echo "Version $VERSION does not contain beta indicator - publishing to npm with latest tag"
-            echo "NPM_TAG=latest" >> $GITHUB_ENV
-          fi
+          VERSION=$(node -p "require('./package.json').version")
+          if [[ "$VERSION" == *"-beta."* ]]; then
+            echo "NPM_TAG=beta" >> "$GITHUB_ENV"
+          elif [[ "$VERSION" == *"-"* ]]; then
+            # Other prereleases (alpha/rc) -> publish under 'next'
+            echo "NPM_TAG=next" >> "$GITHUB_ENV"
+          else
+            echo "NPM_TAG=latest" >> "$GITHUB_ENV"
+          fi
🤖 Prompt for AI Agents
.github/workflows/publish-typescript-sdk.yml around lines 92-101: the current
check looks for any "b" in the version which is too permissive; replace it with
a prerelease-aware check that matches semver beta identifiers (e.g. -beta or
-beta.N). Update the script to set VERSION=$(node -p
"require('./package.json').version") and use a bash regex such as if [[
"$VERSION" =~ -beta([[:digit:]]+)?($|\\.) ]]; then ... to detect "-beta" or
"-beta.N" (and set NPM_TAG=beta), otherwise set NPM_TAG=latest.


- name: Generate SBOM with CycloneDX
run: |
npm install -g @cyclonedx/cyclonedx-npm
cyclonedx-npm --output-file sbom-cyclonedx.json
echo "Generated CycloneDX SBOM in JSON format"

- name: Run npm audit
run: |
npm audit --audit-level=moderate --json > vulnerability-report.json || true
echo "Generated vulnerability report (non-blocking)"

- name: Publish to npm
run: npm publish --tag ${{ env.NPM_TAG }} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Upload SBOM artifacts
uses: actions/upload-artifact@v4
with:
name: sbom-artifacts-typescript-sdk-${{ github.sha }}
path: |
typescript-sdk/sbom-cyclonedx.json
typescript-sdk/vulnerability-report.json
retention-days: 30

release:
runs-on: ubuntu-latest
needs: [test, publish]
if: github.event_name == 'release' && github.event.action == 'published'
defaults:
run:
working-directory: typescript-sdk

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: typescript-sdk/package-lock.json
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build package
run: npm run build

- name: Publish to npm with latest tag
run: npm publish --tag latest --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Comment on lines +153 to +157
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid republishing on release event.

Publishing already happens in publish on push; remove duplicate publish here to prevent 409 errors on identical version.

-      - name: Publish to npm with latest tag
-        run: npm publish --tag latest --access public
-        env:
-          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+      # Publishing happens in the 'publish' job on push. Skip duplicate publish here.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Publish to npm with latest tag
run: npm publish --tag latest --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Publishing happens in the 'publish' job on push. Skip duplicate publish here.
🤖 Prompt for AI Agents
.github/workflows/publish-typescript-sdk.yml around lines 154 to 158: the
workflow contains a duplicate "Publish to npm with latest tag" job step that
re-publishes on release events and can cause 409 errors for identical versions;
remove this npm publish step (the name/run/env block) from these lines so
publishing only occurs in the existing publish-on-push job, or alternatively
gate it behind a conditional that skips publishing when the version/tag already
exists.

- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.release.tag_name }}
release_name: ${{ github.event.release.name }}
body: |
## TypeScript SDK Release ${{ github.event.release.tag_name }}

This release includes the TypeScript SDK for ExosphereHost.

### Installation
```bash
npm install exospherehost@${{ github.event.release.tag_name }}
```

### Changes
${{ github.event.release.body }}

### Package Information
- **Package Name**: exospherehost
- **Version**: ${{ github.event.release.tag_name }}
- **Registry**: https://www.npmjs.com/package/exospherehost
draft: false
prerelease: ${{ contains(github.event.release.tag_name, 'beta') || contains(github.event.release.tag_name, 'alpha') || contains(github.event.release.tag_name, 'rc') }}
15 changes: 15 additions & 0 deletions typescript-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
Dist
dist
node_modules/
dist/
# build cache / type info
*.tsbuildinfo
# coverage / vitest
coverage/
.vitest/
.vite/
# logs & OS junk
npm-debug.log*
yarn-error.log*
.DS_Store
Loading