Skip to content

Merge pull request #26 from TONresistor/dev #55

Merge pull request #26 from TONresistor/dev

Merge pull request #26 from TONresistor/dev #55

Workflow file for this run

name: Release
on:
push:
tags: ["v*"]
# Least privilege by default; jobs opt into the extra scopes they need.
permissions:
contents: read
jobs:
# ---- Build & Verify ----
build:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
- run: npm ci
- run: cd web && npm ci
- run: npm run build -w packages/sdk
- run: node scripts/check-sdk-package.mjs
- run: npm run typecheck
- run: npm run build
- run: node dist/cli/index.js --help
- name: Run tests
run: npx vitest run
- name: Enforce SDK coverage
run: npm run test:sdk:coverage
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# ---- Publish to npm ----
publish-npm:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write # npm provenance
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
- name: Check if version already published
id: check
run: |
LOCAL=$(node -p "require('./package.json').version")
REMOTE=$(npm view teleton version 2>/dev/null || echo "0.0.0")
echo "local=$LOCAL remote=$REMOTE"
if [ "$LOCAL" != "$REMOTE" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- run: npm ci
if: steps.check.outputs.publish == 'true'
- run: cd web && npm ci
if: steps.check.outputs.publish == 'true'
- uses: actions/download-artifact@v4
if: steps.check.outputs.publish == 'true'
with:
name: dist
path: dist/
- run: npm publish --provenance --access public
if: steps.check.outputs.publish == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ---- Publish SDK to npm (if version changed) ----
publish-sdk:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write # npm provenance
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
cache: npm
- name: Check if SDK version needs publishing
id: check
run: |
LOCAL=$(node -p "require('./packages/sdk/package.json').version")
REMOTE=$(npm view @teleton-agent/sdk version 2>/dev/null || echo "0.0.0")
echo "local=$LOCAL" >> "$GITHUB_OUTPUT"
echo "remote=$REMOTE" >> "$GITHUB_OUTPUT"
if [ "$LOCAL" != "$REMOTE" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- name: Install dependencies
if: steps.check.outputs.publish == 'true'
run: npm ci
- name: Build and publish SDK
if: steps.check.outputs.publish == 'true'
run: npm run build -w packages/sdk && cd packages/sdk && npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ---- Publish Docker image ----
publish-docker:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
packages: write # push to ghcr.io
steps:
- uses: actions/checkout@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version and repo
id: meta
run: |
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
echo "repo=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ steps.meta.outputs.repo }}:${{ steps.meta.outputs.version }}
ghcr.io/${{ steps.meta.outputs.repo }}:latest
# ---- GitHub Release ----
create-release:
needs: [publish-npm, publish-sdk, publish-docker]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # create the GitHub release
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if release already exists
id: check
run: |
if gh release view "$GITHUB_REF_NAME" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate changelog
if: steps.check.outputs.exists == 'false'
id: changelog
run: |
PREV_TAG=$(git tag --sort=-version:refname | head -2 | tail -1)
if [ -z "$PREV_TAG" ]; then
LOG=$(git log --oneline)
else
LOG=$(git log --oneline "$PREV_TAG"..HEAD)
fi
echo "log<<EOF" >> "$GITHUB_OUTPUT"
echo "$LOG" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Lowercase image path for the install snippet
id: meta
run: echo "repo=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
if: steps.check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
body: |
## Install
**npm:**
```bash
npm install -g teleton
```
**Docker:**
```bash
docker run -it -v ~/.teleton:/data ghcr.io/${{ steps.meta.outputs.repo }}:latest setup
```
## Changes
${{ steps.changelog.outputs.log }}