From 89368d7ac9400a4d57f7c0e63eeebe51c6ede0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Pich=C3=A9?= Date: Mon, 15 Jul 2024 10:11:30 -0400 Subject: [PATCH] GitHub Action to install TGF --- .github/workflows/test-install.yml | 18 ++++++++++++++++ README.md | 11 ++++++++++ action.yml | 34 ++++++++++++++++++++++++++++++ get-latest-tgf.ps1 | 8 +++++-- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 action.yml diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml index 5aa1b74..4518a2d 100644 --- a/.github/workflows/test-install.yml +++ b/.github/workflows/test-install.yml @@ -9,6 +9,7 @@ on: jobs: posix: strategy: + fail-fast: false matrix: os: [ macos-latest, ubuntu-latest ] runs-on: ${{ matrix.os }} @@ -17,9 +18,26 @@ jobs: - uses: actions/checkout@v4 - run: ./get-latest-tgf.sh + windows: runs-on: windows-latest steps: - uses: actions/checkout@v4 - run: ./get-latest-tgf.ps1 + + + action: + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + ref: ${{ github.head_ref }} + + - run: tgf --help-tgf diff --git a/README.md b/README.md index a935b9d..c9d9d60 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,17 @@ outdated version. ## Installation +### GitHub Action + +You can install `TGF` using the provided GitHub Action: + +``` + steps: + - uses: coveooss/tgf@master +``` + +### Manual installation + On `mac` and `linux`: You can run the `get-latest-tgf.sh` script to check if you have the latest version of tgf installed and install it as needed: diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..77d5322 --- /dev/null +++ b/action.yml @@ -0,0 +1,34 @@ +name: Install TGF +description: GitHub Action to install https://github.com/coveooss/tgf + +inputs: + tgf-path: + description: | + Installs the TGF binary to this folder. + The folder will not be added to the PATH, but the defaults are typically already in the path. + required: false + default: ${{ runner.os == 'Windows' && '${env:LocalAppData}\Microsoft\WindowsApps' || '/usr/local/bin' }} + ref: + description: The ref to use to run the install script. + default: ${{ github.action_ref }} + required: false + + +runs: + using: "composite" + steps: + - name: Install TGF (posix) + if: runner.os != 'Windows' + shell: bash + env: + TGF_PATH: ${{ inputs.tgf-path }} + VERSION: ${{ inputs.ref }} + run: curl "https://raw.githubusercontent.com/coveooss/tgf/${VERSION}/get-latest-tgf.sh" | bash + + - name: Install TGF (windows) + if: runner.os == 'Windows' + shell: pwsh + env: + TGF_PATH: ${{ inputs.tgf-path }} + VERSION: ${{ inputs.ref }} + run: (Invoke-WebRequest https://raw.githubusercontent.com/coveooss/tgf/${env:VERSION}/get-latest-tgf.ps1).Content | Invoke-Expression diff --git a/get-latest-tgf.ps1 b/get-latest-tgf.ps1 index d24538f..2b6b926 100644 --- a/get-latest-tgf.ps1 +++ b/get-latest-tgf.ps1 @@ -30,11 +30,15 @@ $ZipFile = "tgf.zip" $TempTgfFolder = "tgf_unzipped" $TempTgfPath = Join-Path -Path $TempTgfFolder -ChildPath "tgf.exe" -Write-Host "Installing tgf v$($LATEST_VERSION) in the current directory ($(Get-Location)) ..." +Write-Host "Installing: tgf v$($LATEST_VERSION)" Invoke-WebRequest "https://github.com/coveo/tgf/releases/download/v$($LATEST_VERSION)/tgf_$($LATEST_VERSION)_windows_64-bits.zip" -OutFile $ZipFile Expand-Archive -Path $ZipFile -DestinationPath $TempTgfFolder -Copy-Item $TempTgfPath -Destination $TGF_PATH -Force +$Destination = if ([string]::IsNullOrWhiteSpace(${env:TGF_PATH})) { "." } else { $ExecutionContext.InvokeCommand.ExpandString(${env:TGF_PATH}) } +Write-Host "Copying executable to $($Destination)" +Copy-Item $TempTgfPath -Destination $Destination -Force + +Write-Host "Cleaning up..." Remove-Item $ZipFile Remove-Item $TempTgfFolder -Recurse Write-Host "Installation is completed!"