From 35b81dcdd0732da88414a3a9187825214538c2ef Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Wed, 23 Jan 2019 02:24:59 +0100 Subject: [PATCH] Change AppVeyor build to cross-compile instead of having two runs (#311) --- .gitignore | 1 + .promu.yml | 4 ++ Makefile | 11 +++++ appveyor.yml | 111 ++++++++++++++++++++++++++++----------------------- 4 files changed, 76 insertions(+), 51 deletions(-) diff --git a/.gitignore b/.gitignore index b9c70563..c3015a88 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ VERSION *.swp *.un~ +output/ diff --git a/.promu.yml b/.promu.yml index fb1063af..61ac8a68 100644 --- a/.promu.yml +++ b/.promu.yml @@ -12,3 +12,7 @@ build: tarball: files: - LICENSE +crossbuild: + platforms: + - windows/amd64 + - windows/386 diff --git a/Makefile b/Makefile index d77e9312..20d76540 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,16 @@ +export GOOS=windows + fmt: gofmt -l -w -s . build: promu build -v + +test: + go test -v ./... + +crossbuild: + # The prometheus/golang-builder image for promu crossbuild doesn't exist + # on Windows, so for now, we'll just build twice + GOARCH=amd64 promu build --prefix=output/amd64 + GOARCH=386 promu build --prefix=output/386 diff --git a/appveyor.yml b/appveyor.yml index 4e8699fe..9d30050f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,51 +1,60 @@ -version: "{build}" - -os: Windows Server 2012 R2 - -environment: - GOPATH: c:\gopath - matrix: - - MSI_ARCH: amd64 - GOARCH: amd64 - - MSI_ARCH: 386 - GOARCH: 386 - -clone_folder: c:\gopath\src\github.com\martinlindhe\wmi_exporter - -install: - - go version - - set PATH=%GOPATH%\bin;c:\go\bin;%GOPATH%\bin\windows_%GOARCH%;%PATH% - - go get -u github.com/prometheus/promu - - choco install gitversion.portable -y - -build_script: - - ps: gitversion /output json /showvariable FullSemVer | Set-Content VERSION -PassThru - - go test -v ./... - - promu build -v - - ps: | - $ErrorActionPreference = "Stop" - if($env:APPVEYOR_REPO_TAG -eq "True") { - # The MSI version is not semver compliant, so just take the numerical parts - $Version = $env:APPVEYOR_REPO_TAG_NAME -replace '^v?([0-9\.]+).*$','$1' - Write-Verbose "Setting msi version to $Version" - .\installer\build.ps1 -PathToExecutable .\wmi_exporter.exe -Version $Version -Arch "$env:MSI_ARCH" - Push-AppveyorArtifact installer\Output\wmi_exporter-$Version-$env:MSI_ARCH.msi -DeploymentName Installer - } - -after_build: - - 7z a wmi_exporter-%MSI_ARCH%.zip wmi_exporter.exe - -artifacts: - - name: Executable - path: 'wmi_exporter-*.zip' - -deploy: - - provider: GitHub - description: WMI Exporter version $(appveyor_build_version) - artifact: Executable,Installer - auth_token: - secure: 'CrXWeTf7qONUOEki5olFfGEUPMLDeHj61koDXV3OVEaLgtACmnVHsKUub9POflda' - draft: false - prerelease: false - on: - appveyor_repo_tag: true +version: "{build}" + +os: Visual Studio 2017 +build: off +stack: go 1.10 + +environment: + GOPATH: c:\gopath + +clone_folder: c:\gopath\src\github.com\martinlindhe\wmi_exporter + +install: + - set PATH=%GOPATH%\bin;%PATH% + - go get -u github.com/prometheus/promu + - choco install gitversion.portable make -y + +test_script: + - make test + +build_script: + - ps: | + $ErrorActionPreference = "Stop" + gitversion /output json /showvariable FullSemVer | Set-Content VERSION -PassThru + $Version = Get-Content VERSION + make crossbuild + # GH requires all files to have different names, so add version/arch to differentiate + foreach($Arch in "amd64","386") { + Rename-Item output\$Arch\wmi_exporter.exe -NewName wmi_exporter-$Version-$Arch.exe + } + +after_build: + - ps: | + # Build installer packages only on tagged releases + if($env:APPVEYOR_REPO_TAG -ne "True") { + return + } + $ErrorActionPreference = "Stop" + # The MSI version is not semver compliant, so just take the numerical parts + $Version = $env:APPVEYOR_REPO_TAG_NAME -replace '^v?([0-9\.]+).*$','$1' + foreach($Arch in "amd64","386") { + Write-Verbose "Building wmi_exporter $Version msi for $Arch" + .\installer\build.ps1 -PathToExecutable .\output\$Arch\wmi_exporter-$Version-$Arch.exe -Version $Version -Arch "$Arch" + Move-Item installer\Output\wmi_exporter-$Version-$Arch.msi output\$Arch\ + } + - promu checksum output\ + +artifacts: + - name: Artifacts + path: output\**\* + +deploy: + - provider: GitHub + description: WMI Exporter version $(appveyor_build_version) + artifact: Artifacts + auth_token: + secure: 'CrXWeTf7qONUOEki5olFfGEUPMLDeHj61koDXV3OVEaLgtACmnVHsKUub9POflda' + draft: false + prerelease: false + on: + appveyor_repo_tag: true