diff --git a/.goreleaser.yml b/.goreleaser.yml index 952e22d6a..7263992c8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,11 @@ +before: + hooks: + - mkdir -p ./tmp + - curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/stanza-plugins.tar.gz -o ./tmp/stanza-plugins.tar.gz + - curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/stanza-plugins.zip -o ./tmp/stanza-plugins.zip + - curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/version.json -o ./tmp/version.json + - tar -xf ./tmp/stanza-plugins.tar.gz -C ./tmp + builds: - id: stanza binary: stanza @@ -20,14 +28,13 @@ builds: - -X github.com/observiq/stanza/version.GitTag={{ .Tag }} - -X github.com/observiq/stanza/version.GitCommit={{ .FullCommit }} no_unique_dist_dir: false - hooks: - post: ./build/post.sh archives: - builds: - stanza # skip archiving as tar.gz / zip format: binary + name_template: "stanza_{{ .Os }}_{{ .Arch }}" nfpms: - package_name: stanza @@ -39,7 +46,7 @@ nfpms: - rpm - deb contents: - - src: artifacts/plugins + - src: tmp/plugins dst: /opt/observiq/stanza/plugins - src: build/package/config.yaml dst: /opt/observiq/stanza/config.yaml @@ -58,8 +65,10 @@ release: owner: observIQ name: stanza extra_files: - - glob: scripts/*install* - - glob: stanza*.msi + - glob: scripts/*install* + - glob: stanza*.msi + - glob: ./tmp/stanza-plugins.* + - glob: ./tmp/version.json changelog: skip: false diff --git a/build/post.sh b/build/post.sh deleted file mode 100755 index f2e4cacd0..000000000 --- a/build/post.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# This script is the post-build script for goreleaser. -# Because it is run for each binary built, and global post-release hooks are -# not available in the OSS version, we check for file existence to avoid multiple downloads/copies. - -if [ ! -f ./artifacts/stanza-plugins.tar.gz ]; then - curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/stanza-plugins.tar.gz -o ./artifacts/stanza-plugins.tar.gz -fi -if [ ! -f ./artifacts/stanza-plugins.zip ]; then - curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/stanza-plugins.tar.gz -o ./artifacts/stanza-plugins.tar.gz -fi -if [ ! -f ./artifacts/version.json ]; then - curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/version.json -o ./artifacts/version.json -fi -if [ ! -f ./artifacts/unix-install.sh ]; then - cp ./scripts/unix-install.sh ./artifacts/unix-install.sh -fi -if [ ! -f ./artifacts/windows-install.ps1 ]; then - cp ./scripts/windows-install.ps1 ./artifacts/windows-install.ps1 -fi - -tar -xf ./artifacts/stanza-plugins.tar.gz -C ./artifacts diff --git a/scripts/windows-install.ps1 b/scripts/windows-install.ps1 index 0b77b14ed..ecbf9b51f 100644 --- a/scripts/windows-install.ps1 +++ b/scripts/windows-install.ps1 @@ -288,11 +288,17 @@ new-module -name LogAgentInstall -scriptblock { Show-ColorText 'Configuring download urls...' Add-Indent if ( !$script:version ) { - $script:agent_download_url = "$DOWNLOAD_BASE/latest/download/stanza_windows_amd64" + $script:agent_download_url = "$DOWNLOAD_BASE/latest/download/stanza_windows_amd64.exe" $script:plugins_download_url = "$DOWNLOAD_BASE/latest/download/stanza-plugins.zip" } else { - $script:agent_download_url = "$DOWNLOAD_BASE/download/$script:version/stanza_windows_amd64" + + if (Get-BinaryShouldHaveSuffix -version $script:version) { + $script:agent_download_url = "$DOWNLOAD_BASE/download/$script:version/stanza_windows_amd64.exe" + } else { + $script:agent_download_url = "$DOWNLOAD_BASE/download/$script:version/stanza_windows_amd64" + } + $script:plugins_download_url = "$DOWNLOAD_BASE/download/$script:version/stanza-plugins.zip" } Show-ColorText "Using agent download url: " '' "$script:agent_download_url" DarkCyan @@ -300,6 +306,57 @@ new-module -name LogAgentInstall -scriptblock { Remove-Indent } + # Determines whether the binary should have the .exe suffix or not. + # It should have the prefix if the version specified is after v1.6.0; v1.6.0 and before should not have this prefix. + function Get-BinaryShouldHaveSuffix { + param ( + [string]$version + ) + if ($version -match "^v(?\d+)\.(?\d+)\.(?\d+)") { + $major = [int]$matches['major'] + $minor = [int]$matches['minor'] + $patch = [int]$matches['patch'] + + if ($major -gt 1) { + # version is 2+.x.x + Write-Output $true + return + } + + if ($major -lt 1) { + # version is 0.x.x + Write-Output $false + return + } + + if ($minor -gt 6) { + # version is 1.7+.x + Write-Output $true + return + } + + if ($minor -lt 6) { + # version is 1.5-.x + Write-Output $false + return + } + + if ($patch -gt 0) { + # version is 1.6.1+ + Write-Output $true + return + } + + # version is 1.6.0, which is the last release with no suffix for windows binaries + Write-Output $false + return + } + + # Version doesn't match the semantic version convention; We'll assume that we should have the suffix. + Write-Output $true + return + } + # This will set the home directory of the agent based on # the install directory provided. function Set-HomeDir {