Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sync]: update doc generator branch #594

Merged
merged 6 commits into from
Jan 25, 2024
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
28 changes: 25 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ on:
- cron: '0 0 * * 0'

jobs:
generator:
name: Check Generator Templates
test-generator:
name: Test Generator
runs-on: ubuntu-22.04
container:
image: crystallang/crystal
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Run generator tests
run: crystal spec test-generator/spec/*
test-generator-templates:
name: Check Generator Templates
runs-on: ubuntu-22.04
container:
image: crystallang/crystal
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Check generator templates tests
run: ./bin/test_specs
template:
name: Check file formatting
Expand All @@ -28,7 +37,7 @@ jobs:
- name: Run file formatting
run: crystal ./bin/check-format.cr
exercises:
name: Check exercises crystal ${{ matrix.crystal }}
name: Check exercises Crystal ${{ matrix.crystal }}
runs-on: ubuntu-22.04
strategy:
# Allows running the job multiple times with different configurations
Expand All @@ -42,3 +51,16 @@ jobs:
run: apt-get update && apt-get install -y jq
- name: Run tests
run: ./bin/test-exercises.sh
exercises-windows:
name: Check exercises Crystal on Windows
runs-on: windows-2022
steps:
- name: Install Crystal
uses: crystal-lang/install-crystal@v1
with:
crystal: "1.11.1"
- name: 'Setup jq'
run: choco install jq
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Run tests
run: ./bin/test-exercises.ps1
42 changes: 42 additions & 0 deletions bin/fetch-configlet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is a copy of the
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1 file.
# Please submit bugfixes/improvements to the above file to ensure that all tracks
# benefit from the changes.

$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

$requestOpts = @{
Headers = If ($env:GITHUB_TOKEN) { @{ Authorization = "Bearer ${env:GITHUB_TOKEN}" } } Else { @{ } }
MaximumRetryCount = 3
RetryIntervalSec = 1
}

Function Get-DownloadUrl {
$arch = If ([Environment]::Is64BitOperatingSystem) { "x86-64" } Else { "i386" }
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest"
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts `
| Select-Object -ExpandProperty assets `
| Where-Object { $_.name -match "^configlet_.+_windows_${arch}.zip$" } `
| Select-Object -ExpandProperty browser_download_url -First 1
}

$outputDirectory = "bin"
if (!(Test-Path -Path $outputDirectory)) {
Write-Output "Error: no ./bin directory found. This script should be ran from a repo root."
exit 1
}

Write-Output "Fetching configlet..."
$downloadUrl = Get-DownloadUrl
$outputFileName = "configlet.zip"
$outputPath = Join-Path -Path $outputDirectory -ChildPath $outputFileName
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath @requestOpts

$configletPath = Join-Path -Path $outputDirectory -ChildPath "configlet.exe"
if (Test-Path -Path $configletPath) { Remove-Item -Path $configletPath }
[System.IO.Compression.ZipFile]::ExtractToDirectory($outputPath, $outputDirectory)
Remove-Item -Path $outputPath

$configletVersion = (Select-String -Pattern "/releases/download/(.+?)/" -InputObject $downloadUrl -AllMatches).Matches.Groups[1].Value
Write-Output "Downloaded configlet ${configletVersion} to ${configletPath}"
19 changes: 19 additions & 0 deletions bin/generator.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if ($args.Length -eq 0) {
Write-Host "Usage: generator <exercise>"
exit 1
}

$exercise = $args[0]

if (!(Test-Path -Path "./bin/templates")) {
New-Item -Path "./bin" -Name "templates" -ItemType Directory
exit 1
}

Copy-Item -Path "./exercises/practice/$exercise/.meta/test_template.ecr" -Destination "./bin/templates/template.ecr"

if ($args.Length -eq 2) {
crystal ./bin/generator.cr $exercise $args[1] || exit 1
} else {
crystal ./bin/generator.cr $exercise || exit 1
}
4 changes: 2 additions & 2 deletions bin/generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi
cat "./exercises/practice/${slug}/.meta/test_template.ecr" > "./bin/templates/template.ecr"

if [ $# -eq 2 ] ; then
crystal ./bin/generator.cr "${slug}" "${2%/}" || exit 1
crystal ./test-generator/src/generator.cr "${slug}" "${2%/}" || exit 1
else
crystal ./bin/generator.cr "${slug}" || exit 1
crystal ./test-generator/src/generator.cr "${slug}" || exit 1
fi
14 changes: 0 additions & 14 deletions bin/spec/formatter_tests.cr

This file was deleted.

39 changes: 39 additions & 0 deletions bin/test-exercises.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$tempFolderPath = [System.IO.Path]::GetTempPath()

Write-Host $tempFolderPath


if (!(Test-Path -Path $tempFolderPath/"spec")) {
New-Item -Path $tempFolderPath -Name "spec" -ItemType Directory
}
if (!(Test-Path -Path $tempFolderPath/"src")) {
New-Item -Path $tempFolderPath -Name "src" -ItemType Directory
}
Write-Host crystal -v
Write-Host $PWD

Function Test-Run() {
Param(
[string]$Name,
[string]$Type
)
Write-Host "Testing $Name"
Copy-Item -Path "$Name/.meta/src/$Type.cr" -Destination "$tempFolderPath/src/$Type.cr"
$specFile = "$Name/$(jq -r '.files.test[0]' $Name/.meta/config.json)"
Copy-Item -Path $specFile -Destination "$tempFolderPath/spec/spec.cr"
(Get-Content -Path "$tempFolderPath/spec/spec.cr") -replace "pending", "it" | Set-Content -Path "$tempFolderPath/spec/spec.cr"
Set-Location -Path "$tempFolderPath"
crystal spec "./spec/spec.cr"
}

$currentLocation = Get-Location

foreach ($exercise in Get-ChildItem -Path ./exercises/practice/*) {
Test-Run $exercise "example"
}

Set-Location -Path $currentLocation

foreach ($exercise in Get-ChildItem -Path ./exercises/concept/*) {
Test-Run $exercise "exemplar"
}
34 changes: 0 additions & 34 deletions bin/test-templates/files-to-format/example.cr

This file was deleted.

41 changes: 0 additions & 41 deletions bin/test-templates/formatted-files/example.cr

This file was deleted.

1 change: 1 addition & 0 deletions bin/test_specs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_specs() {
for exercise in "${exercises[@]}"; do
# Find the existing spec and move it to a temp location
# so we can generate a new spec in the old location.
echo "Testing ${exercise}..."
specs=("./exercises/practice/${exercise}/spec/"*_spec.cr)
if (( ${#specs[@]} != 1 )); then
error "Expected one spec for ${exercise} but found ${#specs[@]}!"
Expand Down
5 changes: 5 additions & 0 deletions concepts/procs-blocks/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"blurb": "Blocks and Procs, are two core concepts of Crystal. They are used to pass around code as if it were data. They are used for callbacks, iterators and to build DSLs.",
"contributors": [],
"authors": ["meatball133"]
}
Loading
Loading