Skip to main content
Glama

sonarcloud_create_workflow

Generate GitHub Actions workflow to integrate SonarCloud code analysis into CI/CD pipelines for automated quality checks.

Instructions

Generate GitHub Actions workflow with SonarCloud analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'sonarcloud_create_workflow' MCP tool. It generates a complete GitHub Actions workflow YAML file that includes SonarCloud code analysis steps tailored to the specified project type (Java Maven/Gradle, Node.js, Python, Go). Optionally includes Docker build and push to GHCR. Returns formatted instructions with the YAML content.
      "sonarcloud_create_workflow",
      "Generate GitHub Actions workflow with SonarCloud analysis",
      {
        project_type: { type: "string", description: "Project type: java-maven, java-gradle, nodejs, python, golang" },
        organization: { type: "string", description: "SonarCloud organization key" },
        include_docker: { type: "boolean", description: "Include Docker build", default: false },
        github_owner: { type: "string", description: "GitHub owner for GHCR", default: "" }
      },
      async ({ project_type, organization, include_docker, github_owner }) => {
        const workflows = {
          "java-maven": `name: CI/CD with SonarCloud
    
    on:
      push:
        branches: [ main, master, develop ]
      pull_request:
        branches: [ main, master ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
            with:
              fetch-depth: 0  # Full history for SonarCloud
    
          - name: Set up JDK 17
            uses: actions/setup-java@v4
            with:
              java-version: '17'
              distribution: 'temurin'
              cache: maven
    
          - name: Cache SonarCloud packages
            uses: actions/cache@v4
            with:
              path: ~/.sonar/cache
              key: \${{ runner.os }}-sonar
              restore-keys: \${{ runner.os }}-sonar
    
          - name: Build and Test with Coverage
            run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=\${{ github.repository_owner }}_\${{ github.event.repository.name }}
            env:
              GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
              SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}`,
    
          "java-gradle": `name: CI/CD with SonarCloud
    
    on:
      push:
        branches: [ main, master, develop ]
      pull_request:
        branches: [ main, master ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
            with:
              fetch-depth: 0
    
          - name: Set up JDK 17
            uses: actions/setup-java@v4
            with:
              java-version: '17'
              distribution: 'temurin'
              cache: gradle
    
          - name: Cache SonarCloud packages
            uses: actions/cache@v4
            with:
              path: ~/.sonar/cache
              key: \${{ runner.os }}-sonar
              restore-keys: \${{ runner.os }}-sonar
    
          - name: Build, Test and Analyze
            run: ./gradlew build jacocoTestReport sonar --info
            env:
              GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
              SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}`,
    
          "nodejs": `name: CI/CD with SonarCloud
    
    on:
      push:
        branches: [ main, master, develop ]
      pull_request:
        branches: [ main, master ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
            with:
              fetch-depth: 0
    
          - name: Setup Node.js
            uses: actions/setup-node@v4
            with:
              node-version: '20'
              cache: 'npm'
    
          - name: Install dependencies
            run: npm ci
    
          - name: Run tests with coverage
            run: npm test -- --coverage --coverageReporters=lcov
            continue-on-error: true
    
          - name: SonarCloud Scan
            uses: SonarSource/sonarcloud-github-action@master
            env:
              GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
              SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
            with:
              args: >
                -Dsonar.organization=${organization}
                -Dsonar.projectKey=\${{ github.repository_owner }}_\${{ github.event.repository.name }}`,
    
          "python": `name: CI/CD with SonarCloud
    
    on:
      push:
        branches: [ main, master, develop ]
      pull_request:
        branches: [ main, master ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
            with:
              fetch-depth: 0
    
          - name: Set up Python
            uses: actions/setup-python@v5
            with:
              python-version: '3.11'
              cache: 'pip'
    
          - name: Install dependencies
            run: |
              python -m pip install --upgrade pip
              pip install -r requirements.txt
              pip install pytest pytest-cov
    
          - name: Run tests with coverage
            run: pytest --cov=src --cov-report=xml
            continue-on-error: true
    
          - name: SonarCloud Scan
            uses: SonarSource/sonarcloud-github-action@master
            env:
              GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
              SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
            with:
              args: >
                -Dsonar.organization=${organization}
                -Dsonar.projectKey=\${{ github.repository_owner }}_\${{ github.event.repository.name }}
                -Dsonar.python.coverage.reportPaths=coverage.xml`,
    
          "golang": `name: CI/CD with SonarCloud
    
    on:
      push:
        branches: [ main, master, develop ]
      pull_request:
        branches: [ main, master ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
            with:
              fetch-depth: 0
    
          - name: Set up Go
            uses: actions/setup-go@v5
            with:
              go-version: '1.21'
    
          - name: Build
            run: go build -v ./...
    
          - name: Test with coverage
            run: go test -v -coverprofile=coverage.out ./...
    
          - name: SonarCloud Scan
            uses: SonarSource/sonarcloud-github-action@master
            env:
              GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
              SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
            with:
              args: >
                -Dsonar.organization=${organization}
                -Dsonar.projectKey=\${{ github.repository_owner }}_\${{ github.event.repository.name }}
                -Dsonar.go.coverage.reportPaths=coverage.out`
        };
    
        let workflow = workflows[project_type];
        if (!workflow) {
          return {
            content: [{
              type: "text",
              text: `Unknown project type: ${project_type}\n\nSupported: java-maven, java-gradle, nodejs, python, golang`
            }]
          };
        }
    
        // Add Docker job if requested
        if (include_docker) {
          workflow += `
    
      docker:
        needs: build
        runs-on: ubuntu-latest
        if: github.event_name != 'pull_request'
        permissions:
          contents: read
          packages: write
    
        steps:
          - name: Checkout
            uses: actions/checkout@v4
    
          - name: Set up Docker Buildx
            uses: docker/setup-buildx-action@v3
    
          - name: Login to GHCR
            uses: docker/login-action@v3
            with:
              registry: ghcr.io
              username: \${{ github.actor }}
              password: \${{ secrets.GITHUB_TOKEN }}
    
          - name: Build and push
            uses: docker/build-push-action@v5
            with:
              context: .
              push: true
              tags: ghcr.io/${github_owner || "${{ github.repository_owner }}"}/\${{ github.event.repository.name }}:latest
              cache-from: type=gha
              cache-to: type=gha,mode=max`;
        }
    
        return {
          content: [{
            type: "text",
            text: `GITHUB ACTIONS WITH SONARCLOUD
    ==============================
    
    Save to: .github/workflows/ci.yml
    
    ${workflow}
    
    REQUIRED SECRETS:
    -----------------
    gh secret set SONAR_TOKEN
    (Get token from: https://sonarcloud.io/account/security)
    
    SONARCLOUD SETUP:
    -----------------
    1. Import project at sonarcloud.io
    2. Organization: ${organization}
    3. Project key will be: owner_repo-name
    
    QUALITY GATE:
    -------------
    PRs will show SonarCloud status check.
    Configure quality gates at: sonarcloud.io → Project → Administration
    
    COVERAGE REPORTS:
    -----------------
    The workflow generates coverage reports that SonarCloud uses.
    View detailed reports at: sonarcloud.io/project/overview`
          }]
        };
      }
    );
  • Input schema defining parameters for the sonarcloud_create_workflow tool: project_type (required), organization (required), include_docker (optional), github_owner (optional).
    {
      project_type: { type: "string", description: "Project type: java-maven, java-gradle, nodejs, python, golang" },
      organization: { type: "string", description: "SonarCloud organization key" },
      include_docker: { type: "boolean", description: "Include Docker build", default: false },
      github_owner: { type: "string", description: "GitHub owner for GHCR", default: "" }
    },
  • src/index.js:761-761 (registration)
    MCP tool registration call using McpServer.tool() method, specifying the tool name 'sonarcloud_create_workflow', description, schema, and handler.
    "sonarcloud_create_workflow",
  • Reference to sonarcloud_create_workflow tool in the sonarcloud_setup_guide tool's response text.
    Use 'sonarcloud_create_workflow' to generate the GitHub Actions workflow.
  • Reference to sonarcloud_create_workflow tool in the sonarcloud_create_config tool's response text.
    3. Use 'sonarcloud_create_workflow' to generate CI workflow

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rideRTD/RTD-DevOps'

If you have feedback or need assistance with the MCP directory API, please join our Discord server