Skip to content
Draft
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
79 changes: 79 additions & 0 deletions action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash

set -euo pipefail

windows_version="${windows_version:-}"
macos_version="${macos_version:-}"
ubuntu_version="${ubuntu_version:-}"
newest="${newest:-}"
oldest="${newest:-}"

requested_version="${requested_version:-}"
cabal_file="${cabal_file?cabal_file not set}"

source ./common.sh

echo "::debug::windows: ${windows_version}"
if [[ "${windows_version}" != "" ]]; then
echo "::debug::Windows explicit enabled: $${windows_version}"
"windows=--windows-version=${windows_version}"
elif [[ "${windows_version}" == "true" ]]; then
printf "::warning title=Legacy option \`windows\`:: Windows fallback enabled: %s" "$windows_version"
windows="--windows"
else
windows=""
fi

echo "::debug::macOS: ${macos_version}"
if [[ "${macos_version}" != "" ]]; then
echo "::debug::macOS explicit version enabled: ${macos_version}"
macos="--macos-version=${macos_version}"
elif [[ "${macos_version}" == "true" ]]; then
printf "::warning title=Legacy option \`macos\`: :macOS fallback enabled: %s" "$macos_version"
macos="--macos"
else
macos=""
fi

echo "::debug::ubuntu: ${ubuntu_version}"
if [[ "${ubuntu_version}" != "" ]]; then
echo "::debug::Ubuntu explicit version enabled: ${ubuntu_version}"
ubuntu="--ubuntu-version=${ubuntu_version}"
elif [[ "${ubuntu_version}" == "true" ]]; then
printf "::warning title=Legacy option \`ubuntu\`::Ubuntu fallback enabled: %s" "${ubuntu_version}"
ubuntu="--ubuntu"
else
ubuntu=""
fi

echo "::debug::Is --newest enabled: ${newest}"
echo "::debug::Is --oldest enabled: ${oldest}"

if [[ "${oldest}" == "true" && "${newest}" == "true" ]]; then
echo "::error title=Incompatible options::You cannot use the 'oldest' and 'newest' options together!"
exit 1
fi

if [[ "${oldest}" == "true" ]]; then
echo "::debug::oldest version enabled"
relative_version="--oldest"
elif [[ "${newest}" == "true" ]]; then
echo "::debug::newest version enabled"
relative_version="--newest"
else
relative_version=""
echo "::debug::No relative version selected"
fi

minium_modern_version="0.1.9.0"
if [[ "$windows" == "" ]] && [[ "$macos" == "" ]] && [[ "$ubuntu" == "" ]]; then
echo "At least one runner needed, please check the README.md in the get-tested repo"
exit 1
fi

# shellcheck disable=SC2086
if is_tag_newer "$requested_version" "$minium_modern_version"; then
./get-tested "$cabal_file" $windows $macos $ubuntu $relative_version
else
./get-tested "$cabal_file" $windows $macos $ubuntu $relative_version >>"$GITHUB_OUTPUT"
fi
95 changes: 11 additions & 84 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,95 +62,22 @@ runs:
#
# See: https://github.com/actions/runner/issues/895
- name: Set up get-tested
uses: Kleidukos/get-tested/setup-get-tested@d8562f44cf524ed3f4d17011321e978d0f89d4a3
uses: Kleidukos/get-tested/setup-get-tested@731dd342038b2371fe12eccb5a934f51910fef14
with:
version: ${{ inputs.version }}

- name: Set up Windows options
- name: Parse the options and run the get-tested binary
shell: bash
run: |
echo "::debug::windows: ${{ inputs.windows-version }}"
if [[ "${{ inputs.windows-version }}" != "" ]]
then
echo "::debug::Windows explicit enabled: ${{ inputs.windows-version }}"
echo "WINDOWS=--windows-version=${{ inputs.windows-version }}" >> $GITHUB_ENV
elif [[ "${{ inputs.windows }}" == "true" ]]
then
echo "::warning title=Legacy option `windows`::Windows fallback enabled: ${{ inputs.windows }}"
echo "WINDOWS=--windows" >> $GITHUB_ENV
else echo "WINDOWS=" >> $GITHUB_ENV
fi


- name: Set up macOS options
shell: bash
run: |
echo "::debug::macOS: ${{ inputs.macos-version }}"
if [[ "${{ inputs.macos-version }}" != "" ]]
then
echo "::debug::macOS explicit version enabled: ${{ inputs.macos-version }}"
echo "MACOS=--macos-version=${{ inputs.macos-version }}" >> $GITHUB_ENV
elif [[ "${{ inputs.macos }}" == "true" ]]
then
echo "::warning title=Legacy option `macos`::macOS fallback enabled: ${{ inputs.macos }}"
echo "MACOS=--macos" >> $GITHUB_ENV
else echo "MACOS=" >> $GITHUB_ENV
fi

- name: Set up Ubuntu options
shell: bash
run: |
echo "::debug::ubuntu: ${{ inputs.ubuntu-version }}"
if [[ "${{ inputs.ubuntu-version }}" != "" ]]
then
echo "::debug::Ubuntu explicit version enabled: ${{ inputs.ubuntu-version }}"
echo "UBUNTU=--ubuntu-version=${{ inputs.ubuntu-version }}" >> "$GITHUB_ENV"
elif [[ "${{ inputs.ubuntu }}" == "true" ]]
then
echo "::warning title=Legacy option `ubuntu`::Ubuntu fallback enabled: ${{ inputs.ubuntu }}"
echo "UBUNTU=--ubuntu" >> $GITHUB_ENV
else echo "UBUNTU=" >> $GITHUB_ENV
fi

- name: Set up `oldest` and `newest` options
shell: bash
run: |
echo "::debug::Is --newest enabled: ${{ inputs.newest }}"
echo "::debug::Is --oldest enabled: ${{ inputs.oldest }}"

if [[ "${{ inputs.oldest }}" == "true" && "${{ inputs.newest }}" == "true" ]]; then
echo "::error title=Incompatible options::You cannot use the 'oldest' and 'newest' options together!"
exit 1
fi

if [[ "${{ inputs.oldest }}" == "true" ]]
then
echo "::debug::oldest version enabled"
echo "RELATIVE_VERSION=--oldest" >> "$GITHUB_ENV"
elif [[ "${{ inputs.newest }}" == "true" ]]
then
echo "::debug::newest version enabled"
echo "RELATIVE_VERSION=--newest" >> "$GITHUB_ENV"
else
echo "::debug::No relative version selected"
fi


- name: Extract the tested GHC versions
id: set-matrix
shell: bash
run: |
requested_version="${{ inputs.version }}"
minium_modern_version="0.1.9.0"
if [[ "$WINDOWS" == "" ]] && [[ "$MACOS" == "" ]] && [[ "$UBUNTU" == "" ]]; then
echo "At least one runner needed, please check the README.md in the get-tested repo"
exit 1
fi
if [[ "$requested_version" == "" ]] || [[ "$requested_version" == "get-tested-head" ]] || dpkg --compare-versions "$requested_version" ge "$minium_modern_version"; then
./get-tested $WINDOWS $MACOS $UBUNTU $RELATIVE_VERSION "${{ inputs.cabal-file }}"
else
./get-tested $WINDOWS $MACOS $UBUNTU $RELATIVE_VERSION "${{ inputs.cabal-file }}" >> "$GITHUB_OUTPUT"
fi
run: bash ./action.sh
env:
cabal_file: ${{ inputs.cabal-file }}
windows_version: ${{ inputs.windows-version }}
macos_version: ${{ inputs.macos-version }}
ubuntu_version: ${{ inputs.ubuntu-version }}
newest: ${{ inputs.newest }}
oldest: ${{ inputs.oldest }}
requested_version: ${{ inputs.version }}


branding:
Expand Down
11 changes: 11 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

is_tag_newer () {
requested_version="$1"
minimum_modern_version="$2"
if [[ "$requested_version" == "" ]] || [[ "$requested_version" == "get-tested-head" ]] || [[ "$requested_version" == "latest" ]] || dpkg --compare-versions "$requested_version" ge "$minimum_modern_version"; then
return 0
else
return 1
fi
}
67 changes: 3 additions & 64 deletions setup-get-tested/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,9 @@ runs:
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
tmpdir="$(mktemp -d "${RUNNER_TEMP}/setup-get-tested.XXXXXX")"

os="$(uname | tr '[:upper:]' '[:lower:]')"
case "$os" in
msys*|mingw*|cygwin*)
os="windows"
# On Windows runners, convert D:\... to /d/...
tmpdir="$(cygpath -u "$tmpdir")"
directory_posix="$(cygpath -u "${{ inputs.directory }}")"
outfile="get-tested.zip"
;;
*)
directory_posix="${{ inputs.directory }}"
outfile="get-tested.tar.gz"
;;
esac

requested_version="${{ inputs.version }}"
minium_modern_version="0.1.7.1"
if [[ "$requested_version" == "" ]] || [[ "$requested_version" == "get-tested-head" ]] || dpkg --compare-versions "$requested_version" ge "$minium_modern_version"; then
requested_old_version=false
else
requested_old_version=true
fi
trap "rm -rf ${tmpdir}" EXIT
if [[ "$os" == "darwin" ]]; then
pattern='get-tested-*-macOS-arm64.tar.gz'
elif [[ "$os" == "linux" ]] && [[ "$requested_old_version" == true ]]; then
pattern='get-tested-*-linux-amd64'
elif [[ "$os" == "linux" ]]; then
pattern='get-tested-*-Linux-static-x86_64.tar.gz'
else
pattern='get-tested-*-Windows-x86_64.zip'
fi
echo '::debug::chose '$pattern' for ::'$os'::'

trap "rm -rf ${tmpdir}" EXIT

gh_release_flags=(
--repo Kleidukos/get-tested
--pattern "$pattern"
--output "${tmpdir}/${outfile}"
)
if [[ "$requested_version" == "get-tested-head" ]]; then
gh release download "get-tested-head" "${gh_release_flags[@]}"
elif [[ "$requested_version" != "" ]]; then
gh release download "v${requested_version}" "${gh_release_flags[@]}"
else
gh release download "${gh_release_flags[@]}"
fi

mkdir -p "$directory_posix"
if [[ "$os" == "windows" ]]; then
unzip -q -o "${tmpdir}/${outfile}" -d "$directory_posix"
elif [[ "$os" == "linux" ]] && [[ $requested_old_version == true ]]; then
cp "${tmpdir}/${outfile}" "$directory_posix/get-tested"
else
tar -xzf "${tmpdir}/${outfile}" -C "$directory_posix"
fi

path="${directory_posix}/get-tested"
chmod a+x "$path"
echo "path=${path}" >> "${GITHUB_OUTPUT}"
inputs_directory: ${{ inputs.directory }}
requested_version: ${{ inputs.version }}
run: bash ./setup-get-tested/setup-get-tested.sh

branding:
icon: 'list'
Expand Down
68 changes: 68 additions & 0 deletions setup-get-tested/setup-get-tested.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

set -euo pipefail
source ./common.sh

inputs_directory="${inputs_directory:?Missing inputs directory}"

tmpdir="$(mktemp -d "${RUNNER_TEMP}/setup-get-tested.XXXXXX")"

os="$(uname | tr '[:upper:]' '[:lower:]')"
case "$os" in
msys* | mingw* | cygwin*)
os="windows"
# On Windows runners, convert D:\... to /d/...
tmpdir="$(cygpath -u "$tmpdir")"
directory_posix="$(cygpath -u "$inputs_directory")"
outfile="get-tested.zip"
;;
*)
directory_posix="$inputs_directory"
outfile="get-tested.tar.gz"
;;
esac

requested_version="${requested_version:-latest}"
minimum_modern_version="0.1.7.1"
if is_tag_newer "$requested_version" "$minimum_modern_version"; then
requested_old_version=false
else
requested_old_version=true
fi
trap 'rm -rf ''${tmpdir}''' EXIT
if [[ "$os" == "darwin" ]]; then
pattern='get-tested-*-macOS-arm64.tar.gz'
elif [[ "$os" == "linux" ]] && [[ "$requested_old_version" == true ]]; then
pattern='get-tested-*-linux-amd64'
elif [[ "$os" == "linux" ]]; then
pattern='get-tested-*-Linux-static-x86_64.tar.gz'
else
pattern='get-tested-*-Windows-x86_64.zip'
fi
echo "::debug::chose '$pattern' for ::'$os'::"

gh_release_flags=(
--repo Kleidukos/get-tested
--pattern "$pattern"
--output "${tmpdir}/${outfile}"
)
if [[ "$requested_version" == "get-tested-head" ]]; then
gh release download "get-tested-head" "${gh_release_flags[@]}"
elif [[ "$requested_version" != "latest" ]] && [[ "$requested_version" != "" ]]; then
gh release download "v${requested_version}" "${gh_release_flags[@]}"
else
gh release download "${gh_release_flags[@]}"
fi

mkdir -p "$directory_posix"
if [[ "$os" == "windows" ]]; then
unzip -q -o "${tmpdir}/${outfile}" -d "$directory_posix"
elif [[ "$os" == "linux" ]] && [[ $requested_old_version == true ]]; then
cp "${tmpdir}/${outfile}" "$directory_posix/get-tested"
else
tar -xzf "${tmpdir}/${outfile}" -C "$directory_posix"
fi

path="${directory_posix}/get-tested"
chmod a+x "$path"
echo "path=${path}" >>"${GITHUB_OUTPUT}"
Loading