Skip to content
Latchkey

Code Scanning workflow (cli/cli)

The Code Scanning workflow from cli/cli, explained and optimized by Latchkey.

C

CI health: C - fair

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

Grade your own workflow free or run it on Latchkey →
Source: cli/cli.github/workflows/codeql.ymlLicense MITView source

What it does

This is the Code Scanning workflow from the cli/cli repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

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

The workflow

workflow (.yml)
name: Code Scanning

on:
  push:
    branches: [trunk]
  pull_request:
    branches: [trunk]
    paths-ignore:
      - '**/*.md'
  schedule:
    - cron: "0 0 * * 0"

permissions:
  actions: read  # for github/codeql-action/init to get workflow details
  contents: read  # for actions/checkout to fetch code
  security-events: write  # for github/codeql-action/analyze to upload SARIF results

jobs:
  CodeQL-Build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        language: ['go', 'actions']

    steps:
      - name: Check out code
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

      - name: Setup Go
        if: matrix.language == 'go'
        uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
        with:
          go-version-file: "go.mod"

      - name: Initialize CodeQL
        uses: github/codeql-action/init@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
        with:
          languages: ${{ matrix.language }}
          queries: security-and-quality

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

      - name: Upload filtered SARIF
        uses: github/codeql-action/upload-sarif@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
        with:
          sarif_file: sarif-results/${{ matrix.language }}.sarif
          category: "/language:${{ matrix.language }}"

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Code Scanning
 
on:
  push:
    branches: [trunk]
  pull_request:
    branches: [trunk]
    paths-ignore:
      - '**/*.md'
  schedule:
    - cron: "0 0 * * 0"
 
permissions:
  actions: read  # for github/codeql-action/init to get workflow details
  contents: read  # for actions/checkout to fetch code
  security-events: write  # for github/codeql-action/analyze to upload SARIF results
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  CodeQL-Build:
    timeout-minutes: 30
    runs-on: latchkey-small
    strategy:
      fail-fast: false
      matrix:
        language: ['go', 'actions']
 
    steps:
      - name: Check out code
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
 
      - name: Setup Go
        if: matrix.language == 'go'
        uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
        with:
          go-version-file: "go.mod"
 
      - name: Initialize CodeQL
        uses: github/codeql-action/init@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
        with:
          languages: ${{ matrix.language }}
          queries: security-and-quality
 
      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
        with:
          category: "/language:${{ matrix.language }}"
          upload: false
          output: sarif-results
 
      - name: Upload filtered SARIF
        uses: github/codeql-action/upload-sarif@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
        with:
          sarif_file: sarif-results/${{ matrix.language }}.sarif
          category: "/language:${{ matrix.language }}"
 

What changed

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

Actions used in this workflow