Skip to content

chore: release v1.31.0 #308

chore: release v1.31.0

chore: release v1.31.0 #308

name: Release
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
persist-credentials: false
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Check if version is already published
id: check
run: |
PKG_NAME=$(node -p "require('./package.json').name")
PKG_VERSION=$(node -p "require('./package.json').version")
echo "version=${PKG_VERSION}" >> "$GITHUB_OUTPUT"
if npm view "${PKG_NAME}@${PKG_VERSION}" version 2>/dev/null; then
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Sync package.json description from README
if: steps.check.outputs.published == 'false'
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json','utf-8'));
const lines = fs.readFileSync('README.md','utf-8').split('\n');
for (const line of lines) {
const t = line.trim();
if (!t || t.startsWith('#') || t.startsWith('[') || t.startsWith('http') || t.startsWith('![')) continue;
pkg.description = t.replace(/[*_\`]/g,'').replace(/\s+/g,' ').trim();
break;
}
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
- name: Strip video URLs from README for npm
if: steps.check.outputs.published == 'false'
run: sed -i '/^https:\/\/github.com\/user-attachments\//d' README.md
- name: Build
if: steps.check.outputs.published == 'false'
run: pnpm build
- name: Upload workspace
if: steps.check.outputs.published == 'false'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: workspace
path: .
include-hidden-files: true
retention-days: 1
outputs:
version: ${{ steps.check.outputs.version }}
published: ${{ steps.check.outputs.published }}
publish:
needs: build
if: needs.build.outputs.published == 'false'
runs-on: ubuntu-latest
environment: npm
permissions:
contents: write
id-token: write
actions: write
steps:
- name: Download workspace
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: workspace
- name: Configure git credentials
run: |
git config --local --unset-all http.https://github.com/.extraheader || true
git config --local url."https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
cache: pnpm
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Ensure git tag exists
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
TAG="v${VERSION}"
if ! git rev-parse "${TAG}" >/dev/null 2>&1; then
git tag "${TAG}"
git push origin "${TAG}"
fi
- name: Update major version tag for GitHub Action
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
MAJOR="v$(echo "${VERSION}" | cut -d. -f1)"
git tag -f "${MAJOR}"
git push origin "${MAJOR}" --force
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.build.outputs.version }}
run: |
TAG="v${VERSION}"
gh release create "${TAG}" --generate-notes --title "${TAG}" --verify-tag --latest
- name: Trigger Docker publish workflow
# GitHub's anti-recursion rule: tags pushed by GITHUB_TOKEN do NOT
# trigger downstream workflows. Explicitly dispatch publish-docker.yml
# so the GHCR image actually gets built on every release.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.build.outputs.version }}
run: |
TAG="v${VERSION}"
gh workflow run publish-docker.yml --ref "${TAG}"
- name: Notify Slack
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
VERSION: ${{ needs.build.outputs.version }}
REPO: ${{ github.repository }}
run: |
if [ -z "$SLACK_WEBHOOK" ]; then echo "SLACK_WEBHOOK not set, skipping"; exit 0; fi
NL=$'\n'
TEXT="📦 *@copilotkit/aimock v${VERSION} published*${NL}npm: https://www.npmjs.com/package/@copilotkit/aimock/v/${VERSION}${NL}Release: https://github.com/${REPO}/releases/tag/v${VERSION}"
PAYLOAD=$(jq -n --arg text "$TEXT" '{text: $text}')
curl -s -X POST "$SLACK_WEBHOOK" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"