Files
pseudoyu 02514c53f5 perf(ci): keep only the two newest CodeQL databases in the Actions cache
On master, CodeQL saves a ~340 MB overlay-base database to the Actions cache for
every commit and never deletes one; pull requests only restore the newest. 16 of
them (5.4 GB) put the cache at 10.5 GB, over the 10 GB limit, so GitHub evicts
other caches to make room.

After each master analysis a small job deletes all but the two newest. The
second one stays so that a pull request restoring it at that moment is not cut
off. During a burst of master pushes two of these jobs can delete the same
database; a delete that fails is fine when the database is already gone, and
fails the job only when it is still there. Pull requests keep their
incremental analysis.
2026-11-02 16:19:19 +09:00

126 lines
6.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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']
# Docs-only pull requests skip the scan. Pushes to master are not filtered, so every commit on master
# keeps an analysis for pull requests to compare against.
pull_request:
branches: ['master']
paths-ignore:
- '**/*.md'
- 'LICENSE'
- '.github/ISSUE_TEMPLATE/**'
schedule:
- cron: '15 9 * * 3'
# A new push to a pull request cancels the run of the previous push.
# Every other run gets its own group per branch and commit, so a push to master is never cancelled or replaced.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || format('{0}-{1}', github.ref, github.sha) }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
language: ['javascript-typescript']
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Initializes the CodeQL tools for scanning.
# TODO: use hash pinning when https://github.com/dependabot/dependabot-core/pull/13007 pass
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# 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,security-and-quality
languages: ${{ matrix.language }}
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v4
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: '/language:${{matrix.language}}'
# On master, CodeQL saves a ~340 MB overlay-base database to the Actions cache for every commit and never deletes one,
# while pull requests only restore the newest. Keep the two newest so they do not fill the 10 GB cache.
prune-overlay-cache:
name: Prune old CodeQL databases
needs: analyze
if: github.event_name != 'pull_request'
runs-on: ubuntu-slim
timeout-minutes: 5
permissions:
actions: write
steps:
- name: Delete all but the two newest overlay-base databases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
REF: ${{ github.ref }}
run: |
set -euo pipefail
ids=$(gh cache list --repo "$REPO" --ref "$REF" --key codeql-overlay-base-database- --sort created_at --order desc --limit 100 --json id --jq '.[2:][].id')
for id in $ids; do
if ! gh cache delete "$id" --repo "$REPO"; then
# The run for another commit may have deleted it a moment ago; fail only if it is still there
left=$(gh cache list --repo "$REPO" --ref "$REF" --key codeql-overlay-base-database- --limit 100 --json id --jq ".[] | select(.id == $id) | .id")
if [ -n "$left" ]; then
exit 1
fi
fi
done