An open source design system that's fully customizable and agent ready
TypeScript
ci(lint): actionlint runs when a pull request changes a workflow or composite action (#9382)
Cindy Zhang177eed653991
diff --git a/.github/actionlint.yaml b/.github/actionlint.yamlnew file mode 100644index 0000000000..cfaecb264d--- /dev/null+++ b/.github/actionlint.yaml@@ -0,0 +1,11 @@+# Copyright (c) Meta Platforms, Inc. and affiliates.++# Configuration for actionlint, which the Lint workflow runs when a pull+# request changes a workflow or composite action (spec:AST-030 FR11).+self-hosted-runner:+ # Larger-runner labels this repository's paid pools use; actionlint cannot+ # know them, so each is named here. A label a workflow uses that is neither+ # GitHub-hosted nor listed fails (ci-actionlint.test.mjs).+ labels:+ - 2-core-ubuntu-arm+ - 4-core-ubuntudiff --git a/.github/scripts/ci-actionlint.test.mjs b/.github/scripts/ci-actionlint.test.mjsnew file mode 100644index 0000000000..fcb6e8a6e6--- /dev/null+++ b/.github/scripts/ci-actionlint.test.mjs@@ -0,0 +1,100 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file ci-actionlint.test.mjs+ * @input .github/workflows/lint.yml, .github/actionlint.yaml and every workflow+ * @output Contract for the Lint workflow's actionlint step: it runs only when a+ * pull request changes a workflow, a composite action or the actionlint+ * configuration; it pins actionlint by version and checksum; shellcheck+ * reports errors only; a finding fails the step; and every non-GitHub-hosted+ * runner label a workflow names is declared in the configuration+ * @position Contract test for the repository's GitHub Actions workflows+ * (spec:AST-030 FR11)+ */++import fs from 'node:fs';+import path from 'node:path';+import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++const root = path.resolve(import.meta.dirname, '../..');+const lint = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/lint.yml'), 'utf8'),+);+const job = lint.jobs.lint;+const step = job.steps.find(+ candidate => candidate.name === 'Lint changed workflows (actionlint)',+);+const config = yaml.parse(+ fs.readFileSync(path.join(root, '.github/actionlint.yaml'), 'utf8'),+);++/** GitHub-hosted labels actionlint already knows. */+const HOSTED = /^(ubuntu|windows|macos)-/;++describe('Lint: actionlint on workflow changes', () => {+ it('runs on pull requests and skips unless a workflow, action or the config changed', () => {+ expect(step).toBeDefined();+ expect(step.if).toBe("github.event_name == 'pull_request'");+ expect(step.run).toContain(+ 'git diff --quiet "$MERGE_BASE"...HEAD -- .github/workflows .github/actions .github/actionlint.yaml',+ );+ // An unknown merge base runs it rather than skipping.+ expect(step.run).toContain('if [ -n "$MERGE_BASE" ] && git diff --quiet');+ // It comes after the classifier step that fetches the base branch.+ const names = job.steps.map(candidate => candidate.name);+ expect(names.indexOf('Classify changed files')).toBeLessThan(+ names.indexOf(step.name),+ );+ });++ it('pins actionlint by version and checksum for the arm64 runner', () => {+ expect(job['runs-on']).toBe('ubuntu-24.04-arm');+ expect(step.env.ACTIONLINT_VERSION).toMatch(/^\d+\.\d+\.\d+$/);+ expect(step.env.ACTIONLINT_SHA256).toMatch(/^[0-9a-f]{64}$/);+ expect(step.run).toContain('linux_arm64.tar.gz');+ expect(step.run).toContain('sha256sum -c -');+ });++ it('runs shellcheck at error severity and fails the step on a finding', () => {+ expect(step.run).toContain(+ 'if ! SHELLCHECK_OPTS=--severity=error "$RUNNER_TEMP/actionlint" -color -shellcheck=shellcheck -pyflakes=; then',+ );+ // A failure tells a contributor, a fork's included, how to run it locally.+ expect(step.run).toContain('::error title=actionlint::');+ expect(step.run).toContain(+ 'https://github.com/rhysd/actionlint/blob/main/docs/install.md',+ );+ expect(step.run).toContain(+ 'run SHELLCHECK_OPTS=--severity=error actionlint from the repository root',+ );+ expect(step.run).toContain('exit 1');+ // shellcheck must be present, or actionlint would skip it silently.+ expect(step.run).toContain('command -v shellcheck >/dev/null || {');+ expect(step['continue-on-error']).toBeUndefined();+ });++ it('declares every non-GitHub-hosted runner label a workflow names', () => {+ const declared = new Set(config['self-hosted-runner'].labels);+ const used = new Set();+ for (const name of fs.readdirSync(path.join(root, '.github/workflows'))) {+ if (!/\.ya?ml$/.test(name)) continue;+ const source = fs.readFileSync(+ path.join(root, '.github/workflows', name),+ 'utf8',+ );+ for (const match of source.matchAll(+ /\b(\d+-core-[a-z0-9-]+|[a-z0-9-]+-release-pool)\b/g,+ )) {+ used.add(match[1]);+ }+ for (const match of source.matchAll(+ /^\s*runs-on:\s*([^\s$'"{]+)\s*$/gm,+ )) {+ if (!HOSTED.test(match[1])) used.add(match[1]);+ }+ }+ const missing = [...used].filter(label => !declared.has(label)).sort();+ expect(missing).toEqual([]);+ });+});diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex ce65dca24c..c0d4b833f7 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2969,6 +2969,8 @@ jobs:id: rtlif: (steps.rtl-scope.outputs.should_run == 'true') && (steps.scope.outputs.has_rtl_components == 'true' || steps.scope.outputs.has_rtl_harness == 'true' || steps.scope.outputs.force_full_component_audits == 'true')continue-on-error: true+ env:+ PARTS: ${{ matrix.parts }}run: |PACKAGE=${{ matrix.package }}COMPONENTS="${{ steps.rtl-scope.outputs.components }}"@@ -2978,7 +2980,7 @@ jobs:FILTER_ARGS=(--filter "$FILTER")fiSHARD_ARGS=()- if [ "${{ matrix.parts }}" -gt 1 ]; then+ if [ "$PARTS" -gt 1 ]; thenSHARD_ARGS=(--shard "${{ matrix.part }}/${{ matrix.parts }}" --shard-output "rtl-shard-${{ matrix.part }}.json")fiecho "Auditing $PACKAGE components: $COMPONENTS"@@ -2992,6 +2994,8 @@ jobs:- name: Require completed RTL shard reportif: always() && (steps.scope.outputs.has_rtl_components == 'true' || steps.scope.outputs.has_rtl_harness == 'true' || steps.scope.outputs.force_full_component_audits == 'true')+ env:+ PARTS: ${{ matrix.parts }}run: |SCOPE_OUTCOME="${{ steps.rtl-scope.outcome }}"SHOULD_RUN="${{ steps.rtl-scope.outputs.should_run }}"@@ -3005,7 +3009,7 @@ jobs:echo "Applicable RTL audit did not run: $AUDIT_OUTCOME"exit 1fi- if [ "${{ matrix.parts }}" -gt 1 ]; then+ if [ "$PARTS" -gt 1 ]; then# A part writes cards only; pr-rtl-merge checks the joined report.test -s "rtl-shard-${{ matrix.part }}.json"elsediff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex a7c404d468..a78375c020 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -66,6 +66,41 @@ jobs:>> "$GITHUB_OUTPUT"fi+ # A change to a workflow, a composite action or this config runs+ # actionlint over the workflows, with shellcheck on their run: scripts,+ # so a broken expression, an unknown runner label or a script that cannot+ # work fails here instead of on every later run. actionlint checks a+ # local action's metadata and inputs where a workflow uses it, not the+ # action's own steps; ci-run-scripts-parse.test.mjs parses those.+ # Any other pull request skips it in a second. The binary is pinned by+ # version and checksum; shellcheck reports errors only, so its existing+ # warnings never block (spec:AST-030 FR11).+ - name: Lint changed workflows (actionlint)+ if: github.event_name == 'pull_request'+ env:+ ACTIONLINT_VERSION: 1.7.12+ ACTIONLINT_SHA256: 325e971b6ba9bfa504672e29be93c24981eeb1c07576d730e9f7c8805afff0c6+ BASE_REF: ${{ github.base_ref }}+ run: |+ MERGE_BASE=$(git merge-base HEAD "origin/$BASE_REF" 2>/dev/null || echo "")+ if [ -n "$MERGE_BASE" ] && git diff --quiet "$MERGE_BASE"...HEAD -- .github/workflows .github/actions .github/actionlint.yaml; then+ echo "No workflow or composite action changed; actionlint skipped."+ exit 0+ fi+ if ! command -v shellcheck >/dev/null; then+ sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends shellcheck >/dev/null+ fi+ command -v shellcheck >/dev/null || { echo "::error::shellcheck is not installed."; exit 1; }+ archive="$RUNNER_TEMP/actionlint.tar.gz"+ curl -fsSL -o "$archive" \+ "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_arm64.tar.gz"+ echo "$ACTIONLINT_SHA256 $archive" | sha256sum -c -+ tar -xzf "$archive" -C "$RUNNER_TEMP" actionlint+ if ! SHELLCHECK_OPTS=--severity=error "$RUNNER_TEMP/actionlint" -color -shellcheck=shellcheck -pyflakes=; then+ echo "::error title=actionlint::A workflow or composite action has the problems listed above. To check locally, install actionlint (https://github.com/rhysd/actionlint/blob/main/docs/install.md) and shellcheck, then run SHELLCHECK_OPTS=--severity=error actionlint from the repository root."+ exit 1+ fi+# Merge-back carries exact published release-branch outputs into main under# trusted validation (spec:AST-017 FR50). Detect its branch contract so# required lint can route it to the stronger validator.