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

Pre-fetch cobolcheck #130

Merged
merged 4 commits into from
Apr 19, 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
14 changes: 10 additions & 4 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5


- name: Cache GnuCOBOL
id: cache-gnu-cobol
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
Expand All @@ -52,14 +51,21 @@ jobs:
shell: pwsh
run: Expand-Archive ~\gnucobol-3.2-dev.zip -DestinationPath gnucobol -Force

- name: Run tests for all exercises
- name: Fetch CobolCheck
shell: pwsh
run: bin/fetch-cobolcheck.ps1

- name: Setup environment
shell: pwsh
run: |
$env:Path = "D:\a\cobol\cobol\gnucobol\bin;" + $env:Path
$env:Path = "D:\a\cobol\cobol\gnucobol\bin;$HOME\bin;" + $env:Path
[System.Environment]::SetEnvironmentVariable('COB_CONFIG_DIR', 'D:\a\cobol\cobol\gnucobol\config')
[System.Environment]::SetEnvironmentVariable('COB_COPY_DIR', 'D:\a\cobol\cobol\gnucobol\copy')
[System.Environment]::SetEnvironmentVariable('COB_CFLAGS', '-I D:\a\cobol\cobol\gnucobol\include')
[System.Environment]::SetEnvironmentVariable('COB_LDFLAGS', '-L D:\a\cobol\cobol\gnucobol\lib')
[System.Environment]::SetEnvironmentVariable('COB_LIBRARY_PATH', 'D:\a\cobol\cobol\gnucobol\lib')
[System.Environment]::SetEnvironmentVariable('COB_LIBS', 'D:\a\cobol\cobol\gnucobol\bin\libcob-4.dll')
bin/test.ps1

- name: Run tests for all exercises
shell: pwsh
run: bin/test.ps1
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ jobs:
curl -sLk https://sourceforge.net/projects/open-cobol/files/gnu-cobol/3.1/gnucobol-3.1.2.tar.gz | tar xz
cd gnucobol-3.1.2 && ./configure --prefix=/usr && sudo make && sudo make install && sudo ldconfig

- name: Fetch CobolCheck
run: bin/fetch-cobolcheck

- name: Run tests for all exercises
run: bin/test
54 changes: 54 additions & 0 deletions bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# This file is inspired by https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

case "$(uname)" in
Darwin*) os='mac' ;;
Linux*) os='linux' ;;
Windows*) os='windows' ;;
MINGW*) os='windows' ;;
MSYS_NT-*) os='windows' ;;
*) os='linux' ;;
esac

case "${os}" in
windows*) ext='.exe' ;;
*) ext='' ;;
esac

arch="$(uname -m)"

curlopts=(
--silent
--show-error
--fail
--location
--retry 3
)

if [[ -n "${GITHUB_TOKEN}" ]]; then
curlopts+=(--header "authorization: Bearer ${GITHUB_TOKEN}")
fi

suffix="${os}-${arch}${ext}"

get_download_url() {
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${LATEST}" |
grep "\"browser_download_url\": \".*/download/.*/cobol-check.*${suffix}\"$" |
cut -d'"' -f4
}

main() {
output_path="/usr/local/bin/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
}

main
29 changes: 29 additions & 0 deletions bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is inspired by https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1.
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

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

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

$arch = If ([Environment]::Is64BitOperatingSystem) { "amd64" } Else { "x86" }
$fileName = "cobol-check-windows-$arch.exe"

Function Get-DownloadUrl {
$latestUrl = "https://api.github.com/repos/0xE282B0/cobol-check/releases/latest"
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts
| Select-Object -ExpandProperty assets
| Where-Object { $_.browser_download_url -match $FileName }
| Select-Object -ExpandProperty browser_download_url
}

$downloadUrl = Get-DownloadUrl
$outputDir = Join-Path -Path $HOME -ChildPath "bin"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
9 changes: 7 additions & 2 deletions exercises/practice/acronym/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/all-your-base/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/allergies/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/armstrong-numbers/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/atbash-cipher/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/binary/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/bob/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/circular-buffer/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/collatz-conjecture/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/complex-numbers/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/darts/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
9 changes: 7 additions & 2 deletions exercises/practice/difference-of-squares/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
if ($cobolcheckCmd) {
$cobolcheck = $cobolcheckCmd.Path
Write-Output "Found cobolcheck, using $cobolcheck"
} elseif (![System.IO.File]::Exists("$cobolcheck")){
Write-Output "Cobolcheck not found. Trying to fetch it."
& "$PSScriptRoot\bin\fetch-cobolcheck.ps1"
}

Write-Output "Run cobolcheck."
Set-Location $PSScriptRoot

Invoke-Expression "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down
Loading
Loading