Skip to content
Latchkey

CodeQL workflow (mongodb/motor)

The CodeQL workflow from mongodb/motor, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, run de-duplication, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: mongodb/motor.github/workflows/codeql.ymlLicense Apache-2.0View source

What it does

This is the CodeQL workflow from the mongodb/motor repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
  push:
    branches: [ "master", "*" ]
  pull_request:
    branches: [ "master", "*" ]
  schedule:
    - cron: '35 23 * * 5'
  workflow_call:
    inputs:
      ref:
        required: true
        type: string

jobs:
  analyze:
    name: Analyze ${{ matrix.language }}
    runs-on: ubuntu-latest
    timeout-minutes: 360
    permissions:
      # required for all workflows
      security-events: write
      # required to fetch internal or private CodeQL packs
      packages: read
      actions: read
      contents: read
    strategy:
      fail-fast: false
      matrix:
        include:
        - language: python
        - language: actions
    steps:
    - name: Checkout repository
      uses: actions/checkout@v7
      with:
        ref: ${{ inputs.ref }}
        persist-credentials: false
    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: 3.x

    # Initializes the CodeQL tools for scanning.
    - name: Initialize CodeQL
      uses: github/codeql-action/init@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4
      with:
        languages: ${{ matrix.language }}
        build-mode: none
        # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
        queries: security-extended
        config: |
          paths-ignore:
            - 'test/**'

    - shell: bash
      if: matrix.language == 'python'
      run: |
        pip install -e .

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4
      with:
        category: "/language:${{matrix.language}}"

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
 
on:
  push:
    branches: [ "master", "*" ]
  pull_request:
    branches: [ "master", "*" ]
  schedule:
    - cron: '35 23 * * 5'
  workflow_call:
    inputs:
      ref:
        required: true
        type: string
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  analyze:
    name: Analyze ${{ matrix.language }}
    runs-on: latchkey-small
    timeout-minutes: 360
    permissions:
      # required for all workflows
      security-events: write
      # required to fetch internal or private CodeQL packs
      packages: read
      actions: read
      contents: read
    strategy:
      fail-fast: false
      matrix:
        include:
        - language: python
        - language: actions
    steps:
    - name: Checkout repository
      uses: actions/checkout@v7
      with:
        ref: ${{ inputs.ref }}
        persist-credentials: false
    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        cache: 'pip'
        python-version: 3.x
 
    # Initializes the CodeQL tools for scanning.
    - name: Initialize CodeQL
      uses: github/codeql-action/init@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4
      with:
        languages: ${{ matrix.language }}
        build-mode: none
        # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
        queries: security-extended
        config: |
          paths-ignore:
            - 'test/**'
 
    - shell: bash
      if: matrix.language == 'python'
      run: |
        pip install -e .
 
    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4
      with:
        category: "/language:${{matrix.language}}"
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow