|
| 1 | +name: Release (npm & Docker) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Version to release (e.g., 1.0.1)' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + publish-npm: |
| 14 | + description: 'Publish to npm' |
| 15 | + required: false |
| 16 | + type: boolean |
| 17 | + default: true |
| 18 | + publish-docker: |
| 19 | + description: 'Publish to Docker Hub' |
| 20 | + required: false |
| 21 | + type: boolean |
| 22 | + default: true |
| 23 | + |
| 24 | +env: |
| 25 | + DOCKER_IMAGE: countly/countly-mcp-server |
| 26 | + DOCKERHUB_USERNAME: countly |
| 27 | + |
| 28 | +permissions: |
| 29 | + id-token: write # Required for npm OIDC |
| 30 | + contents: read |
| 31 | + |
| 32 | +jobs: |
| 33 | + test-and-build: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + name: Test & Build |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v5 |
| 40 | + |
| 41 | + - name: Setup Node.js |
| 42 | + uses: actions/setup-node@v6 |
| 43 | + with: |
| 44 | + node-version: '20.x' |
| 45 | + cache: 'npm' |
| 46 | + |
| 47 | + - name: Install dependencies |
| 48 | + run: npm ci |
| 49 | + |
| 50 | + - name: Build project |
| 51 | + run: npm run build |
| 52 | + |
| 53 | + - name: Run tests (with transport integration tests) |
| 54 | + run: npm run test:ci |
| 55 | + env: |
| 56 | + COUNTLY_SERVER_URL: https://test.count.ly |
| 57 | + COUNTLY_AUTH_TOKEN: test-token-for-ci |
| 58 | + |
| 59 | + - name: Upload build artifacts |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: build |
| 63 | + path: build/ |
| 64 | + retention-days: 1 |
| 65 | + |
| 66 | + publish-npm: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + needs: test-and-build |
| 69 | + name: Publish to npm |
| 70 | + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish-npm) |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Checkout code |
| 74 | + uses: actions/checkout@v5 |
| 75 | + |
| 76 | + - name: Set up Node.js |
| 77 | + uses: actions/setup-node@v6 |
| 78 | + with: |
| 79 | + node-version: '20.x' |
| 80 | + registry-url: 'https://registry.npmjs.org/' |
| 81 | + cache: 'npm' |
| 82 | + |
| 83 | + - name: Install dependencies |
| 84 | + run: npm ci |
| 85 | + |
| 86 | + - name: Download build artifacts |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + name: build |
| 90 | + path: build/ |
| 91 | + |
| 92 | + - name: Update package.json version (manual trigger only) |
| 93 | + if: github.event_name == 'workflow_dispatch' |
| 94 | + run: npm version ${{ inputs.version }} --no-git-tag-version |
| 95 | + |
| 96 | + - name: Publish to npm |
| 97 | + run: npm publish --access public |
| 98 | + env: |
| 99 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 100 | + |
| 101 | + publish-docker: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + needs: test-and-build |
| 104 | + name: Build & Push Docker Image |
| 105 | + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish-docker) |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout code |
| 109 | + uses: actions/checkout@v5 |
| 110 | + |
| 111 | + - name: Set up QEMU |
| 112 | + uses: docker/setup-qemu-action@v3 |
| 113 | + |
| 114 | + - name: Set up Docker Buildx |
| 115 | + uses: docker/setup-buildx-action@v3 |
| 116 | + |
| 117 | + - name: Extract version from tag or input |
| 118 | + id: meta |
| 119 | + run: | |
| 120 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 121 | + VERSION="${{ inputs.version }}" |
| 122 | + elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then |
| 123 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 124 | + else |
| 125 | + VERSION="dev-${GITHUB_SHA::8}" |
| 126 | + fi |
| 127 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 128 | + echo "Building version: $VERSION" |
| 129 | +
|
| 130 | + - name: Log in to Docker Hub |
| 131 | + uses: docker/login-action@v3 |
| 132 | + with: |
| 133 | + username: ${{ env.DOCKERHUB_USERNAME }} |
| 134 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 135 | + |
| 136 | + - name: Build and push Docker image |
| 137 | + uses: docker/build-push-action@v6 |
| 138 | + with: |
| 139 | + context: . |
| 140 | + platforms: linux/amd64,linux/arm64 |
| 141 | + push: true |
| 142 | + tags: | |
| 143 | + ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }} |
| 144 | + ${{ env.DOCKER_IMAGE }}:latest |
| 145 | + cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache |
| 146 | + cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max |
| 147 | + labels: | |
| 148 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 149 | + org.opencontainers.image.version=${{ steps.meta.outputs.version }} |
| 150 | + org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} |
| 151 | + org.opencontainers.image.revision=${{ github.sha }} |
| 152 | +
|
| 153 | + - name: Update Docker Hub description |
| 154 | + uses: peter-evans/dockerhub-description@v4 |
| 155 | + with: |
| 156 | + username: ${{ env.DOCKERHUB_USERNAME }} |
| 157 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 158 | + repository: ${{ env.DOCKER_IMAGE }} |
| 159 | + readme-filepath: ./DOCKER.md |
| 160 | + short-description: "MCP server for Countly Analytics - Access 40+ analytics tools via Model Context Protocol" |
0 commit comments