|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [Parameter(Mandatory = $true)][string]$Org, |
| 4 | + [switch]$Teardown |
| 5 | +) |
| 6 | + |
| 7 | +$ErrorActionPreference = 'Stop' |
| 8 | +$repo = 'ghec-ch31-copilot-environment-instructions' |
| 9 | +$repoFull = "$Org/$repo" |
| 10 | + |
| 11 | +if (-not (Get-Command gh -ErrorAction SilentlyContinue)) { |
| 12 | + throw 'gh is required' |
| 13 | +} |
| 14 | + |
| 15 | +if ($Teardown) { |
| 16 | + if (-not $repo.StartsWith('ghec-ch31-')) { |
| 17 | + throw 'Refusing to delete a non-ch31 repository' |
| 18 | + } |
| 19 | + gh repo delete $repoFull --yes |
| 20 | + Write-Host "Deleted $repoFull" |
| 21 | + exit 0 |
| 22 | +} |
| 23 | + |
| 24 | +gh repo view $repoFull 2>$null |
| 25 | +if ($LASTEXITCODE -ne 0) { |
| 26 | + gh repo create $repoFull --public --description 'Safe fallback for GHEC Ch31 Copilot environment instructions' |
| 27 | +} |
| 28 | + |
| 29 | +function Set-SeedFile { |
| 30 | + param([string]$Path, [string]$Message, [string]$Content) |
| 31 | + |
| 32 | + $sha = gh api "repos/$repoFull/contents/$Path" --jq .sha 2>$null |
| 33 | + $encoded = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($Content)) |
| 34 | + $args = @('--method', 'PUT', "repos/$repoFull/contents/$Path", '-f', "message=$Message", '-f', "content=$encoded") |
| 35 | + if ($sha) { $args += @('-f', "sha=$sha") } |
| 36 | + gh api @args | Out-Null |
| 37 | +} |
| 38 | + |
| 39 | +Set-SeedFile -Path 'README.md' -Message 'Add Ch31 fallback overview' -Content @' |
| 40 | +# GHEC Ch31 — Copilot Environment & Instructions |
| 41 | +
|
| 42 | +Safe fallback repository for validating a Copilot setup workflow and instruction |
| 43 | +layout. It contains no customer data, secret, service, internal endpoint, runner, |
| 44 | +or Copilot policy change. |
| 45 | +
|
| 46 | +Run `npm ci && npm test`. The default-branch setup workflow is the common |
| 47 | +environment baseline for Copilot cloud agent and Copilot code review. |
| 48 | +'@ |
| 49 | + |
| 50 | +Set-SeedFile -Path 'package.json' -Message 'Add minimal Node.js fixture' -Content @' |
| 51 | +{ |
| 52 | + "name": "ghec-ch31-copilot-environment-instructions", |
| 53 | + "version": "1.0.0", |
| 54 | + "private": true, |
| 55 | + "scripts": { |
| 56 | + "test": "node test/greeting.test.js" |
| 57 | + } |
| 58 | +} |
| 59 | +'@ |
| 60 | + |
| 61 | +Set-SeedFile -Path 'package-lock.json' -Message 'Add npm lockfile' -Content @' |
| 62 | +{ |
| 63 | + "name": "ghec-ch31-copilot-environment-instructions", |
| 64 | + "version": "1.0.0", |
| 65 | + "lockfileVersion": 3, |
| 66 | + "requires": true, |
| 67 | + "packages": { |
| 68 | + "": { |
| 69 | + "name": "ghec-ch31-copilot-environment-instructions", |
| 70 | + "version": "1.0.0" |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | +'@ |
| 75 | + |
| 76 | +Set-SeedFile -Path 'src/greeting.js' -Message 'Add greeting fixture' -Content @' |
| 77 | +function formatGreeting (name) { |
| 78 | + return `Hello, ${name}!` |
| 79 | +} |
| 80 | +
|
| 81 | +module.exports = { formatGreeting } |
| 82 | +'@ |
| 83 | + |
| 84 | +Set-SeedFile -Path 'test/greeting.test.js' -Message 'Add fixture test' -Content @' |
| 85 | +const assert = require('assert') |
| 86 | +const { formatGreeting } = require('../src/greeting') |
| 87 | +
|
| 88 | +assert.strictEqual(formatGreeting('Ada'), 'Hello, Ada!') |
| 89 | +console.log('greeting test passed') |
| 90 | +'@ |
| 91 | + |
| 92 | +Set-SeedFile -Path '.github/copilot-instructions.md' -Message 'Add repository Copilot instructions' -Content @' |
| 93 | +# Repository instructions |
| 94 | +
|
| 95 | +Use Node.js 20. Run `npm ci` and `npm test` before proposing a change. Keep |
| 96 | +changes small, avoid adding secrets or network access, and explain validation in |
| 97 | +the pull request. Human review and CI remain required. |
| 98 | +'@ |
| 99 | + |
| 100 | +Set-SeedFile -Path '.github/instructions/source.instructions.md' -Message 'Add path-specific Copilot instructions' -Content @' |
| 101 | +--- |
| 102 | +applyTo: "src/**/*.js" |
| 103 | +--- |
| 104 | +Use CommonJS exports. Update the matching test under `test/` for behavior |
| 105 | +changes and run `npm test`. |
| 106 | +'@ |
| 107 | + |
| 108 | +Set-SeedFile -Path '.github/workflows/copilot-setup-steps.yml' -Message 'Add Copilot setup steps' -Content @' |
| 109 | +name: Copilot setup steps |
| 110 | +
|
| 111 | +on: |
| 112 | + workflow_dispatch: |
| 113 | + push: |
| 114 | + paths: [.github/workflows/copilot-setup-steps.yml] |
| 115 | + pull_request: |
| 116 | + paths: [.github/workflows/copilot-setup-steps.yml] |
| 117 | +
|
| 118 | +jobs: |
| 119 | + copilot-setup-steps: |
| 120 | + runs-on: ubuntu-latest |
| 121 | + permissions: |
| 122 | + contents: read |
| 123 | + timeout-minutes: 15 |
| 124 | + steps: |
| 125 | + - uses: actions/checkout@v4 |
| 126 | + - uses: actions/setup-node@v4 |
| 127 | + with: |
| 128 | + node-version: "20" |
| 129 | + cache: npm |
| 130 | + - run: npm ci |
| 131 | + - run: npm test |
| 132 | +'@ |
| 133 | + |
| 134 | +$issueTitle = 'Validate the Copilot environment and instructions' |
| 135 | +$existing = gh issue list --repo $repoFull --state all --limit 100 --json title --jq '.[].title' 2>$null |
| 136 | +if ($existing -notcontains $issueTitle) { |
| 137 | + $body = @' |
| 138 | +Validate the default-branch Copilot setup workflow and instruction layout. |
| 139 | +
|
| 140 | +Acceptance criteria: |
| 141 | +- Run the setup workflow from Actions and retain its successful URL. |
| 142 | +- Make a small, reviewed pull request that changes `src/greeting.js`. |
| 143 | +- Confirm the repository and matching path-specific instructions are on the PR head branch. |
| 144 | +- Request approved Copilot code review and/or assign an approved cloud-agent task. |
| 145 | +- Record observed evidence and any unavailable-feature limitation. |
| 146 | +
|
| 147 | +Do not add a secret, service, self-hosted runner, or policy change to this seed. |
| 148 | +'@ |
| 149 | + gh issue create --repo $repoFull --title $issueTitle --body $body | Out-Null |
| 150 | +} |
| 151 | + |
| 152 | +Write-Host "Safe fallback ready: $repoFull" |
| 153 | +Write-Host 'Next: confirm the setup workflow is on the repository default branch, run it from Actions, then use the bounded issue only if the applicable Copilot feature is approved.' |
0 commit comments