diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..eee5dd0 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,106 @@ +name: Publish Package and Build Docker Image + +on: + push: + tags: + - 'v*.*.*' # Trigger on version tags like v1.0.3 + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + registry-url: 'https://registry.npmjs.org' + + - name: Install pnpm + run: npm install -g pnpm + + - name: Install dependencies + run: pnpm install + + - name: Build package + run: pnpm run build + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish summary + run: | + VERSION=${GITHUB_REF#refs/tags/} + echo "✅ Successfully published coderio@${VERSION#v} to npm" + + build-docker: + needs: publish-npm # Wait for npm publish to complete successfully + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Extract version from tag + id: version + run: | + VERSION=${GITHUB_REF#refs/tags/} + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "Building Docker image for version: ${VERSION}" + + - name: Wait for npm package availability + run: | + VERSION=${{ steps.version.outputs.version }} + VERSION_NO_V=${VERSION#v} + echo "Waiting for coderio@${VERSION_NO_V} to be available on npm..." + + for i in {1..30}; do + if npm view coderio@${VERSION_NO_V} version 2>/dev/null; then + echo "✅ Package coderio@${VERSION_NO_V} is available on npm!" + exit 0 + fi + echo "⏳ Waiting... (attempt $i/30)" + sleep 10 + done + + echo "❌ Package not available after 5 minutes" + exit 1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Aliyun Container Registry + run: | + echo "${{ secrets.ALIYUN_REGISTRY_PASSWORD }}" | docker login \ + --username "${{ secrets.ALIYUN_REGISTRY_USERNAME }}" \ + --password-stdin \ + crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com + + - name: Build Docker image + run: | + VERSION=${{ steps.version.outputs.version }} + docker build \ + --build-arg VERSION=${VERSION} \ + -t crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio:${VERSION} \ + -t crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio:latest \ + . + + - name: Push Docker image (versioned tag) + run: | + VERSION=${{ steps.version.outputs.version }} + docker push crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio:${VERSION} + + - name: Push Docker image (latest tag) + run: | + docker push crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio:latest + + - name: Build summary + run: | + VERSION=${{ steps.version.outputs.version }} + echo "✅ Successfully built and pushed Docker images:" + echo " 📦 crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio:${VERSION}" + echo " 📦 crpi-p4hwwrt00km3axuk.cn-shanghai.personal.cr.aliyuncs.com/coderio/coderio:latest"