From 11580c595b9a6ad2c08ea9539276dd0460ced7e1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 14 Sep 2023 15:15:25 -0500 Subject: [PATCH 1/4] quick & dirty 1.7 support --- .github/workflows/tests.yaml | 7 ++- action.yaml | 19 ++++++-- scripts/unixish-17.sh | 95 ++++++++++++++++++++++++++++++++++++ scripts/windowsish-17.ps1 | 74 ++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 scripts/unixish-17.sh create mode 100644 scripts/windowsish-17.ps1 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 60b6d8a..0f83d15 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -36,6 +36,7 @@ jobs: version: - '1.5' - '1.6' + - '1.7' name: "Test Action - (img: ${{ matrix.image }}; version: ${{ matrix.version }}; force: ${{ matrix.force }})" runs-on: ${{ matrix.image }} steps: @@ -50,7 +51,7 @@ jobs: - name: Check jq - Unix-ish if: (runner.os == 'Linux' || runner.os == 'macOS') && matrix.force == 'true' - shell: bash +e {0} + # language=sh run: | _err= _which="$(which jq)" @@ -71,7 +72,7 @@ jobs: - name: Check Outputs - Unix-ish if: runner.os == 'Linux' || runner.os == 'macOS' - shell: bash -e {0} + # language=sh run: | _installed='${{ steps.install-jq.outputs.installed }}' _err= @@ -107,6 +108,7 @@ jobs: - name: Check jq - Windows-ish if: runner.os == 'Windows' && matrix.force == 'true' + # language=sh run: | Get-Command "jq.exe" $_cmd={jq.exe --version } @@ -122,6 +124,7 @@ jobs: - name: Check Outputs - Windows-ish if: runner.os == 'Windows' shell: powershell + # language=pwsh run: | $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest diff --git a/action.yaml b/action.yaml index c310a22..a40d1e9 100644 --- a/action.yaml +++ b/action.yaml @@ -10,7 +10,7 @@ inputs: version: required: false description: "Version of jq to install" - default: "1.6" + default: "1.7" force: required: false description: "If 'true', does not check for existing jq installation before continuing." @@ -44,7 +44,12 @@ runs: shell: bash env: JQ_VERSION: '${{ inputs.version }}' - run: $GITHUB_ACTION_PATH/scripts/unixish.sh + run: | + if [[ '${{ inputs.version }}' == '1.5' ]] || [[ '${{ inputs.version }}' == '1.6' ]]; then + $GITHUB_ACTION_PATH/scripts/unixish.sh + else + $GITHUB_ACTION_PATH/scripts/unixish-17.sh + fi - name: 'Check for jq - Windows-ish' id: jq-check-windows @@ -65,4 +70,12 @@ runs: shell: powershell env: JQ_VERSION: '${{ inputs.version }}' - run: '& $Env:GITHUB_ACTION_PATH\scripts\windowsish.ps1' + run: | + if ( "${{ inputs.version }}" -eq "1.5" -or "${{ inputs.version }}" -eq "1.6") + { + '& $Env:GITHUB_ACTION_PATH\scripts\windowsish.ps1' + } + else + { + '& $Env:GITHUB_ACTION_PATH\scripts\windowsish-17.ps1' + } diff --git a/scripts/unixish-17.sh b/scripts/unixish-17.sh new file mode 100644 index 0000000..77e5934 --- /dev/null +++ b/scripts/unixish-17.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +set -e + +echo '::group::Prep' + +# validate input and prepare some vars + +_base_url='https://github.com/jqlang/jq/releases/download' + +_arch_env="$(echo "$RUNNER_ARCH" | tr '[:upper:]' '[:lower:]')" + +_os= +_arch= + +_bin_name= +_dl_name= +_dl_path= +_dl_url= + +case $RUNNER_OS in + Linux) + _os='linux' + ;; + macOS) + _os='osx' + ;; + + *) + echo "Cannot handle OS of type $RUNNER_OS" + echo "Expected one of: [ Linux macOS ]" + exit 1 + ;; +esac + +case "${_arch_env}" in + 'x86'|'386') + _arch='i386' + ;; + 'x64'|'amd64'|'x86_64') + _arch='amd64' + ;; + 'arm'|'armhf') + _arch='armhf' + ;; + 'armel') + _arch='armel' + ;; + 'arm64'|'aarch64') + _arch='arm64' + ;; + + *) + echo "Cannot handle arch of type $RUNNER_ARCH" + echo "Expected one of: [ x86 386 x64 amd64 x86_64 arm armhf armel arm64 aarch64 ]" + exit 1 + ;; +esac + +# build bin name +_bin_name="jq-${_os}-${_arch}" + +# build download vars +_dl_name="${_bin_name}" +_dl_path="$RUNNER_TEMP/${_dl_name}" + +_dl_url="${_base_url}/jq-$JQ_VERSION/${_dl_name}" + +echo '::endgroup::' + +echo '::group::Downloading jq' + +echo "Src: ${_dl_url}" +echo "Dst: ${_dl_path}" + +wget -O- "${_dl_url}" > "${_dl_path}" + +echo '::endgroup::' + +echo '::group::Copying to tool cache' + +echo "Creating tool cache directory $RUNNER_TOOL_CACHE/jq" +mkdir -p "$RUNNER_TOOL_CACHE/jq" + +echo "Installing into tool cache:" +echo "Src: $RUNNER_TEMP/${_bin_name}" +echo "Dst: $RUNNER_TOOL_CACHE/jq/jq" +mv "$RUNNER_TEMP/${_bin_name}" "$RUNNER_TOOL_CACHE/jq/jq" + +chmod +x "$RUNNER_TOOL_CACHE/jq/jq" + +echo "Adding $RUNNER_TOOL_CACHE/jq to path..." +echo "$RUNNER_TOOL_CACHE/jq" >> $GITHUB_PATH + +echo '::endgroup::' diff --git a/scripts/windowsish-17.ps1 b/scripts/windowsish-17.ps1 new file mode 100644 index 0000000..531df9f --- /dev/null +++ b/scripts/windowsish-17.ps1 @@ -0,0 +1,74 @@ +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest + +Write-Host "::group::Prep" + +$_base_url = "https://github.com/jqlang/jq/releases/download" + +$_arch_env = ($Env::RUNNER_ARCH).ToLower() + +# validate input and prepare some vars + +switch ($_arch_env) +{ + "x86" { + $_arch = "i386" + } + "386" { + $_arch = "i386" + } + "x64" { + $_arch = "amd64" + } + "x86_64" { + $_arch = "amd64" + } + "amd64" { + $_arch = "amd64" + } + default { + Write-Host "Cannot handle arch of type $Env:RUNNER_ARCH" + Write-Host "Expected one of: [ x86 386 x64 x86_64 amd64 ]" + exit 1 + } +} + +# build bin name +$_bin_name = "jq-windows-${_arch}" + +# build download vars + +$_dl_name = "${_bin_name}" +$_dl_path = "$Env:RUNNER_TEMP\${_dl_name}" + +$_dl_url = "${_base_url}/jq-$Env:JQ_VERSION/${_dl_name}" + +Write-Host "::endgroup::" + +# download artifact + +Write-Host "::group::Downloading jq" + +Write-Host "Src: ${_dl_url}" +Write-Host "Dst: ${_dl_path}" + +Invoke-WebRequest -Uri "${_dl_url}" -OutFile "${_dl_path}" + +Write-Host "::endgroup::" + +# install into tool cache + +Write-Host "::group::Copying to tool cache" + +Write-Host "Creating tool cache directory $Env:RUNNER_TOOL_CACHE\jq\" +New-Item "$Env:RUNNER_TOOL_CACHE\jq\" -ItemType Directory -Force + +Write-Host "Installing into tool cache:" +Write-Host "Src: $Env:RUNNER_TEMP\${_bin_name}" +Write-Host "Dst: $Env:RUNNER_TOOL_CACHE\jq\jq.exe" +Move-Item -Force -LiteralPath "$Env:RUNNER_TEMP\${_bin_name}" -Destination "$Env:RUNNER_TOOL_CACHE\jq\jq.exe" + +Write-Host "Adding $Env:RUNNER_TOOL_CACHE\jq\ to path..." +Add-Content "$Env:GITHUB_PATH" "$Env:RUNNER_TOOL_CACHE\jq\" + +Write-Host "::endgroup::" From 6563c792d682c2601006aa757093876c108112c1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 14 Sep 2023 15:23:59 -0500 Subject: [PATCH 2/4] cleanup --- .github/workflows/tests.yaml | 10 ++++------ action.yaml | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0f83d15..4dcc31b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -21,13 +21,11 @@ jobs: strategy: matrix: image: - - "ubuntu-latest" - - "ubuntu-20.04" - "ubuntu-22.04" - - "macos-latest" + - "ubuntu-20.04" + - "macos-13" - "macos-11" - "macos-12" - - "windows-latest" - "windows-2022" - "windows-2019" force: @@ -108,7 +106,7 @@ jobs: - name: Check jq - Windows-ish if: runner.os == 'Windows' && matrix.force == 'true' - # language=sh + # language=powershell run: | Get-Command "jq.exe" $_cmd={jq.exe --version } @@ -124,7 +122,7 @@ jobs: - name: Check Outputs - Windows-ish if: runner.os == 'Windows' shell: powershell - # language=pwsh + # language=powershell run: | $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest diff --git a/action.yaml b/action.yaml index a40d1e9..158f0ca 100644 --- a/action.yaml +++ b/action.yaml @@ -31,6 +31,7 @@ runs: id: jq-check-unix if: (runner.os == 'Linux' || runner.os == 'macOS') shell: bash +e {0} + # language=sh run: | _jq_bin="$(which jq)" if [ -f "${_jq_bin}" ]; then @@ -44,6 +45,7 @@ runs: shell: bash env: JQ_VERSION: '${{ inputs.version }}' + # language=sh run: | if [[ '${{ inputs.version }}' == '1.5' ]] || [[ '${{ inputs.version }}' == '1.6' ]]; then $GITHUB_ACTION_PATH/scripts/unixish.sh @@ -55,6 +57,7 @@ runs: id: jq-check-windows if: runner.os == 'Windows' shell: powershell + # language=powershell run: | if (Get-Command "jq.exe" -ErrorAction SilentlyContinue) { @@ -70,6 +73,7 @@ runs: shell: powershell env: JQ_VERSION: '${{ inputs.version }}' + # language=powershell run: | if ( "${{ inputs.version }}" -eq "1.5" -or "${{ inputs.version }}" -eq "1.6") { From 123947248b5bb452ae7a767d04945e831133502b Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 14 Sep 2023 15:27:19 -0500 Subject: [PATCH 3/4] very weird... --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4dcc31b..56e4496 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -111,7 +111,7 @@ jobs: Get-Command "jq.exe" $_cmd={jq.exe --version } $_vers=jq.exe --version 2>&1 - if ( "${_vers}" -ne "jq-${{ matrix.version }}" ) + if ( "${_vers}" -ne "jq-${{ matrix.version }}" -and "${_vers}" -ne "jq-${{ matrix.version }}-dirty" ) { Write-Host "jq.exe --version returned unexpected value" Write-Host " Expected: jq-${{ matrix.version }}" From 2cbae9632e6a63ab3a6df48ccd60b2a814d9c504 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 14 Sep 2023 15:32:15 -0500 Subject: [PATCH 4/4] readme and examples updates --- .github/workflows/example-linux.yaml | 9 +++++---- .github/workflows/example-macos.yaml | 9 +++++---- .github/workflows/example-windows.yaml | 9 +++++---- README.md | 9 +++++++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/example-linux.yaml b/.github/workflows/example-linux.yaml index 8755950..6ee4744 100644 --- a/.github/workflows/example-linux.yaml +++ b/.github/workflows/example-linux.yaml @@ -6,12 +6,12 @@ on: version: type: string required: false - description: "Version of jq to install" - default: "1.6" + description: 'Version of jq to install' + default: '1.7' force: type: boolean required: false - description: "Do not check for existing jq installation before continuing." + description: 'Do not check for existing jq installation before continuing.' default: false jobs: @@ -19,12 +19,13 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Setup jq' - uses: dcarbone/install-jq-action@v1.0.1 + uses: dcarbone/install-jq-action@v2.0.0 with: version: '${{ inputs.version }}' force: '${{ inputs.force }}' - name: 'Check jq' + # language=sh run: | which jq jq --version diff --git a/.github/workflows/example-macos.yaml b/.github/workflows/example-macos.yaml index bc9fc24..00ff1e3 100644 --- a/.github/workflows/example-macos.yaml +++ b/.github/workflows/example-macos.yaml @@ -6,12 +6,12 @@ on: version: type: string required: false - description: "Version of jq to install" - default: "1.6" + description: 'Version of jq to install' + default: '1.7' force: type: boolean required: false - description: "Do not check for existing jq installation before continuing." + description: 'Do not check for existing jq installation before continuing.' default: false jobs: @@ -19,12 +19,13 @@ jobs: runs-on: macos-latest steps: - name: 'Setup jq' - uses: dcarbone/install-jq-action@v1.0.1 + uses: dcarbone/install-jq-action@v2.0.0 with: version: '${{ inputs.version }}' force: '${{ inputs.force }}' - name: 'Check jq' + # language=sh run: | which jq jq --version diff --git a/.github/workflows/example-windows.yaml b/.github/workflows/example-windows.yaml index a9107cd..eb75de5 100644 --- a/.github/workflows/example-windows.yaml +++ b/.github/workflows/example-windows.yaml @@ -6,12 +6,12 @@ on: version: type: string required: false - description: "Version of jq to install" - default: "1.6" + description: 'Version of jq to install' + default: '1.7' force: type: boolean required: false - description: "Do not check for existing jq installation before continuing." + description: 'Do not check for existing jq installation before continuing.' default: false jobs: @@ -19,12 +19,13 @@ jobs: runs-on: windows-latest steps: - name: 'Setup jq' - uses: dcarbone/install-jq-action@v1.0.1 + uses: dcarbone/install-jq-action@v2.0.0 with: version: '${{ inputs.version }}' force: '${{ inputs.force }}' - name: 'Check jq' + # language=powershell run: | Get-Command "jq.exe" jq.exe --version diff --git a/README.md b/README.md index 39853c0..893440d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,11 @@ Multiplatform [jq](https://github.com/stedolan/jq) installer action [![Tests - Setup jq Action](https://github.com/dcarbone/install-jq-action/actions/workflows/tests.yaml/badge.svg)](https://github.com/dcarbone/install-jq-action/actions/workflows/tests.yaml) -This action cannot currently handle MacOS arm64 runners. +This action is tested against the following versions of JQ: + +- [1.7](https://github.com/jqlang/jq/releases/tag/jq-1.7) +- [1.6](https://github.com/jqlang/jq/releases/tag/jq-1.6) +- [1.5](https://github.com/jqlang/jq/releases/tag/jq-1.5) # Index @@ -16,6 +20,7 @@ This action cannot currently handle MacOS arm64 runners. * [linux](./.github/workflows/example-linux.yaml) * [macos](./.github/workflows/example-macos.yaml) +* [windows](./.github/workflows/example-windows.yaml) ## Action Inputs @@ -24,7 +29,7 @@ This action cannot currently handle MacOS arm64 runners. version: required: false description: "Version of jq to install" - default: "1.6" + default: "1.7" ``` This must be a version with a [corresponding release](https://github.com/stedolan/jq/releases).