diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 8e4a74db..f3a50d6a 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -29,7 +29,6 @@ jobs: - name: Checkout repository uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 - - name: Cache GnuCOBOL id: cache-gnu-cobol uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 @@ -52,6 +51,10 @@ jobs: shell: pwsh run: Expand-Archive ~\gnucobol-3.2-dev.zip -DestinationPath gnucobol -Force + - name: Fetch CobolCheck + shell: pwsh + run: bin/fetch-cobolcheck.ps1 + - name: Run tests for all exercises shell: pwsh run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 18fdaeda..e333e837 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/bin/fetch-cobolcheck b/bin/fetch-cobolcheck new file mode 100755 index 00000000..16c73077 --- /dev/null +++ b/bin/fetch-cobolcheck @@ -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 diff --git a/bin/fetch-cobolcheck.ps1 b/bin/fetch-cobolcheck.ps1 new file mode 100644 index 00000000..e762e1c5 --- /dev/null +++ b/bin/fetch-cobolcheck.ps1 @@ -0,0 +1,28 @@ +# 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 +$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe" +Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";" + $PSScriptRoot, "Machine")