Files
awesome-copilot/.github/workflows/check-plugin-structure.yml
T
James MontemagnoandCopilot App d6131471b8 Phase 2: submission-gate, risk tiers, and PR status state machine (#4184) (#4190)
* Add submission-gate check, merge-risk tiers, and PR status state machine (#4184)

Phase 2 (enforcement) of github/awesome-copilot#4184:
- submission-gate aggregate required check (reader) with infra vs contribution failure classification
- merge-risk:low/medium/high classification from .github/risk-tiers.yml with tier approval policy
- Submission Gate Writer maintaining state labels and a persistent status comment
- /rerun-checks and /request-review PR commands
- validate-skills and validate-submission-gate workflows, unit tests, and maintainer docs

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Fix codespell findings and add spelling to submission gate checks

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Harden submission gate per review feedback

- Publish the submission-gate check from the trusted writer via the Checks API
  and flag any other submission-gate check run as tampering
- Fail closed on truncated file lists, unscannable diffs, permission lookup
  errors, and skipped required checks
- Discard evaluations when the PR head or reviews change mid-run
- Low tier requires a resource owner approval
- Commands must start the comment, matching the workflow filter

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Address #4190 review: command reader/writer, pools, paths, staleness

- Split /rerun-checks and /request-review into a read-only issue_comment
  reader and a workflow_run writer that re-reads the comment, PR, and
  permission before writing.
- Drop the workflow-security pool; agentic workflows and hooks are
  content (medium unless they add scripts or hook commands); the core
  pool is core-maintainers.
- Include each check's workflow file and eng scripts in its paths.
- Discard evaluations when the base branch or risk labels change; run
  the gate on PR edits (retargeting).
- Correct copies of the writer's check that claim success while the
  evaluation fails.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Fail closed on lost contributor signal; publish gate check before labels

- A contributor check whose pr-check job succeeded but whose result artifact
  is missing or unreadable is now an infrastructure failure, so a lost HIGH
  signal can't lower the approval tier.
- Publish the submission-gate check right after stale-state revalidation;
  label and comment sync are independent and reported afterwards.
- Revert the self-path added to validate-agentic-workflows-pr.yml's trigger:
  that workflow rejects any .github change. Exempt it in the drift test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Fail closed on bad routing config; advisory checks never hold the gate

- loadGateConfig: a missing review-routing.yml still falls back, but a
  file that can't be parsed (or whose pools isn't a mapping) now throws
  instead of silently relaxing approvals.
- Pending required: false checks no longer keep the PR in
  awaiting-automation or the gate check in progress, and the polling loop
  doesn't wait on them. They render as pending (advisory).
- PR commands: 👀 marks a command as claimed; 🚀 is written only after
  the reply is posted and is the only replay guard, so a run that failed
  partway can be retried.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Fix codespell: unparseable -> unparsable

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-10-01 11:39:09 +10:00

187 lines
7.0 KiB
YAML

name: Check Plugin Structure
on:
pull_request:
branches: [main]
paths:
- "plugins/**"
- ".github/workflows/check-plugin-structure.yml"
permissions:
contents: read
pull-requests: write
jobs:
check-materialized-files:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Check for materialized files in plugin directories
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const fs = require('fs');
const path = require('path');
const pluginsDir = 'plugins';
const errors = [];
function findSymlinks(rootDir) {
const symlinks = [];
const dirsToScan = [rootDir];
while (dirsToScan.length > 0) {
const currentDir = dirsToScan.pop();
let entries;
try {
entries = fs.readdirSync(currentDir, { withFileTypes: true });
} catch (error) {
throw new Error(`Failed to read directory "${currentDir}": ${error.message}`);
}
for (const entry of entries) {
const entryPath = path.join(currentDir, entry.name);
let stat;
try {
stat = fs.lstatSync(entryPath);
} catch (error) {
throw new Error(`Failed to inspect "${entryPath}": ${error.message}`);
}
if (stat.isSymbolicLink()) {
symlinks.push(entryPath);
continue;
}
if (stat.isDirectory()) {
dirsToScan.push(entryPath);
}
}
}
return symlinks;
}
if (!fs.existsSync(pluginsDir)) {
console.log('No plugins directory found');
return;
}
const pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true })
.filter(d => d.isDirectory())
.map(d => d.name);
for (const plugin of pluginDirs) {
const pluginPath = path.join(pluginsDir, plugin);
// Check for materialized agent/command/skill files
for (const subdir of ['agents', 'commands', 'skills']) {
const subdirPath = path.join(pluginPath, subdir);
if (!fs.existsSync(subdirPath)) continue;
const stat = fs.lstatSync(subdirPath);
if (stat.isSymbolicLink()) {
errors.push(`${pluginPath}/${subdir} is a symlink — symlinks should not exist in plugin directories`);
continue;
}
if (stat.isDirectory()) {
const files = fs.readdirSync(subdirPath);
if (files.length > 0) {
errors.push(
`${pluginPath}/${subdir}/ contains ${files.length} file(s): ${files.join(', ')}. ` +
`Plugin directories on main should only contain plugin.json and README.md. ` +
`Agent, command, and skill files are materialized automatically during publish to marketplace.`
);
}
}
}
// Check for symlinks anywhere in the plugin directory without invoking a shell
try {
const symlinkPaths = findSymlinks(pluginPath);
if (symlinkPaths.length > 0) {
const formattedPaths = symlinkPaths.map(filePath => `\`${filePath}\``).join(', ');
errors.push(`${pluginPath} contains symlinks: ${formattedPaths}`);
}
} catch (error) {
errors.push(`Failed to inspect ${pluginPath} for symlinks: ${error.message}`);
}
}
if (errors.length > 0) {
const prBranch = context.payload.pull_request.head.ref;
const prRepo = context.payload.pull_request.head.repo.full_name;
const isFork = context.payload.pull_request.head.repo.fork;
const body = [
'⚠️ **Materialized files or symlinks detected in plugin directories**',
'',
'Plugin directories on the `main` branch should only contain:',
'- `plugin.json` (metadata)',
'- `README.md`',
'',
'Agent, command, and skill files are copied in automatically when publishing to `marketplace`.',
'',
'**Issues found:**',
...errors.map(e => `- ${e}`),
'',
'---',
'',
'### How to fix',
'',
'It looks like your branch may include materialized plugin files that should not be on `main`. Here are two options:',
'',
'**Option 1: Rebase to drop materialized files** (recommended if you have few commits)',
'```bash',
`git fetch origin main`,
`git rebase --onto origin/main origin/main ${prBranch}`,
`git push --force-with-lease`,
'```',
'',
'**Option 2: Remove the extra files manually**',
'```bash',
'# Remove materialized files from plugin directories',
'find plugins/ -mindepth 2 -maxdepth 2 -type d \\( -name agents -o -name commands -o -name skills \\) -exec rm -rf {} +',
'# Remove any symlinks',
'find plugins/ -type l -delete',
'git add -A && git commit -m "fix: remove materialized plugin files"',
'git push',
'```',
].join('\n');
let reviewPosted = false;
if (!isFork) {
try {
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'REQUEST_CHANGES',
body
});
reviewPosted = true;
} catch (error) {
core.warning(
`Could not create PR review (continuing with failure report): ${error.message}`
);
}
} else {
core.warning('PR is from a fork; skipping createReview to avoid permission errors.');
}
if (!reviewPosted) {
core.warning('Materialized plugin issues detected. Full details:');
core.warning(body);
}
core.setFailed('Plugin directories contain materialized files or symlinks that should not be on main');
} else {
console.log('✅ All plugin directories are clean');
}