diff --git a/.github/workflows/installation.yml b/.github/workflows/installation.yml new file mode 100644 index 00000000..da2f57ae --- /dev/null +++ b/.github/workflows/installation.yml @@ -0,0 +1,53 @@ +name: Installation Tests + +on: + pull_request: + branches: [ main ] + +jobs: + install_test: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + env: + PCT_INSTALL_DEBUG: true + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Get Latest Tag (Windows) + id: latest_tag + if: runner.os == 'Windows' + run: | + $TagVersion = git tag --list | + Where-Object { $_ -match '^\d+\.\d+\.\d+$' } | + Sort-Object -Descending | + Select-Object -First 1 + echo "::set-output name=tag::0.4.0 d18bd02" + - name: Install PCT (Windows) + if: runner.os == 'Windows' + shell: pwsh + run: | + . .\tools\install.ps1; Install-Pct + - name: Validate install (Windows) + if: runner.os == 'Windows' + run: | + $HomeDir = Get-Item ~ | Select-Object -ExpandProperty FullName + $PctPath = "${HomeDir}\.puppetlabs\pct\pct.exe" + $verInfo = & $PctPath --version | + Select-Object -First 1 | + ForEach-Object { $_ -split " " } | + Select-Object -Skip 1 -First 2 + if (& $PctPath --version | Out-String -Stream | Select-String -Pattern '${{ steps.latest_tag.outputs.tag }}') { + exit 0 + } else { + exit 1 + } + - name: Install PCT (Unix) + if: runner.os != 'Windows' + run: ./tools/install.sh + - name: Validate install (Unix) + if: runner.os != 'Windows' + run: $HOME/.puppetlabs/pct/pct --version | grep "pct $(git tag | tail -n 1)" diff --git a/.goreleaser.yml b/.goreleaser.yml index 5bd654de..acf7372e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -52,7 +52,7 @@ builds: mod_timestamp: '{{ .CommitTimestamp }}' archives: - - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ tolower .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" + - name_template: "{{ .ProjectName }}_{{ tolower .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" replacements: darwin: Darwin linux: Linux diff --git a/README.md b/README.md index 733b39e3..ce9761ff 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ * [Installing template packages](#installing-template-packages) * [Request a feature](#request-a-feature) * [Reporting Problems](#reporting-problems) +* [Installing Telemetry Free Version](#installing-telemetry-free-version) ## Overview @@ -50,7 +51,7 @@ curl -L https://pup.pt/pdkgo/install.sh | sh ### Windows Systems ```ps -iex "&{ $(irm https://pup.pt/pdkgo/install.ps1) }" +iex "&{ $(irm https://pup.pt/pdkgo/install.ps1); Install-Pct }" ``` This will install the latest release of PCT to `~/.puppetlabs/pct`. @@ -59,6 +60,9 @@ This will install the latest release of PCT to `~/.puppetlabs/pct`. > :warning: If you do not use the install script and are extracting the archive yourself, be sure to use the fully qualified path to `~/.puppetlabs/pct` on *nix or `$HOME/.puppetlabs/pct` on Windows when you set your `PATH` environment variable. +A version of the product, with telemetry functionality disabled, is available too. +See [here](#installing-telemetry-free-version) for instructions on how to install it. + ## Setting up Tab Completion After installation, we'd highly recommend setting up tab completion for your shell to ensure the best possible experience. @@ -445,3 +449,32 @@ to file an issue on our GitHub repository: https://github.com/puppetlabs/pdkgo/i Make sure to fill in the information that is requested in the issue template as it will help us investigate the problem more quickly. + +## Installing Telemetry Free Version + +As of `0.5.0`, we have been gathering telemetry data to provide insights in to how our products are being used. + +The following data is collected: + +- Version of application in use +- OS / platform of the device +- What commands have been invoked (including command args) +- Any errors that occurred when running the application + +We understand that there will be some users who prefer to have no telemetry data sent. +For those users, we offer a version of PCT with the telemetry functionality disabled. + +To install: +### Unix Systems + +```bash +curl -L https://pup.pt/pdkgo/install.sh | sh -s -- --no-telemetry +``` + +### Windows Systems + +```ps +iex "&{ $(irm https://pup.pt/pdkgo/install.ps1); Install-Pct -NoTelemetry }" +``` + +This will install the latest release of PCT, without telemetry functionality, to `~/.puppetlabs/pct`. diff --git a/tools/install.ps1 b/tools/install.ps1 index 87f9b9fb..ea9f56d6 100755 --- a/tools/install.ps1 +++ b/tools/install.ps1 @@ -1,49 +1,61 @@ -[CmdletBinding()] -param ( -) +function Install-Pct { + [CmdletBinding()] + param ( + [switch]$NoTelemetry + ) -Set-StrictMode -Version 3.0 -$ErrorActionPreference = "Stop" + Set-StrictMode -Version 3.0 + $ErrorActionPreference = "Stop" -$org = 'puppetlabs' -$repo = 'pdkgo' + $org = 'puppetlabs' + $repo = 'pdkgo' -$app = 'pct' + $app = 'pct' -$arch = "x86_64" -$os = 'windows' -$ext = '.zip' + $appPkgName = 'pct' + if ($NoTelemetry) { + $appPkgName = 'notel_pct' + } -$ver = (Invoke-RestMethod "https://api.github.com/repos/${org}/${repo}/releases")[0].tag_name -$file = "${app}_${ver}_${os}_${arch}${ext}" -$downloadURL = "https://github.com/${org}/${repo}/releases/download/$ver/$file" + $arch = "x86_64" + $os = 'windows' + $ext = '.zip' -$Destination = "~/.puppetlabs/pct" -$Destination = $PSCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination) + $file = "${appPkgName}_${os}_${arch}${ext}" + $downloadURL = "https://github.com/${org}/${repo}/releases/latest/download/$file" -$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) -$null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue -$packagePath = Join-Path -Path $tempDir -ChildPath $file + $Destination = "~/.puppetlabs/pct" + $Destination = $PSCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination) -if (!$PSVersionTable.ContainsKey('PSEdition') -or $PSVersionTable.PSEdition -eq "Desktop") { - $oldProgressPreference = $ProgressPreference - $ProgressPreference = "SilentlyContinue" -} + $tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) + $null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue + $packagePath = Join-Path -Path $tempDir -ChildPath $file -try { - Write-Host "Downloading and extracting ${app} ${ver} to ${Destination}" - Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath -} -finally { if (!$PSVersionTable.ContainsKey('PSEdition') -or $PSVersionTable.PSEdition -eq "Desktop") { - $ProgressPreference = $oldProgressPreference + $oldProgressPreference = $ProgressPreference + $ProgressPreference = "SilentlyContinue" } -} -if (Test-Path -Path $Destination) { - Remove-Item -Path $Destination -Force -Recurse -} -Expand-Archive -Path $packagePath -DestinationPath $Destination + try { + if ($NoTelemetry) { + Write-Host "Downloading and extracting ${app} (TELEMETRY DISABLED VERSION) to ${Destination}" + } + else { + Write-Host "Downloading and extracting ${app} to ${Destination}" + } + Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath + } + finally { + if (!$PSVersionTable.ContainsKey('PSEdition') -or $PSVersionTable.PSEdition -eq "Desktop") { + $ProgressPreference = $oldProgressPreference + } + } -Write-Host 'Remember to add the pct app to your path:' -Write-Host "`$env:Path += `"`$env:PATH;${Destination}`"" + if (Test-Path -Path $Destination) { + Remove-Item -Path $Destination -Force -Recurse + } + Expand-Archive -Path $packagePath -DestinationPath $Destination + + Write-Host 'Remember to add the pct app to your path:' + Write-Host "`$env:Path += `"`$env:PATH;${Destination}`"" +} diff --git a/tools/install.sh b/tools/install.sh index 13fad342..0860379b 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -1,29 +1,99 @@ #!/bin/sh -set -eu +set -e -org="puppetlabs" -repo="pdkgo" +ARCH="x86_64" +OS="$(uname -s | tr '[:upper:]' '[:lower:]')" +EXT=".tar.gz" -app="pct" +ORG="puppetlabs" +REPO="pdkgo" +APP="pct" +APP_PKG_NAME="pct" -arch="x86_64" -os="$(uname -s | tr '[:upper:]' '[:lower:]')" -ext=".tar.gz" +NO_TEL=${1:-false} -releases="$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${org}/${repo}/releases")" +if [ ${NO_TEL} = "--no-telemetry" ]; then + APP_PKG_NAME="notel_pct" +fi -ver="$(echo "$releases" | grep -oE -m 1 '"tag_name": "(([0-9]+\.)+[0-9]+(-pre+)?)"' | cut -d '"' -f 4 | head -1)" +RELEASES="" +FILE="" +VER="" +CHECKSUM="" -file="${app}_${ver}_${os}_${arch}${ext}" +logDebug() { + if [ ! -z $PCT_INSTALL_DEBUG ]; then + echo $1 + fi +} -downloadURL="https://github.com/${org}/${repo}/releases/download/${ver}/${file}" +getChecksums() { + for i in {1..5}; do + FILE="${APP_PKG_NAME}_${OS}_${ARCH}${EXT}" + checksumURL="https://github.com/${ORG}/${REPO}/releases/latest/download/checksums.txt" + resp=$(curl -Ls "${checksumURL}" -o /tmp/pct_checksums.txt --write-out "%{http_code}") + respCode=$(echo ${resp} | tail -n 1) + logDebug "GET ${checksumURL} | Resp: ${resp}" + if [ ${respCode} -ne 200 ]; then + echo "Fetching checksums.txt failed on attempt ${i}, retrying..." + sleep 5 + else + CHECKSUM=$(grep ${FILE} /tmp/pct_checksums.txt | cut -d ' ' -f 1) + return 0 + fi + done + echo "Fetching checksums.txt failed after max retry attempts" + exit 1 +} -destination="${HOME}/.puppetlabs/pct" +downloadLatestRelease() { + destination="${HOME}/.puppetlabs/pct" -[ -d "${destination}" ] || mkdir -p "${destination}" + [ -d ${destination} ] || mkdir -p ${destination} ] -echo "Downloading and extracting ${app} ${ver} to ${destination}" -curl -L -s "${downloadURL}" -o - | tar xz -C "${destination}" + if [ "${noTel}" = "--no-telemetry" ]; then + echo "Downloading and extracting ${APP_PKG_NAME} (TELEMETRY DISABLED VERSION) to ${destination}" + else + echo "Downloading and extracting ${APP_PKG_NAME} to ${destination}" + fi -echo 'Remember to add the pct app to your path:' -echo 'export PATH=$PATH:'${destination} + downloadURL="https://github.com/${ORG}/${REPO}/releases/latest/download/${FILE}" + + for i in {1..5}; do + resp=$(curl -Ls ${downloadURL} -o /tmp/${FILE} --write-out "%{http_code}") + respCode=$(echo ${resp} | tail -n 1) + logDebug "GET ${downloadURL} | Resp: ${resp}" + if [ ${respCode} -ne 200 ]; then + echo "Fetching PCT package failed on attempt ${i}, retrying..." + sleep 5 + else + downloadChecksumRaw=$(shasum -a 256 /tmp/${FILE} || sha256sum /tmp/${FILE}) + downloadChecksum=$(echo ${downloadChecksumRaw} | cut -d ' ' -f 1) + logDebug "Checksum calc for ${FILE}:" + logDebug " - Expect checksum: ${CHECKSUM}" + logDebug " - Actual checksum: ${downloadChecksum}" + if [ ${downloadChecksum} = ${CHECKSUM} ]; then + logDebug "Extracting /tmp/${FILE} to ${destination}" + tar -zxf "/tmp/${FILE}" -C ${destination} + tarStatus=$(echo $?) + logDebug "Removing /tmp/${FILE}" + rm "/tmp/${FILE}" + if [ ${tarStatus} -eq 0 ]; then + echo "Remember to add the pct app to your path:" + echo 'export PATH=$PATH:'${destination} + exit 0 + else + echo "Untar unsuccessful (status code: $?)" + exit 1 + fi + else + echo "Checksum verification failed for ${FILE}" + exit 1 + fi + return 0 + fi + done +} + +getChecksums +downloadLatestRelease