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

quick & dirty 1.7 support #4

Merged
merged 4 commits into from
Sep 14, 2023
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
9 changes: 5 additions & 4 deletions .github/workflows/example-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ 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:
example:
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
9 changes: 5 additions & 4 deletions .github/workflows/example-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ 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:
example:
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
9 changes: 5 additions & 4 deletions .github/workflows/example-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ 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:
example:
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
15 changes: 8 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,6 +34,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:
Expand All @@ -50,7 +49,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)"
Expand All @@ -71,7 +70,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=
Expand Down Expand Up @@ -107,11 +106,12 @@ jobs:

- 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 }}" )
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 }}"
Expand All @@ -122,6 +122,7 @@ jobs:
- name: Check Outputs - Windows-ish
if: runner.os == 'Windows'
shell: powershell
# language=powershell
run: |
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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).
Expand Down
23 changes: 20 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -44,12 +45,19 @@ runs:
shell: bash
env:
JQ_VERSION: '${{ inputs.version }}'
run: $GITHUB_ACTION_PATH/scripts/unixish.sh
# language=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
if: runner.os == 'Windows'
shell: powershell
# language=powershell
run: |
if (Get-Command "jq.exe" -ErrorAction SilentlyContinue)
{
Expand All @@ -65,4 +73,13 @@ runs:
shell: powershell
env:
JQ_VERSION: '${{ inputs.version }}'
run: '& $Env:GITHUB_ACTION_PATH\scripts\windowsish.ps1'
# language=powershell
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'
}
95 changes: 95 additions & 0 deletions scripts/unixish-17.sh
Original file line number Diff line number Diff line change
@@ -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::'
Loading