Skip to content

Commit

Permalink
Fetch latest TGF release from GH API for install scripts (#401)
Browse files Browse the repository at this point in the history
* Update posix install script to call GH api directly

* Fetch latest release from GH api in windows install script

* Use releases/latest redirect to find the latest version number

* Migrate PS script to use the redirect

* Test install on windows

* Stop iwr from being so noisy

* Simplify test job names

* Simplify workflow some more

* Fix bad tgf version test
  • Loading branch information
dotboris authored Jul 12, 2023
1 parent 0592936 commit d8f6c4e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
name: Test TGF installation
name: Test Install

on:
pull_request:
branches:
- master
jobs:
build:
name: Install

jobs:
posix:
strategy:
matrix:
os: [ macos-latest, ubuntu-latest ]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
- run: ./get-latest-tgf.sh

- name: Install TGF
run: |
./get-latest-tgf.sh
windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- run: ./get-latest-tgf.ps1
17 changes: 14 additions & 3 deletions get-latest-tgf.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
$ErrorActionPreference = "Stop" #Make all errors terminating

try {
$bVersion = (Invoke-WebRequest -Uri "https://coveo-bootstrap-us-east-1.s3.amazonaws.com/tgf_version.txt").Content
$LATEST_VERSION = [System.Text.Encoding]::ASCII.GetString($bVersion)
$latestReleaseRequest = @{
Method = "HEAD"
Uri = "https://github.com/coveooss/tgf/releases/latest"
# Prevent redirect. We want the Location header.
MaximumRedirection = 0
# It considers the redirect http codes errors. Ignore that.
SkipHttpErrorCheck = $true
# The missed redirect generates an actual error which stops the program. We ignore it.
ErrorAction = "SilentlyContinue"
}

$latestReleaseUrl = (Invoke-WebRequest @latestReleaseRequest).Headers["Location"]
$LATEST_VERSION = $latestReleaseUrl.Split("/")[-1].TrimStart("v")
Write-Host "- tgf version (latest):" $LATEST_VERSION
} catch {
Write-Host Error fetching latest version
Expand All @@ -21,4 +32,4 @@ Copy-Item $TempTgfPath -Destination $TGF_PATH -Force
Remove-Item $ZipFile
Remove-Item $TempTgfFolder -Recurse
Write-Host "Installation is completed!"
Write-Host "Make sure to add tgf to your path."
Write-Host "Make sure to add tgf to your path."
26 changes: 18 additions & 8 deletions get-latest-tgf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TGF=${TGF_PATH:=${DEFAULT_INSTALL_DIR}}/tgf

if [ ! -d "${TGF_PATH}" ]; then
echo "creating ${TGF_PATH} directory..."
mkdir -p ${TGF_PATH}
mkdir -p "${TGF_PATH}"
fi

if [ ! -w "${TGF_PATH}" ]; then
Expand Down Expand Up @@ -34,14 +34,24 @@ fi

get_local_tgf_version () {
# The sed regex extracts for example 1.23.2 from "tgf v1.23.2", so as to be comparable to get_latest_tgf_version()
[ -r ${TGF} ] && TGF_LOCAL_VERSION=$(${TGF} --current-version | sed -E -e 's/^.* v(.*)/\1/')
[ -r "${TGF}" ] && TGF_LOCAL_VERSION=$(${TGF} --current-version | sed -E -e 's/^.* v(.*)/\1/')
}

get_latest_tgf_version () {
TGF_LATEST_VERSION=$(curl --silent https://coveo-bootstrap-us-east-1.s3.amazonaws.com/tgf_version.txt)

if [ -z "${TGF_LATEST_VERSION}" ]
then
# The github releases/latest page redirects you to the latest release. We extract the version from the url of the
# `location` header. We could have used the API here but this avoids rate limits. It's also easier to parse http
# headers in bash than it is to parse JSON.
TGF_LATEST_VERSION="$(
curl --fail --silent --show-error --head https://github.com/coveooss/tgf/releases/latest \
| grep -i '^location: ' \
| cut -d ' ' -f 2 \
| cut -d '/' -f 8 \
| tr -d '[:space:]' \
| sed 's/^v//'
)"

if [ -z "$TGF_LATEST_VERSION" ]
then
echo "Could not obtain tgf latest version."
exit 1
fi
Expand All @@ -66,7 +76,7 @@ install_latest_tgf () {
echo 'Installing latest tgf for OSX with arch '$OSX_ARCH' in' $TGF_PATH '...'
DOWNLOAD_URL=$([ "$OSX_ARCH" == "arm64" ] && echo "https://github.com/coveooss/tgf/releases/download/v${TGF_LATEST_VERSION}/tgf_${TGF_LATEST_VERSION}_macOS_arm64.zip" || echo "https://github.com/coveooss/tgf/releases/download/v${TGF_LATEST_VERSION}/tgf_${TGF_LATEST_VERSION}_macOS_64-bits.zip")
curl -sL $DOWNLOAD_URL | bsdtar -xf- -C ${TGF_PATH} && chmod +x ${TGF} && script_end
else
else
echo 'OS not supported.'
exit 1
fi
Expand All @@ -79,7 +89,7 @@ echo '- tgf version (local) :' "${TGF_LOCAL_VERSION}"
echo '- tgf version (latest):' "${TGF_LATEST_VERSION}"

if [[ "${TGF_LOCAL_VERSION}" == "${TGF_LATEST_VERSION}" ]]
then
then
echo 'Local version is up to date.'
else
install_latest_tgf
Expand Down

0 comments on commit d8f6c4e

Please sign in to comment.