mirror of
https://github.com/dcarbone/install-jq-action.git
synced 2026-02-12 02:56:56 +08:00
291 lines
9.4 KiB
YAML
291 lines
9.4 KiB
YAML
name: 'Tests - Setup jq Action'
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'action.yaml'
|
|
- '.github/workflows/tests.yaml'
|
|
- 'scripts/unixish.sh'
|
|
- 'scripts/unixish-17.sh'
|
|
- 'scripts/windowsish.ps1'
|
|
- 'scripts/windowsish-17.ps1'
|
|
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
test-linux:
|
|
strategy:
|
|
matrix:
|
|
image:
|
|
- "ubuntu-latest"
|
|
- "ubuntu-20.04"
|
|
- "ubuntu-22.04"
|
|
- "ubuntu-24.04"
|
|
- "macos-latest"
|
|
- "macos-13"
|
|
- "macos-14"
|
|
- "macos-15"
|
|
- "windows-latest"
|
|
- "windows-2019"
|
|
- "windows-2022"
|
|
force:
|
|
- 'true'
|
|
- 'false'
|
|
version:
|
|
- '1.7'
|
|
include:
|
|
- image: "ubuntu-latest"
|
|
version: '1.6'
|
|
- image: "ubuntu-latest"
|
|
version: '1.5'
|
|
|
|
- image: "ubuntu-20.04"
|
|
version: '1.6'
|
|
- image: "ubuntu-20.04"
|
|
version: '1.5'
|
|
|
|
- image: "ubuntu-22.04"
|
|
version: '1.6'
|
|
- image: "ubuntu-22.04"
|
|
version: '1.5'
|
|
|
|
- image: "ubuntu-24.04"
|
|
version: '1.6'
|
|
- image: "ubuntu-24.04"
|
|
version: '1.5'
|
|
|
|
- image: "windows-latest"
|
|
version: '1.6'
|
|
- image: "windows-latest"
|
|
version: '1.5'
|
|
|
|
- image: "windows-2019"
|
|
version: '1.6'
|
|
- image: "windows-2019"
|
|
version: '1.5'
|
|
|
|
- image: "windows-2022"
|
|
version: '1.6'
|
|
- image: "windows-2022"
|
|
version: '1.5'
|
|
|
|
name: "Test Action - (img: ${{ matrix.image }}; version: ${{ matrix.version }}; force: ${{ matrix.force }})"
|
|
runs-on: ${{ matrix.image }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup jq
|
|
id: install-jq
|
|
uses: ./
|
|
with:
|
|
version: '${{ matrix.version }}'
|
|
force: '${{ matrix.force }}'
|
|
|
|
- name: Check jq - Unix-ish
|
|
if: (runner.os == 'Linux' || runner.os == 'macOS') && matrix.force == 'true'
|
|
# language=sh
|
|
run: |
|
|
_err=
|
|
_which="$(which jq)"
|
|
_vers="$(jq --version)"
|
|
if [[ "${_which}" != "$RUNNER_TOOL_CACHE/jq/jq" ]]; then
|
|
echo "jq found at unexpected path."
|
|
echo " Expected: \"$RUNNER_TOOL_CACHE/jq/jq\""
|
|
echo " Actual: \"${_which}\""
|
|
_err=1
|
|
fi
|
|
if [[ "${_vers}" != 'jq-${{ matrix.version }}' ]]; then
|
|
echo "jq --version returned unexpected value"
|
|
echo ' Expected: "jq-${{ matrix.version }}"'
|
|
echo " Actual: \"${_vers}\""
|
|
_err=1
|
|
fi
|
|
if [ -n "${_err}" ]; then exit 1; fi;
|
|
|
|
- name: Check Outputs - Unix-ish
|
|
if: runner.os == 'Linux' || runner.os == 'macOS'
|
|
# language=sh
|
|
run: |
|
|
_installed='${{ steps.install-jq.outputs.installed }}'
|
|
_err=
|
|
if [[ '${{ matrix.force }}' == 'true' ]]; then
|
|
# enabling "force" must result in an install
|
|
if [[ '${{ steps.install-jq.outputs.installed }}' != 'true' ]]; then
|
|
echo 'Unexpected value for "installed":'
|
|
echo 'Expected: "true"'
|
|
echo 'Actual: "${{ steps.install-jq.outputs.installed }}"'
|
|
_err=1
|
|
fi
|
|
else
|
|
if [[ '${{ steps.install-jq.outputs.found }}' == 'true' ]]; then
|
|
# if found, must not be installed without force
|
|
if [[ '${{ steps.install-jq.outputs.installed }}' != 'false' ]]; then
|
|
echo 'Unexpected value for "installed":'
|
|
echo 'Expected: "false"'
|
|
echo 'Actual: "${{ steps.install-jq.outputs.installed }}"'
|
|
_err=1
|
|
fi
|
|
else
|
|
# if not found, must be installed
|
|
if [[ '${{ steps.install-jq.outputs.installed }}' != 'true' ]]; then
|
|
echo 'Unexpected value for "installed":'
|
|
echo 'Expected: "true"'
|
|
echo 'Actual: "${{ steps.install-jq.outputs.installed }}"'
|
|
_err=1
|
|
fi
|
|
fi
|
|
fi
|
|
if [ -n "${_err}" ]; then exit 1; fi;
|
|
|
|
|
|
- name: Check jq - Windows-ish
|
|
if: runner.os == 'Windows' && matrix.force == 'true'
|
|
# language=powershell
|
|
run: |
|
|
Get-Command "jq.exe"
|
|
$_cmd={jq.exe --version }
|
|
$_vers=jq.exe --version 2>&1
|
|
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 }}"
|
|
Write-Host " Actual: ${_vers}"
|
|
exit 1
|
|
}
|
|
|
|
- name: Check Outputs - Windows-ish
|
|
if: runner.os == 'Windows'
|
|
shell: powershell
|
|
# language=powershell
|
|
run: |
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-StrictMode -Version Latest
|
|
$_installed='${{ steps.install-jq.outputs.installed }}'
|
|
$_err = 0
|
|
if ("${{ matrix.force }}" -eq "true")
|
|
{
|
|
# enabling "force" must result in an install
|
|
if ("${{ steps.install-jq.outputs.installed }}" -ne "true")
|
|
{
|
|
Write-Host "Unexpected value for installed"
|
|
Write-Host "Expected: true"
|
|
Write-Host "Actual: ${{ steps.install-jq.outputs.installed }}"
|
|
$_err=1
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ("${{ steps.install-jq.outputs.found }}" -eq "true")
|
|
{
|
|
# if found, must not be installed without force
|
|
if ("${{ steps.install-jq.outputs.installed }}" -ne "false")
|
|
{
|
|
Write-Host "Unexpected value for installed"
|
|
Write-Host "Expected: false"
|
|
Write-Host "Actual: ${{ steps.install-jq.outputs.installed }}"
|
|
$_err=1
|
|
}
|
|
}
|
|
else
|
|
{
|
|
# if not found, must be installed
|
|
if ("${{ steps.install-jq.outputs.installed }}" -ne "true") {
|
|
Write-Host "Unexpected value for installed"
|
|
Write-Host "Expected: true"
|
|
Write-Host "Actual: ${{ steps.install-jq.outputs.installed }}"
|
|
$_err=1
|
|
}
|
|
}
|
|
}
|
|
if ("${_err}" -ne 0)
|
|
{
|
|
exit 1
|
|
}
|
|
test-container:
|
|
strategy:
|
|
matrix:
|
|
image:
|
|
- "ubuntu-24.04"
|
|
- "ubuntu-22.04"
|
|
- "ubuntu-20.04"
|
|
force:
|
|
- 'true'
|
|
- 'false'
|
|
version:
|
|
- '1.5'
|
|
- '1.6'
|
|
- '1.7'
|
|
name: "Test Action (Container) - (img: ${{ matrix.image }}; version: ${{ matrix.version }}; force: ${{ matrix.force }})"
|
|
runs-on: ${{ matrix.image }}
|
|
container:
|
|
image: node:20
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup jq
|
|
id: install-jq
|
|
uses: ./
|
|
with:
|
|
version: '${{ matrix.version }}'
|
|
force: '${{ matrix.force }}'
|
|
|
|
- name: Check jq
|
|
# language=sh
|
|
run: |
|
|
_err=
|
|
_which="$(which jq)"
|
|
_vers="$(jq --version)"
|
|
if [[ "${_which}" != "$RUNNER_TOOL_CACHE/jq/jq" ]]; then
|
|
echo "jq found at unexpected path."
|
|
echo " Expected: \"$RUNNER_TOOL_CACHE/jq/jq\""
|
|
echo " Actual: \"${_which}\""
|
|
_err=1
|
|
fi
|
|
if [[ "${_vers}" != 'jq-${{ matrix.version }}' ]]; then
|
|
echo "jq --version returned unexpected value"
|
|
echo ' Expected: "jq-${{ matrix.version }}"'
|
|
echo " Actual: \"${_vers}\""
|
|
_err=1
|
|
fi
|
|
if [ -n "${_err}" ]; then exit 1; fi;
|
|
|
|
- name: Check Outputs
|
|
# language=sh
|
|
run: |
|
|
_installed='${{ steps.install-jq.outputs.installed }}'
|
|
_err=
|
|
if [[ '${{ matrix.force }}' == 'true' ]]; then
|
|
# enabling "force" must result in an install
|
|
if [[ '${{ steps.install-jq.outputs.installed }}' != 'true' ]]; then
|
|
echo 'Unexpected value for "installed":'
|
|
echo 'Expected: "true"'
|
|
echo 'Actual: "${{ steps.install-jq.outputs.installed }}"'
|
|
_err=1
|
|
fi
|
|
else
|
|
if [[ '${{ steps.install-jq.outputs.found }}' == 'true' ]]; then
|
|
# if found, must not be installed without force
|
|
if [[ '${{ steps.install-jq.outputs.installed }}' != 'false' ]]; then
|
|
echo 'Unexpected value for "installed":'
|
|
echo 'Expected: "false"'
|
|
echo 'Actual: "${{ steps.install-jq.outputs.installed }}"'
|
|
_err=1
|
|
fi
|
|
else
|
|
# if not found, must be installed
|
|
if [[ '${{ steps.install-jq.outputs.installed }}' != 'true' ]]; then
|
|
echo 'Unexpected value for "installed":'
|
|
echo 'Expected: "true"'
|
|
echo 'Actual: "${{ steps.install-jq.outputs.installed }}"'
|
|
_err=1
|
|
fi
|
|
fi
|
|
fi
|
|
if [ -n "${_err}" ]; then exit 1; fi;
|