name: Publish Release
on:
push:
tags:
- 'v*'
jobs:
publish-npm:
name: Publish to npm
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Configure git for HTTPS
run: |
git config --global url."https://github.com/".insteadOf "git@github.com:"
git config --global url."https://".insteadOf "ssh://"
- name: Install dependencies
run: pnpm install --ignore-scripts
- name: Update version for prerelease
if: contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') || contains(github.ref_name, 'rc')
run: |
# For tags like v1.10.1-beta, auto-increment NPM version
TAG_VERSION="${{ github.ref_name }}"
TAG_VERSION="${TAG_VERSION#v}" # Remove 'v' prefix
if [[ "$TAG_VERSION" == *-beta ]]; then
BASE_VERSION="${TAG_VERSION%-beta}"
# Get the latest published beta version from npm
LATEST_BETA=$(npm view @promptx/core versions --json | jq -r '.[]' | grep "^${BASE_VERSION}-beta\." | sort -V | tail -1 | sed 's/.*-beta\.//')
if [[ -z "$LATEST_BETA" ]]; then
# No existing beta versions, start from 0
NEXT_VERSION="${BASE_VERSION}-beta.0"
else
# Increment the beta version
NEXT_BETA=$((LATEST_BETA + 1))
NEXT_VERSION="${BASE_VERSION}-beta.${NEXT_BETA}"
fi
else
# For other prerelease types, use tag version as-is
NEXT_VERSION="$TAG_VERSION"
fi
echo "Auto-incremented version: $NEXT_VERSION"
echo "PACKAGE_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
# Update all package.json files
for pkg in apps/cli apps/desktop packages/core packages/logger packages/mcp-server packages/resource; do
jq --arg ver "$NEXT_VERSION" '.version = $ver' $pkg/package.json > tmp.json && mv tmp.json $pkg/package.json
echo "Updated $pkg to version $NEXT_VERSION"
done
- name: Build packages
run: pnpm build
- name: Run tests
run: pnpm test || true # Temporarily skip test failures
- name: Publish to npm
run: |
# Determine npm tag based on version
if [[ "${{ github.ref_name }}" == *"beta"* ]]; then
NPM_TAG="beta"
elif [[ "${{ github.ref_name }}" == *"alpha"* ]]; then
NPM_TAG="alpha"
elif [[ "${{ github.ref_name }}" == *"rc"* ]]; then
NPM_TAG="rc"
else
NPM_TAG="latest"
fi
echo "Publishing with tag: $NPM_TAG"
# Publish workspace packages with appropriate tag
pnpm -r publish --access public --no-git-checks --tag $NPM_TAG
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ github.ref_name }}
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') || contains(github.ref_name, 'rc') }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
publish-docker:
name: Publish to Docker Hub
runs-on: ubuntu-latest
needs: publish-npm # 等待 npm 发布完成
# 只在正式版本发布时构建 Docker 镜像
if: ${{ !contains(github.ref_name, 'beta') && !contains(github.ref_name, 'alpha') && !contains(github.ref_name, 'rc') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version from tag
id: version
run: |
# Extract version from tag (remove 'v' prefix)
VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "📦 Building Docker image for version: $VERSION"
- name: Wait for npm package availability
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Waiting for @promptx/mcp-server@$VERSION to be available on npm..."
for i in {1..20}; do
if npm view @promptx/mcp-server@$VERSION version 2>/dev/null; then
echo "✅ Package @promptx/mcp-server@$VERSION is available"
break
fi
if [ $i -eq 20 ]; then
echo "❌ Timeout waiting for npm package"
exit 1
fi
echo "Attempt $i/20: Package not yet available, waiting 30s..."
sleep 30
done
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./docker
platforms: linux/amd64,linux/arm64
push: true
tags: |
deepracticexs/promptx:${{ steps.version.outputs.version }}
deepracticexs/promptx:latest
build-args: |
VERSION=${{ steps.version.outputs.version }}
cache-from: type=registry,ref=deepracticexs/promptx:buildcache
cache-to: type=registry,ref=deepracticexs/promptx:buildcache,mode=max
- name: Summary
run: |
echo "## Docker Image Published 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tags**:" >> $GITHUB_STEP_SUMMARY
echo " - \`deepracticexs/promptx:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo " - \`deepracticexs/promptx:latest\`" >> $GITHUB_STEP_SUMMARY
echo "- **Platforms**: linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Usage" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker run -d -p 5203:5203 -v ~/.promptx:/root/.promptx deepracticexs/promptx:${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY