Skip to content

Commit 3db3fe5

Browse files
authored
Pipeline refactor (#135)
* fix windows package signing * pipeline refactor
1 parent f942d3e commit 3db3fe5

File tree

9 files changed

+138
-40
lines changed

9 files changed

+138
-40
lines changed

.github/workflows/prerelease.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ jobs:
122122
- name: Download zip from GH Release assets and extract .exe
123123
shell: pwsh
124124
run: |
125-
build\windows\download_zip_extract_exe.ps1 "$env:INTEGRATION" ${{ matrix.goarch }} "$env:TAG" "$env:REPO_FULL_NAME"
125+
build\windows\download_zip.ps1 "$env:INTEGRATION" ${{ matrix.goarch }} "$env:TAG" "$env:REPO_FULL_NAME"
126+
build\windows\extract_exe.ps1 "$env:INTEGRATION" ${{ matrix.goarch }} "$env:TAG"
126127
- name: Create MSI
127128
shell: pwsh
128129
run: |

.github/workflows/push_pr.yml

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ on:
77
- master
88
- renovate/**
99
pull_request:
10+
workflow_dispatch:
1011

1112
env:
12-
TAG: "v0.0.0" # needed for goreleaser windows builds
13-
REPO_FULL_NAME: ${{ github.event.repository.full_name }}
13+
INTEGRATION: "postgresql"
1414
ORIGINAL_REPO_NAME: "newrelic/nri-postgresql"
15-
DOCKER_LOGIN_AVAILABLE: ${{ secrets.OHAI_DOCKER_HUB_ID }}
15+
REPO_FULL_NAME: ${{ github.event.repository.full_name }}
16+
TAG: "v0.0.0" # needed for fake-prereleases
1617

1718
jobs:
1819
static-analysis:
1920
name: Run all static analysis checks
20-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-latest
2122
steps:
2223
- uses: actions/checkout@v3
2324
- uses: actions/setup-go@v4
@@ -41,7 +42,7 @@ jobs:
4142

4243
test-nix:
4344
name: Run unit tests on *Nix
44-
runs-on: ubuntu-22.04
45+
runs-on: ubuntu-latest
4546
steps:
4647
- uses: actions/checkout@v3
4748
- name: Login to DockerHub
@@ -55,7 +56,7 @@ jobs:
5556

5657
test-windows:
5758
name: Run unit tests on Windows
58-
runs-on: windows-2022
59+
runs-on: windows-latest
5960
env:
6061
GOPATH: ${{ github.workspace }}
6162
defaults:
@@ -72,12 +73,11 @@ jobs:
7273
go-version-file: "src/github.com/${{ env.ORIGINAL_REPO_NAME }}/go.mod"
7374
- name: Running unit tests
7475
shell: pwsh
75-
run: |
76-
.\build\windows\unit_tests.ps1
76+
run: .\build\windows\unit_tests.ps1
7777

7878
test-integration-nix:
7979
name: Run integration tests on *Nix
80-
runs-on: ubuntu-22.04
80+
runs-on: ubuntu-latest
8181
defaults:
8282
run:
8383
working-directory: src/github.com/${{env.ORIGINAL_REPO_NAME}}
@@ -102,16 +102,68 @@ jobs:
102102
GOPATH: ${{ github.workspace }}
103103
run: make integration-test
104104

105-
test-build:
106-
name: Test binary compilation for all platforms:arch
107-
runs-on: ubuntu-22.04
105+
test-build-nix:
106+
name: Test binary compilation and packaging for linux
107+
runs-on: ubuntu-latest
108+
env:
109+
GPG_MAIL: '[email protected]'
110+
GPG_PASSPHRASE: ${{ secrets.OHAI_GPG_PASSPHRASE }}
111+
GPG_PRIVATE_KEY_BASE64: ${{ secrets.OHAI_GPG_PRIVATE_KEY_BASE64 }} # base64 encoded
108112
steps:
109-
- uses: actions/checkout@v3
110-
- name: Login to DockerHub
111-
if: ${{env.DOCKER_LOGIN_AVAILABLE}}
112-
uses: docker/login-action@v2
113-
with:
114-
username: ${{ secrets.OHAI_DOCKER_HUB_ID }}
115-
password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }}
113+
- uses: actions/checkout@v4
114+
- run: |
115+
git tag "$TAG"
116+
if [ -z "$GPG_PASSPHRASE" ]; then
117+
echo NO_SIGN=true >> $GITHUB_ENV
118+
fi
116119
- name: Build all platforms:arch
117-
run: make ci/build
120+
run: make ci/fake-prerelease
121+
- name: Upload artifacts for next job
122+
uses: actions/upload-artifact@v3
123+
with:
124+
name: windows-packages
125+
path: dist/nri-*.zip
126+
127+
test-build-windows:
128+
name: Create MSI
129+
runs-on: windows-latest
130+
needs: [test-build-nix]
131+
env:
132+
GOPATH: ${{ github.workspace }}
133+
PFX_CERTIFICATE_BASE64: ${{ secrets.OHAI_PFX_CERTIFICATE_BASE64 }} # base64 encoded
134+
PFX_CERTIFICATE_DESCRIPTION: 'New Relic'
135+
PFX_PASSPHRASE: ${{ secrets.OHAI_PFX_PASSPHRASE }}
136+
defaults:
137+
run:
138+
working-directory: src/github.com/${{ env.ORIGINAL_REPO_NAME }}
139+
strategy:
140+
matrix:
141+
goarch: [amd64,386]
142+
steps:
143+
- name: Checkout
144+
uses: actions/checkout@v3
145+
with:
146+
path: src/github.com/${{ env.ORIGINAL_REPO_NAME }}
147+
- shell: bash
148+
run: git tag "$TAG"
149+
150+
- name: Download artifact from previous job
151+
uses: actions/download-artifact@v3
152+
with:
153+
name: windows-packages
154+
path: src/github.com/${{ env.ORIGINAL_REPO_NAME }}/dist/
155+
156+
- name: Get PFX certificate from GH secrets
157+
shell: bash
158+
run: |
159+
if [ -z "$PFX_CERTIFICATE_BASE64" ]; then
160+
echo NO_SIGN=true >> $GITHUB_ENV
161+
else
162+
printf "%s" "$PFX_CERTIFICATE_BASE64" | base64 -d - > wincert.pfx
163+
fi
164+
- name: Extract .exe
165+
shell: pwsh
166+
run: build\windows\extract_exe.ps1 "$env:INTEGRATION" ${{ matrix.goarch }} "$env:TAG"
167+
- name: Create MSI
168+
shell: pwsh
169+
run: build\windows\package_msi.ps1 -integration "$env:INTEGRATION" -arch ${{ matrix.goarch }} -tag "$env:TAG" -pfx_passphrase "$env:PFX_PASSPHRASE" -pfx_certificate_description "$env:PFX_CERTIFICATE_DESCRIPTION"

build/ci.mk

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,27 @@ ifdef TAG
7171
else
7272
@echo "===> $(INTEGRATION) === [ci/prerelease] TAG env variable expected to be set"
7373
exit 1
74-
endif
74+
endif
75+
76+
.PHONY : ci/fake-prerelease
77+
ci/fake-prerelease: ci/deps
78+
ifdef TAG
79+
@docker run --rm -t \
80+
--name "nri-$(INTEGRATION)-prerelease" \
81+
-v $(CURDIR):/go/src/github.com/newrelic/nri-$(INTEGRATION) \
82+
-w /go/src/github.com/newrelic/nri-$(INTEGRATION) \
83+
-e INTEGRATION \
84+
-e PRERELEASE=true \
85+
-e NO_PUBLISH=true \
86+
-e NO_SIGN \
87+
-e GITHUB_TOKEN \
88+
-e REPO_FULL_NAME \
89+
-e TAG \
90+
-e GPG_MAIL \
91+
-e GPG_PASSPHRASE \
92+
-e GPG_PRIVATE_KEY_BASE64 \
93+
$(BUILDER_TAG) make release
94+
else
95+
@echo "===> $(INTEGRATION) === [ci/fake-prerelease] TAG env variable expected to be set"
96+
exit 1
97+
endif

build/package/windows/nri-386-installer/nri-installer.wixproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<SchemaVersion>2.0</SchemaVersion>
99
<OutputName>nri-$(IntegrationName)-386</OutputName>
1010
<OutputType>Package</OutputType>
11-
<SignToolPath>C:\Program Files (x86)\Windows Kits\10\bin\x64\</SignToolPath>
11+
<SignToolPath>C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\</SignToolPath>
1212
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
1313
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
1414
<Name>newrelic-nri-$(IntegrationName)-installer</Name>
@@ -44,9 +44,9 @@
4444
</CreateProperty>
4545
</Target>
4646
<Target Name="SignInstaller">
47-
<Exec Command="&quot;$(SignToolPath)signtool.exe&quot; sign /s &quot;My&quot; /d &quot;$(pfx_certificate_description)&quot; /n &quot;$(pfx_certificate_description)&quot; &quot;$(OutputPath)$(OutputName).msi&quot;"/>
47+
<Exec Condition="'$(noSign)' != 'true'" Command="&quot;$(SignToolPath)signtool.exe&quot; sign /s &quot;My&quot; /d &quot;$(pfx_certificate_description)&quot; /n &quot;$(pfx_certificate_description)&quot; &quot;$(OutputPath)$(OutputName).msi&quot;"/>
4848
<Copy SourceFiles="$(OutputPath)$(OutputName).msi" DestinationFiles="$(OutputPath)$(OutputName).x.y.z.msi"/>
4949
<!-- <Delete Files="$(OutputPath)$(OutputName).msi" /> -->
5050
</Target>
5151
<Target Name="AfterBuild" DependsOnTargets="SignInstaller"/>
52-
</Project>
52+
</Project>

build/package/windows/nri-amd64-installer/nri-installer.wixproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<SchemaVersion>2.0</SchemaVersion>
99
<OutputName>nri-$(IntegrationName)-amd64</OutputName>
1010
<OutputType>Package</OutputType>
11-
<SignToolPath>C:\Program Files (x86)\Windows Kits\10\bin\x64\</SignToolPath>
11+
<SignToolPath>C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\</SignToolPath>
1212
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
1313
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
1414
<Name>newrelic-nri-$(IntegrationName)-installer</Name>
@@ -44,9 +44,9 @@
4444
</CreateProperty>
4545
</Target>
4646
<Target Name="SignInstaller">
47-
<Exec Command="&quot;$(SignToolPath)signtool.exe&quot; sign /s &quot;My&quot; /d &quot;$(pfx_certificate_description)&quot; /n &quot;$(pfx_certificate_description)&quot; &quot;$(OutputPath)$(OutputName).msi&quot;"/>
47+
<Exec Condition="'$(noSign)' != 'true'" Command="&quot;$(SignToolPath)signtool.exe&quot; sign /s &quot;My&quot; /d &quot;$(pfx_certificate_description)&quot; /n &quot;$(pfx_certificate_description)&quot; &quot;$(OutputPath)$(OutputName).msi&quot;"/>
4848
<Copy SourceFiles="$(OutputPath)$(OutputName).msi" DestinationFiles="$(OutputPath)$(OutputName).x.y.z.msi"/>
4949
<!-- <Delete Files="$(OutputPath)$(OutputName).msi" /> -->
5050
</Target>
5151
<Target Name="AfterBuild" DependsOnTargets="SignInstaller"/>
52-
</Project>
52+
</Project>

build/release.mk

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,21 @@ release/fix-archive:
4242

4343
.PHONY : release/sign/nix
4444
release/sign/nix:
45+
ifneq ($(NO_SIGN), true)
4546
@echo "===> $(INTEGRATION) === [release/sign] signing packages"
4647
@bash $(CURDIR)/build/nix/sign.sh
47-
48+
else
49+
@echo "===> $(INTEGRATION) === [release/sign] signing packages is disabled by environment variable"
50+
endif
4851

4952
.PHONY : release/publish
5053
release/publish:
54+
ifneq ($(NO_PUBLISH), true)
5155
@echo "===> $(INTEGRATION) === [release/publish] publishing artifacts"
5256
@bash $(CURDIR)/build/upload_artifacts_gh.sh
57+
else
58+
@echo "===> $(INTEGRATION) === [release/publish] publish is disabled by environment variable"
59+
endif
5360

5461
.PHONY : release
5562
release: release/build release/fix-archive release/sign/nix release/publish release/clean

build/windows/download_zip_extract_exe.ps1 renamed to build/windows/download_zip.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ param (
55
[string]$REPO_FULL_NAME="none"
66
)
77
write-host "===> Creating dist folder"
8-
New-Item -ItemType directory -Path .\dist
8+
New-Item -ItemType directory -Path .\dist -Force
99

1010
$VERSION=${TAG}.substring(1)
11-
$exe_folder="nri-${INTEGRATION}_windows_${ARCH}"
1211
$zip_name="nri-${INTEGRATION}-${ARCH}.${VERSION}.zip"
1312

1413
$zip_url="https://github.com/${REPO_FULL_NAME}/releases/download/${TAG}/${zip_name}"
1514
write-host "===> Downloading & extracting .exe from ${zip_url}"
1615
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
1716
Invoke-WebRequest "${zip_url}" -OutFile ".\dist\${zip_name}"
18-
write-host "===> Expanding"
19-
expand-archive -path "dist\${zip_name}" -destinationpath "dist\${exe_folder}\"

build/windows/extract_exe.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
param (
2+
[string]$INTEGRATION="none",
3+
[string]$ARCH="amd64",
4+
[string]$TAG="v0.0.0"
5+
)
6+
write-host "===> Creating dist folder"
7+
New-Item -ItemType directory -Path .\dist -Force
8+
9+
$VERSION=${TAG}.substring(1)
10+
$exe_folder="nri-${INTEGRATION}_windows_${ARCH}"
11+
$zip_name="nri-${INTEGRATION}-${ARCH}.${VERSION}.zip"
12+
13+
write-host "===> Expanding"
14+
expand-archive -path "dist\${zip_name}" -destinationpath "dist\${exe_folder}\"

build/windows/package_msi.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ if ($wrong.Length -ne 0) {
3030
exit -1
3131
}
3232

33-
echo "===> Import .pfx certificate from GH Secrets"
34-
Import-PfxCertificate -FilePath wincert.pfx -Password (ConvertTo-SecureString -String $pfx_passphrase -AsPlainText -Force) -CertStoreLocation Cert:\CurrentUser\My
33+
$noSign = $env:NO_SIGN ?? "false"
34+
if ($noSign -ieq "true") {
35+
echo "===> Import .pfx certificate is disabled by environment variable"
36+
} else {
37+
echo "===> Import .pfx certificate from GH Secrets"
38+
Import-PfxCertificate -FilePath wincert.pfx -Password (ConvertTo-SecureString -String $pfx_passphrase -AsPlainText -Force) -CertStoreLocation Cert:\CurrentUser\My
3539

36-
echo "===> Show certificate installed"
37-
Get-ChildItem -Path cert:\CurrentUser\My\
40+
echo "===> Show certificate installed"
41+
Get-ChildItem -Path cert:\CurrentUser\My\
42+
}
3843

3944
echo "===> Checking MSBuild.exe..."
4045
$msBuild = (Get-ItemProperty hklm:\software\Microsoft\MSBuild\ToolsVersions\4.0).MSBuildToolsPath
@@ -47,8 +52,7 @@ echo $msBuild
4752
echo "===> Building Installer"
4853
Push-Location -Path "build\package\windows\nri-$arch-installer"
4954

50-
. $msBuild/MSBuild.exe nri-installer.wixproj /p:IntegrationVersion=${version} /p:IntegrationName=$integration /p:Year=$buildYear /p:pfx_certificate_description=$pfx_certificate_description
51-
55+
. $msBuild/MSBuild.exe nri-installer.wixproj /p:IntegrationVersion=${version} /p:IntegrationName=$integration /p:Year=$buildYear /p:NoSign=$noSign /p:pfx_certificate_description=$pfx_certificate_description
5256
if (-not $?)
5357
{
5458
echo "Failed building installer"
@@ -60,4 +64,4 @@ echo "===> Making versioned installed copy"
6064
cd bin\Release
6165
cp "nri-$integration-$arch.msi" "nri-$integration-$arch.$version.msi"
6266

63-
Pop-Location
67+
Pop-Location

0 commit comments

Comments
 (0)