Skip to content

CodeQL

CodeQL #96

Workflow file for this run

name: "CodeQL"
on:
schedule:
- cron: '27 21 * * *' # At 21:27 every day
jobs:
analyze:
name: Analyze
runs-on: kibana
permissions:
actions: read
contents: read
security-events: write
if: github.repository == 'elastic/kibana' # Hack: Do not run on forks
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
branch: [ 'main', '8.19' ]
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ matrix.branch }}
- name: Initialize CodeQL
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
debug: true
# TODO: Possibly required to follow all call paths, however, when enabled, the step below runs out of memory.
# Possible workarounds: Apply for access to the GitHub beta where we can use beefier machines, or run it ourselves on Buildkite
# - name: yarn kbn bootstrap
# run: |
# mkdir ~/.npm-global
# npm config set prefix '~/.npm-global'
# export PATH=~/.npm-global/bin:$PATH
# yarn kbn bootstrap --no-validate --no-vscode
- name: Set sha and branch
run: |
echo "CHECKOUT_REF=$(git symbolic-ref HEAD)" >> "$GITHUB_ENV"
echo "CHECKOUT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
env:
NODE_OPTIONS: "--max-old-space-size=8192"
CODEQL_EXTRACTOR_JAVASCRIPT_OPTION_SKIP_TYPES: true
# CodeQL divides the memory between ts and jvm, though most of the memory is used by the ts.
# We double the memory, so ts can use it in full capacity.
# Refer to https://github.com/github/codeql/blob/59a77a873c894bca7274a7ed7c7c6d937547e9b3/javascript/resources/tools/autobuild.sh#L7-L13
# 2 * 14576, considering our runner is 4 CPU/16GB.
CODEQL_RAM: 29152
CODEQL_THREADS: 2
with:
category: "/language:${{matrix.language}}"
ref: ${{ env.CHECKOUT_REF }}
sha: ${{ env.CHECKOUT_SHA }}
alert:
name: Alert
runs-on: ubuntu-latest
needs: analyze
if: ${{ github.repository == 'elastic/kibana' && success() }} # Hack: Do not run on forks
steps:
- name: Checkout kibana-operations
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'elastic/kibana-operations'
ref: main
path: ./kibana-operations
token: ${{secrets.KIBANAMACHINE_TOKEN}}
- name: CodeQL alert
working-directory: ./kibana-operations/triage
env:
GITHUB_TOKEN: ${{secrets.KIBANAMACHINE_TOKEN}}
SLACK_TOKEN: ${{secrets.CODE_SCANNING_SLACK_TOKEN}}
SLACK_CHANNEL: ${{secrets.CODE_SCANNING_SLACK_CHANNEL_ID}}
CODE_SCANNING_ES_HOST: ${{secrets.CODE_SCANNING_ES_HOST}}
CODE_SCANNING_ES_API_KEY: ${{secrets.CODE_SCANNING_ES_API_KEY}}
CODE_SCANNING_BRANCHES: main,8.19
run: |
npm ci --omit=dev
node codeql-alert
notify_on_failure:
name: Failure notification
runs-on: ubuntu-latest
needs: analyze
if: failure()
steps:
- name: Send notification to slack
uses: slackapi/[email protected]
with:
method: chat.postMessage
token: ${{ secrets.CODE_SCANNING_SLACK_TOKEN }}
payload: |
channel: ${{ secrets.CODE_SCANNING_SLACK_CHANNEL_ID }}
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":broken_heart: CodeQL analysis failed for ${{ github.repository }}."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow Run"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]