diff --git a/.github/workflows/__runner-images.yml b/.github/workflows/__runner-images.yml deleted file mode 100644 index 8c7ce02f7c..0000000000 --- a/.github/workflows/__runner-images.yml +++ /dev/null @@ -1,128 +0,0 @@ -# Warning: This file is generated automatically, and should not be modified. -# Instead, please modify the template in the pr-checks directory and run: -# pr-checks/sync.sh -# to regenerate this file. - -name: PR Check - Runner images -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GO111MODULE: auto -on: - push: - branches: - - main - - releases/v* - pull_request: {} - merge_group: - types: - - checks_requested - schedule: - - cron: "0 5 * * *" - workflow_dispatch: - inputs: - dotnet-version: - type: string - description: The version of .NET to install - required: false - default: 9.x - go-version: - type: string - description: The version of Go to install - required: false - default: ">=1.21.0" - workflow_call: - inputs: - dotnet-version: - type: string - description: The version of .NET to install - required: false - default: 9.x - go-version: - type: string - description: The version of Go to install - required: false - default: ">=1.21.0" -defaults: - run: - shell: bash -concurrency: - cancel-in-progress: ${{ github.event_name == 'pull_request' || false }} - group: runner-images-${{github.ref}}-${{inputs.dotnet-version}}-${{inputs.go-version}} -jobs: - runner-images: - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-22.04 - version: linked - - os: ubuntu-22.04-arm - version: linked - - os: ubuntu-24.04 - version: linked - - os: ubuntu-24.04-arm - version: linked - - os: ubuntu-26.04 - version: linked - - os: ubuntu-26.04-arm - version: linked - - os: windows-2022 - version: linked - - os: windows-2025 - version: linked - - os: macos-15-large - version: linked - - os: macos-15-xlarge - version: linked - - os: macos-26-large - version: linked - - os: macos-26-xlarge - version: linked - name: Runner images - if: github.triggering_actor != 'dependabot[bot]' - permissions: - contents: read - security-events: read - timeout-minutes: 45 - runs-on: ${{ matrix.os }} - steps: - - name: Check out repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Install .NET - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 - with: - dotnet-version: ${{ inputs.dotnet-version || '9.x' }} - - name: Install Go - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: - go-version: ${{ inputs.go-version || '>=1.21.0' }} - cache: false - - name: Prepare test - id: prepare-test - uses: ./.github/actions/prepare-test - with: - version: ${{ matrix.version }} - use-all-platform-bundle: "false" - setup-kotlin: "true" - - uses: ./../action/init - with: - languages: ${{ env.LANGUAGES }} - tools: ${{ steps.prepare-test.outputs.tools-url }} - - name: Build code - run: ./build.sh - - uses: ./../action/analyze - with: - upload-database: false - - name: Assert databases exist - run: | - cd "$RUNNER_TEMP/codeql_databases" - for lang in ${LANGUAGES//,/ }; do - if [[ ! -d "$lang" ]]; then - echo "Did not find a database for $lang" - exit 1 - fi - echo "Found database for $lang" - done - env: - LANGUAGES: cpp,csharp,go,java,javascript,python,ruby${{ startsWith(matrix.os, 'macos') && ',swift' || '' }} - CODEQL_ACTION_TEST_MODE: true diff --git a/.github/workflows/runner-images.yml b/.github/workflows/runner-images.yml new file mode 100644 index 0000000000..aca46494d9 --- /dev/null +++ b/.github/workflows/runner-images.yml @@ -0,0 +1,105 @@ +# An end-to-end integration test checking that CodeQL can analyze interpreted and compiled code on +# the GitHub-hosted runner images. +name: PR Check - Runner images +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GO111MODULE: auto +on: + push: + branches: + - main + - releases/v* + pull_request: + merge_group: + types: [checks_requested] + schedule: + - cron: "0 5 * * *" + workflow_dispatch: + +concurrency: + cancel-in-progress: ${{ github.event_name == 'pull_request' || false }} + group: ${{ github.workflow }}-${{ github.ref }} + +defaults: + run: + shell: bash + +jobs: + read-runner-images: + name: Read runner images + if: github.triggering_actor != 'dependabot[bot]' + permissions: + contents: read + timeout-minutes: 5 + # A lightweight runner is enough for this job, and this one has `yq` installed. + runs-on: ubuntu-slim + outputs: + images: ${{ steps.read.outputs.images }} + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Read runner images + id: read + # Assigning the output of `yq` to a variable first makes the step fail if `yq` fails. + run: | + images=$(yq -o=json -I=0 '.images' pr-checks/runner-images.yml) + echo "images=$images" >> "$GITHUB_OUTPUT" + + runner-images: + name: Runner images + if: github.triggering_actor != 'dependabot[bot]' + needs: read-runner-images + strategy: + fail-fast: false + matrix: + os: ${{ fromJSON(needs.read-runner-images.outputs.images) }} + # Other PR checks cover the supported CodeQL versions, so this check only tests the linked + # version. Linux Arm64 bundles are only available for CodeQL 2.27.0 and later, so older + # stable versions can't run on the Arm64 images. + version: [linked] + permissions: + contents: read + security-events: read + timeout-minutes: 45 + runs-on: ${{ matrix.os }} + env: + # The languages to build and analyze. CodeQL only supports Swift on macOS. + LANGUAGES: "cpp,csharp,go,java,javascript,python,ruby${{ startsWith(matrix.os, 'macos') && ',swift' || '' }}" + CODEQL_ACTION_TEST_MODE: true + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install .NET + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 + with: + dotnet-version: 9.x + - name: Install Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: ">=1.21.0" + # Don't cache dependencies, so that the autobuilder has to download them. + cache: false + - name: Prepare test + id: prepare-test + uses: ./.github/actions/prepare-test + with: + version: ${{ matrix.version }} + - uses: ./../action/init + with: + languages: ${{ env.LANGUAGES }} + tools: ${{ steps.prepare-test.outputs.tools-url }} + - name: Build code + run: ./build.sh + - uses: ./../action/analyze + with: + upload-database: false + - name: Assert databases exist + run: | + cd "$RUNNER_TEMP/codeql_databases" + for lang in ${LANGUAGES//,/ }; do + if [[ ! -d "$lang" ]]; then + echo "Did not find a database for $lang" + exit 1 + fi + echo "Found database for $lang" + done diff --git a/package-lock.json b/package-lock.json index 8fd98030ef..c7ee79f3c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10609,6 +10609,7 @@ }, "devDependencies": { "@types/node": "^24.19.0", + "jsonschema": "^1.5.0", "tsx": "^4.23.15" } }, diff --git a/pr-checks/checks/runner-images.yml b/pr-checks/checks/runner-images.yml deleted file mode 100644 index 70354e9ada..0000000000 --- a/pr-checks/checks/runner-images.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: "Runner images" -description: "An end-to-end integration test checking that CodeQL can analyze interpreted and compiled code on the GitHub-hosted runner images" -# This check runs on each image listed in -# https://github.com/actions/runner-images#available-images, except for: -# - `ubuntu-slim`, which is intended for lightweight jobs rather than builds like this one. -# - `windows-11-arm`, since CodeQL doesn't support Windows on Arm64. -# - `xcode-27`, a preview image that the `unsupported-macos` check runs on. -operatingSystems: - # The Ubuntu 22.04 images have brownouts from 23 March 2027 and are retired on 17 April 2027, so - # remove them before the brownouts start. - # See https://github.com/actions/runner-images/issues/14254. - - os: ubuntu - runner-image: ubuntu-22.04 - - os: ubuntu - runner-image: ubuntu-22.04-arm - - os: ubuntu - runner-image: ubuntu-24.04 - - os: ubuntu - runner-image: ubuntu-24.04-arm - - os: ubuntu - runner-image: ubuntu-26.04 - - os: ubuntu - runner-image: ubuntu-26.04-arm - - os: windows - runner-image: windows-2022 - - os: windows - runner-image: windows-2025 - # Use larger runners for macOS to keep these jobs off the critical path. - - os: macos - runner-image: macos-15-large - - os: macos - runner-image: macos-15-xlarge - - os: macos - runner-image: macos-26-large - - os: macos - runner-image: macos-26-xlarge -# Other PR checks cover the supported CodeQL versions, so this check only tests the linked version. -# Linux Arm64 bundles are only available for CodeQL 2.27.0 and later, so older stable versions -# can't run on the Arm64 images. -versions: - - linked -installGo: true -installDotNet: true -# The languages to build and analyze. CodeQL only supports Swift on macOS. -env: - LANGUAGES: "cpp,csharp,go,java,javascript,python,ruby${{ startsWith(matrix.os, 'macos') && ',swift' || '' }}" -steps: - - uses: ./../action/init - with: - languages: ${{ env.LANGUAGES }} - tools: ${{ steps.prepare-test.outputs.tools-url }} - - name: Build code - run: ./build.sh - - uses: ./../action/analyze - with: - upload-database: false - - name: Assert databases exist - run: | - cd "$RUNNER_TEMP/codeql_databases" - for lang in ${LANGUAGES//,/ }; do - if [[ ! -d "$lang" ]]; then - echo "Did not find a database for $lang" - exit 1 - fi - echo "Found database for $lang" - done diff --git a/pr-checks/deflake.ts b/pr-checks/deflake.ts index a682ae2028..0e0b38bed0 100644 --- a/pr-checks/deflake.ts +++ b/pr-checks/deflake.ts @@ -26,6 +26,7 @@ const NON_GENERATED_WORKFLOWS_TO_RERUN = [ "CodeQL action", "PR Check - Debug artifact upload", "PR Check - Debug artifacts after failure", + "PR Check - Runner images", "PR Checks", "Query filters tests", "Test that the workaround for python 3.12 on windows works", diff --git a/pr-checks/package.json b/pr-checks/package.json index e18e433d47..4224f2dee5 100644 --- a/pr-checks/package.json +++ b/pr-checks/package.json @@ -22,6 +22,7 @@ }, "devDependencies": { "@types/node": "^24.19.0", + "jsonschema": "^1.5.0", "tsx": "^4.23.15" } } diff --git a/pr-checks/runner-images.schema.json b/pr-checks/runner-images.schema.json new file mode 100644 index 0000000000..d734fd65e5 --- /dev/null +++ b/pr-checks/runner-images.schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Runner images", + "description": "The GitHub-hosted runner images that the `runner-images` PR check runs on", + "type": "object", + "properties": { + "images": { + "description": "Labels of the runner images that the check runs on", + "type": "array", + "items": { "type": "string", "minLength": 1 }, + "minItems": 1, + "uniqueItems": true + }, + "excluded": { + "description": "Labels of the runner images that the check doesn't run on, mapped to the reasons", + "type": "object", + "additionalProperties": { "type": "string", "minLength": 1 } + } + }, + "required": ["images"], + "additionalProperties": false +} diff --git a/pr-checks/runner-images.test.ts b/pr-checks/runner-images.test.ts new file mode 100644 index 0000000000..3b23b36d74 --- /dev/null +++ b/pr-checks/runner-images.test.ts @@ -0,0 +1,34 @@ +#!/usr/bin/env npx tsx + +/* +Checks that `runner-images.yml` matches its schema. +*/ + +import * as assert from "node:assert/strict"; +import * as fs from "node:fs"; +import * as path from "node:path"; +import { describe, it } from "node:test"; + +import * as jsonschema from "jsonschema"; +import * as yaml from "yaml"; + +import { PR_CHECKS_DIR } from "./config"; + +describe("runner-images.yml", async () => { + await it("matches runner-images.schema.json", () => { + const contents: unknown = yaml.parse( + fs.readFileSync(path.join(PR_CHECKS_DIR, "runner-images.yml"), "utf8"), + ); + const schema = JSON.parse( + fs.readFileSync( + path.join(PR_CHECKS_DIR, "runner-images.schema.json"), + "utf8", + ), + ) as jsonschema.Schema; + const result = new jsonschema.Validator().validate(contents, schema); + assert.deepEqual( + result.errors.map((error) => error.stack), + [], + ); + }); +}); diff --git a/pr-checks/runner-images.yml b/pr-checks/runner-images.yml new file mode 100644 index 0000000000..f08b7d3f4e --- /dev/null +++ b/pr-checks/runner-images.yml @@ -0,0 +1,36 @@ +# The GitHub-hosted runner images that the `runner-images` PR check runs on, identified by their +# labels. +# +# Each image has a required check. Before merging a PR that adds or removes images, a maintainer +# needs to wait for the PR's checks to finish, then update the required checks by running +# `pr-checks/sync-checks.ts` with `--ref` set to the PR's head commit. +# +# The check runs on each image listed in +# https://github.com/actions/runner-images#available-images, apart from the ones under `excluded` +# and any that GitHub is about to retire. +images: + # The Ubuntu 22.04 images have brownouts from 23 March 2027 and are retired on 17 April 2027, so + # remove them before the brownouts start. + # See https://github.com/actions/runner-images/issues/14254. + - ubuntu-22.04 + - ubuntu-22.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm + - ubuntu-26.04 + - ubuntu-26.04-arm + - windows-2022 + - windows-2025 + # Use larger runners for macOS to keep these jobs off the critical path. + - macos-15-large + - macos-15-xlarge + - macos-26-large + - macos-26-xlarge +# The images that the check doesn't run on, with the reasons. +excluded: + ubuntu-slim: > + It's intended for lightweight jobs rather than builds like the ones this check runs. + windows-11-arm: > + CodeQL doesn't support Windows on Arm64. + xcode-27: > + CodeQL doesn't support traced analysis on macOS 27 or later, or with Xcode 27 or later. + The `unsupported-macos` check runs on this image instead.