Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:
description: "Action (check_progress, assign_next, reset)"
required: false
default: "check_progress"
create:
types: [repository]
Comment on lines +19 to +20

concurrency:
group: skills-progression-${{ github.event.pull_request.number || github.event.issue.number || github.run_id }}
Expand Down Expand Up @@ -162,3 +164,47 @@ jobs:
} catch (error) {
console.error('Error awarding achievement:', error);
}

create-first-issue:
name: Create First Challenge Issue
runs-on: ubuntu-latest
if: github.event_name == 'create'

steps:
- name: Create First Issue
uses: actions/github-script@v7
with:
script: |
const issueTitle = "Welcome to Your First Challenge!";
const issueBody = `
## Your First Challenge
Welcome to the repository! Your first challenge is to complete the following steps:
- [ ] Clone this repository to your local machine.
- [ ] Make a small change to the README file.
- [ ] Commit and push your changes.
- [ ] Open a pull request to merge your changes.

Once you complete these steps, close this issue to unlock the next challenge!
`;

const { data: existingIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
labels: 'first-issue',
per_page: 100
});

const alreadyExists = existingIssues.some((issue) => issue.title === issueTitle);
if (alreadyExists) {
console.log('First challenge issue already exists. Skipping creation.');
return;
}

await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
labels: ['challenge', 'first-issue']
});
46 changes: 46 additions & 0 deletions learning-room/.github/workflows/skills-progression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:
description: "Action (check_progress, assign_next, reset)"
required: false
default: "check_progress"
create:
types: [repository]
Comment on lines +19 to +20

concurrency:
group: skills-progression-${{ github.event.pull_request.number || github.event.issue.number || github.run_id }}
Expand Down Expand Up @@ -162,3 +164,47 @@ jobs:
} catch (error) {
console.error('Error awarding achievement:', error);
}

create-first-issue:
name: Create First Challenge Issue
runs-on: ubuntu-latest
if: github.event_name == 'create'

steps:
- name: Create First Issue
uses: actions/github-script@v7
with:
script: |
const issueTitle = "Welcome to Your First Challenge!";
const issueBody = `
## Your First Challenge
Welcome to the repository! Your first challenge is to complete the following steps:
- [ ] Clone this repository to your local machine.
- [ ] Make a small change to the README file.
- [ ] Commit and push your changes.
- [ ] Open a pull request to merge your changes.

Once you complete these steps, close this issue to unlock the next challenge!
`;

const { data: existingIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
labels: 'first-issue',
per_page: 100
});

const alreadyExists = existingIssues.some((issue) => issue.title === issueTitle);
if (alreadyExists) {
console.log('First challenge issue already exists. Skipping creation.');
return;
}

await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
labels: ['challenge', 'first-issue']
});
5 changes: 2 additions & 3 deletions scripts/classroom/Restore-LearningRoomFiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ function Get-ProfilePaths {
'docs/setup-guide.md'
)
'core-day2' = @(
'docs/samples/copilot-improvement-before.md',
'docs/samples/peer-review-practice.md'
'docs/samples/copilot-improvement-before.md'
)
'automation-core' = @(
'.github/workflows/pr-validation-bot.yml',
Expand Down Expand Up @@ -138,7 +137,7 @@ try {
Invoke-CheckedCommand git @('checkout', "template/$TemplateRef", '--', $file)
}

Invoke-CheckedCommand git @('add', '--', $selectedPaths)
Invoke-CheckedCommand git (@('add', '--') + $selectedPaths)

$status = git status --short
if (-not $status) {
Expand Down
31 changes: 0 additions & 31 deletions scripts/classroom/Seed-LearningRoomChallenge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,3 @@ Invoke-CheckedCommand gh $arguments

Write-Host "Workflow started. Check the repository Actions tab, then verify the issue list:"
Write-Host " gh issue list -R $Repository --search \"Challenge $Challenge\""
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Repository,

[ValidateRange(1, 16)]
[int]$Challenge = 1,

[string]$Assignee = ''
)

$ErrorActionPreference = 'Stop'

function Invoke-CheckedCommand {
param([string]$FilePath, [string[]]$Arguments)
& $FilePath @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed: $FilePath $($Arguments -join ' ')"
}
}

$fields = @('-f', "start_challenge=$Challenge")
if ($Assignee) {
$fields += @('-f', "assignee=$Assignee")
}

Write-Host "Triggering student progression workflow in $Repository for Challenge $Challenge..."
Invoke-CheckedCommand gh @('workflow', 'run', 'student-progression.yml', '-R', $Repository) + $fields

Write-Host "Workflow started. Check the repository Actions tab, then verify the issue list:"
Write-Host " gh issue list -R $Repository --search \"Challenge $Challenge\""
224 changes: 224 additions & 0 deletions scripts/classroom/Sync-StudentLearningRoomRepos.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
[CmdletBinding()]
param(
[string]$StudentRepository = '',

[string]$ClassroomOrg = 'Community-Access-Classroom',

[string]$TemplateRef = 'main',

[ValidateSet('core-day1', 'core-day2', 'automation-core', 'all-core', 'custom')]
[string]$Profile = 'all-core',

[string[]]$RepoPrefixes = @('you-belong-here-', 'you-can-build-this-'),

[switch]$OpenPullRequest,

[switch]$AutoMerge,

[switch]$AdminMerge,

[switch]$DryRun,

[switch]$Force
)

$ErrorActionPreference = 'Stop'

function Invoke-CheckedCommand {
param([string]$FilePath, [string[]]$Arguments)

& $FilePath @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed: $FilePath $($Arguments -join ' ')"
}
}

function Invoke-GhJson {
param([string[]]$Arguments)

$json = & gh @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed: gh $($Arguments -join ' ')"
}

if (-not $json) {
return $null
}

return $json | ConvertFrom-Json
}

function Test-RepositoryHasActivity {
param([string]$Repository)

$activity = [ordered]@{
HasNonMainBranch = $false
HasOpenPR = $false
}

$branches = Invoke-GhJson -Arguments @('api', "repos/$Repository/branches?per_page=100")
if ($branches) {
$nonMain = @($branches | Where-Object { $_.name -ne 'main' })
if ($nonMain.Count -gt 0) {
$activity.HasNonMainBranch = $true
}
}

$openPrs = Invoke-GhJson -Arguments @('pr', 'list', '-R', $Repository, '--state', 'open', '--json', 'number')
if ($openPrs) {
if (@($openPrs).Count -gt 0) {
$activity.HasOpenPR = $true
}
}

return [PSCustomObject]$activity
}

function Get-TargetRepositories {
param(
[string]$SingleRepository,
[string]$Organization,
[string[]]$Prefixes
)

if ($SingleRepository) {
return @($SingleRepository)
}

$repos = Invoke-GhJson -Arguments @('repo', 'list', $Organization, '--limit', '500', '--json', 'name,nameWithOwner,isPrivate')
if (-not $repos) {
return @()
}

$targets = @()
foreach ($repo in $repos) {
if (-not $repo.isPrivate) {
continue
}

foreach ($prefix in $Prefixes) {
if ($repo.name.StartsWith($prefix, [System.StringComparison]::OrdinalIgnoreCase)) {
$targets += $repo.nameWithOwner
break
}
}
}

return $targets
}

Write-Host 'Checking GitHub CLI authentication...'
Invoke-CheckedCommand gh @('auth', 'status', '-h', 'github.com')

$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
$restoreScript = Join-Path $scriptDir 'Restore-LearningRoomFiles.ps1'
if (-not (Test-Path -LiteralPath $restoreScript -PathType Leaf)) {
throw "Required script not found: $restoreScript"
}

$targets = Get-TargetRepositories -SingleRepository $StudentRepository -Organization $ClassroomOrg -Prefixes $RepoPrefixes
if (-not $targets -or $targets.Count -eq 0) {
Write-Host 'No target repositories found. Nothing to do.'
return
}

Write-Host "Found $($targets.Count) target repository/repositories."

$summary = @()

foreach ($repo in $targets) {
Write-Host ''
Write-Host "Processing $repo"

$row = [ordered]@{
Repository = $repo
Status = 'unknown'
Details = ''
}

try {
if (-not $Force) {
$activity = Test-RepositoryHasActivity -Repository $repo
if ($activity.HasNonMainBranch -or $activity.HasOpenPR) {
$reasons = @()
if ($activity.HasNonMainBranch) { $reasons += 'non-main branches exist' }
if ($activity.HasOpenPR) { $reasons += 'open PRs exist' }

$row.Status = 'skipped'
$row.Details = ($reasons -join '; ')
Write-Host "Skipping due to activity: $($row.Details)"
$summary += [PSCustomObject]$row
continue
}
}

$stamp = Get-Date -Format 'yyyyMMddHHmmss'
$branchName = "recovery/template-sync-$stamp"

$restoreParams = @{
StudentRepository = $repo
Profile = $Profile
TemplateRef = $TemplateRef
BranchName = $branchName
CommitMessage = 'chore: sync learning-room template baseline'
}

if ($OpenPullRequest -or $AutoMerge) {
$restoreParams.OpenPullRequest = $true
}

if ($DryRun) {
$row.Status = 'dry-run'
$row.Details = "Would run restore on branch $branchName"
Write-Host $row.Details
$summary += [PSCustomObject]$row
continue
}

& $restoreScript @restoreParams
if ($LASTEXITCODE -ne 0) {
throw "Restore script failed for $repo"
}

if ($AutoMerge) {
$prNumber = & gh pr list -R $repo --head $branchName --state open --json number --jq '.[0].number'
if ($LASTEXITCODE -ne 0) {
throw "Could not query PR number for $repo"
}

if (-not $prNumber) {
$row.Status = 'updated'
$row.Details = 'No open recovery PR found after restore (possibly no diff)'
Write-Host $row.Details
$summary += [PSCustomObject]$row
continue
}

$mergeArgs = @('pr', 'merge', $prNumber, '-R', $repo, '--squash', '--delete-branch')
if ($AdminMerge) {
$mergeArgs += '--admin'
}

Invoke-CheckedCommand gh $mergeArgs
$row.Status = 'merged'
$row.Details = "Merged PR #$prNumber"
Write-Host $row.Details
}
else {
$row.Status = 'updated'
$row.Details = 'Restore completed'
Write-Host $row.Details
}
}
catch {
$row.Status = 'failed'
$row.Details = $_.Exception.Message
Write-Warning $row.Details
}

$summary += [PSCustomObject]$row
}

Write-Host ''
Write-Host 'Summary'
$summary | Format-Table -AutoSize
Loading
Loading