Skip to content

Commit da32cc1

Browse files
committed
Add support for Azure Artifact Signing
1 parent 8b1f666 commit da32cc1

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

.github/workflows/publish-windows.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ on:
77
tags:
88
- v*
99

10+
permissions:
11+
contents: read
12+
id-token: write
13+
1014
jobs:
1115
build:
1216
runs-on: windows-latest
17+
environment: azuresigning
1318
steps:
1419
- name: Checkout
1520
uses: actions/checkout@v2
@@ -21,9 +26,21 @@ jobs:
2126
run: |
2227
npm i
2328
npm i -g nexe@4.0.0-rc.7
29+
- name: Retrieve the metadata and decode it to a file
30+
env:
31+
AZURESIGNING_METADATA: ${{ secrets.AZURESIGNING_METADATA }}
32+
run: |
33+
echo $AZURESIGNING_METADATA | base64 --decode > "$RUNNER_TEMP\metadata.json"
34+
shell: bash
35+
- name: Azure login
36+
uses: azure/login@v1
37+
with:
38+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
39+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
40+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
2441
- name: Build bundle
2542
run: |
26-
npm run winbundle
43+
npm run winbundle -- --signtool-path "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe" --azure-signing-metadata "%RUNNER_TEMP%\metadata.json"
2744
- name: Upload Bundle File
2845
uses: actions/upload-artifact@v4
2946
with:

scripts/winbundle.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ const request = require('request');
55
const async = require('async');
66
const nodeUnzip = require('node-unzip-2');
77
const archiver = require('archiver');
8+
const os = require('os');
89

910
const bundleName = "nodeodm-windows-x64.zip";
1011

12+
const scratch = 'RUNNER_TEMP' in process.env ? process.env.RUNNER_TEMP : os.tmpdir();
13+
1114
const download = function(uri, filename, callback) {
1215
console.log(`Downloading ${uri}`);
1316
request.head(uri, function(err, res, body) {
@@ -68,13 +71,42 @@ async.series([
6871
cb => {
6972
downloadApp(path.join("apps", "unzip"), "https://github.com/OpenDroneMap/NodeODM/releases/download/v2.1.0/unzip600.zip", cb);
7073
},
74+
cb => {
75+
downloadApp(path.join(scratch, "azuresigning"), "https://www.nuget.org/api/v2/package/Microsoft.ArtifactSigning.Client/1.0.115", cb);
76+
},
7177
cb => {
7278
console.log("Building executable");
73-
const code = spawnSync('nexe.cmd', ['index.js', '-t', 'windows-x64-12.16.3', '-o', 'nodeodm.exe'], { stdio: "pipe"}).status;
79+
const code = spawnSync('nexe.cmd', ['index.js', '-t', 'windows-x64-12.16.3', '-o', 'nodeodm.exe'], { stdio: "inherit", shell: true }).status;
7480

7581
if (code === 0) cb();
7682
else cb(new Error(`nexe returned non-zero error code: ${code}`));
7783
},
84+
cb => {
85+
let signtoolPath = null;
86+
let metadataPath = null;
87+
88+
const signtoolPathArgIndex = process.argv.indexOf("--signtool-path");
89+
if (signtoolPathArgIndex !== -1 && signtoolPathArgIndex + 1 < process.argv.length) {
90+
signtoolPath = process.argv[signtoolPathArgIndex + 1];
91+
}
92+
93+
const metadataPathArgIndex = process.argv.indexOf("--azure-signing-metadata");
94+
if (metadataPathArgIndex !== -1 && metadataPathArgIndex + 1 < process.argv.length) {
95+
metadataPath = process.argv[metadataPathArgIndex + 1];
96+
}
97+
98+
if (signtoolPath && metadataPath) {
99+
console.log("Signing executable");
100+
101+
const dlibPath = path.join(scratch, "azuresigning", "bin", "x64", "Azure.CodeSigning.Dlib.dll");
102+
const code = spawnSync(signtoolPath, ['sign', '/v', '/debug', '/fd', 'SHA256', '/tr', 'http://timestamp.acs.microsoft.com', '/td', 'SHA256', '/dlib', dlibPath, '/dmdf', metadataPath, 'nodeodm.exe'], { stdio: "inherit" }).status;
103+
104+
if (code === 0) cb();
105+
else cb(new Error(`signtool returned non-zero error code: ${code}`));
106+
} else {
107+
cb();
108+
}
109+
},
78110
cb => {
79111
// Zip
80112
const outFile = path.join("dist", bundleName);

0 commit comments

Comments
 (0)