CI: Fix Windows halotools binaries branding (#336)

This commit is contained in:
Michał Leszczyński
2024-07-09 14:49:18 -07:00
committed by GitHub
parent be2795297a
commit ccf35c45b6
3 changed files with 33 additions and 42 deletions

View File

@@ -72,6 +72,8 @@ jobs:
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
- name: Install dependencies (root) - name: Install dependencies (root)
shell: bash shell: bash
run: | run: |
@@ -91,7 +93,6 @@ jobs:
run: | run: |
cd cli cd cli
../node_modules/.bin/webpack ../node_modules/.bin/webpack
mv dist_webpack/* .
mkdir build mkdir build
cp node_modules/@pokusew/pcsclite/build/Release/pcsclite.node build/pcsclite.node cp node_modules/@pokusew/pcsclite/build/Release/pcsclite.node build/pcsclite.node
- name: Package HaLo CLI tool (Linux) - name: Package HaLo CLI tool (Linux)
@@ -99,54 +100,50 @@ jobs:
shell: bash shell: bash
run: | run: |
cd cli cd cli
node build_scripts/ci_scripts.js --platform linux --product cli node ./build_scripts/ci_scripts.js --platform linux --product cli
node_modules/.bin/pkg --compress GZip -t node20-linux-x64 -c package.json -o dist/halocli entry_cli.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-linux-x64 -c package.json -o dist/halocli dist_webpack/entry_cli.bundle.js
node build_scripts/ci_scripts.js --platform linux --product bridge node ./build_scripts/ci_scripts.js --platform linux --product bridge
node_modules/.bin/pkg --compress GZip -t node20-linux-x64 -c package.json -o dist/halo-bridge entry_bridge.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-linux-x64 -c package.json -o dist/halo-bridge dist_webpack/entry_bridge.bundle.js
node build_scripts/ci_scripts.js --platform linux --product gateway node ./build_scripts/ci_scripts.js --platform linux --product gateway
node_modules/.bin/pkg --compress GZip -t node20-linux-x64 -c package.json -o dist/halo-gateway entry_gateway.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-linux-x64 -c package.json -o dist/halo-gateway dist_webpack/entry_gateway.bundle.js
- name: Package HaLo CLI tool (Windows) - name: Package HaLo CLI tool (Windows)
if: matrix.platform == 'windows' if: matrix.platform == 'windows'
shell: bash shell: bash
run: | run: |
cd cli cd cli
node build_scripts/ci_scripts.js --platform windows --product cli node ./build_scripts/ci_scripts.js --platform windows --product cli
cat halotools_version.json
export PKG_PATCHED_BIN='1'
export PKG_CACHE_PATH='./.pkg-cache/' export PKG_CACHE_PATH='./.pkg-cache/'
export PKG_IGNORE_TAG='1' export PKG_IGNORE_TAG='1'
node_modules/.bin/pkg --compress GZip -t node20-win-x64 -c package.json -o dist/halocli.exe entry_cli.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-win-x64 -c package.json -o dist/halocli.exe dist_webpack/entry_cli.bundle.js
- name: Package HaLo Bridge tool (Windows) - name: Package HaLo Bridge tool (Windows)
if: matrix.platform == 'windows' if: matrix.platform == 'windows'
shell: bash shell: bash
run: | run: |
cd cli cd cli
node build_scripts/ci_scripts.js --platform windows --product bridge node ./build_scripts/ci_scripts.js --platform windows --product bridge
export PKG_PATCHED_BIN='1'
export PKG_CACHE_PATH='./.pkg-cache/' export PKG_CACHE_PATH='./.pkg-cache/'
export PKG_IGNORE_TAG='1' export PKG_IGNORE_TAG='1'
node_modules/.bin/pkg --compress GZip -t node20-win-x64 -c package.json -o dist/halo-bridge.exe entry_bridge.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-win-x64 -c package.json -o dist/halo-bridge.exe dist_webpack/entry_bridge.bundle.js
- name: Package HaLo Gateway tool (Windows) - name: Package HaLo Gateway tool (Windows)
if: matrix.platform == 'windows' if: matrix.platform == 'windows'
shell: bash shell: bash
run: | run: |
cd cli cd cli
node build_scripts/ci_scripts.js --platform windows --product gateway node ./build_scripts/ci_scripts.js --platform windows --product gateway
export PKG_PATCHED_BIN='1'
export PKG_CACHE_PATH='./.pkg-cache/' export PKG_CACHE_PATH='./.pkg-cache/'
export PKG_IGNORE_TAG='1' export PKG_IGNORE_TAG='1'
node_modules/.bin/pkg --compress GZip -t node20-win-x64 -c package.json -o dist/halo-gateway.exe entry_gateway.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-win-x64 -c package.json -o dist/halo-gateway.exe dist_webpack/entry_gateway.bundle.js
- name: Package HaLo CLI tool (MacOS) - name: Package HaLo CLI tool (MacOS)
if: matrix.platform == 'macos' if: matrix.platform == 'macos'
shell: bash shell: bash
run: | run: |
cd cli cd cli
node build_scripts/ci_scripts.js --platform macos --product cli node ./build_scripts/ci_scripts.js --platform macos --product cli
node_modules/.bin/pkg --compress GZip -t node20-macos-x64 -c package.json -o dist/halocli entry_cli.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-macos-x64 -c package.json -o dist/halocli dist_webpack/entry_cli.bundle.js
node build_scripts/ci_scripts.js --platform macos --product bridge node ./build_scripts/ci_scripts.js --platform macos --product bridge
node_modules/.bin/pkg --compress GZip -t node20-macos-x64 -c package.json -o dist/halo-bridge entry_bridge.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-macos-x64 -c package.json -o dist/halo-bridge dist_webpack/entry_bridge.bundle.js
node build_scripts/ci_scripts.js --platform macos --product gateway node ./build_scripts/ci_scripts.js --platform macos --product gateway
node_modules/.bin/pkg --compress GZip -t node20-macos-x64 -c package.json -o dist/halo-gateway entry_gateway.bundle.js ./node_modules/.bin/pkg --compress GZip -t node20-macos-x64 -c package.json -o dist/halo-gateway dist_webpack/entry_gateway.bundle.js
mv "macos_bridge_app" "dist/HaLo CLI Bridge Server.app" mv "macos_bridge_app" "dist/HaLo CLI Bridge Server.app"
mv "macos_pkgbuild_scripts" "dist/macos_pkgbuild_scripts" mv "macos_pkgbuild_scripts" "dist/macos_pkgbuild_scripts"
mv "Entitlements.plist" "dist/Entitlements.plist" mv "Entitlements.plist" "dist/Entitlements.plist"
@@ -226,14 +223,14 @@ jobs:
sha256sum -c jsign.sum sha256sum -c jsign.sum
- name: Authenticate with gcloud (Windows) - name: Authenticate with gcloud (Windows)
if: matrix.platform == 'windows' if: matrix.platform == 'windows'
uses: google-github-actions/auth@ef5d53e30bbcd8d0836f4288f5e50ff3e086997d uses: google-github-actions/auth@v2.1.3
with: with:
credentials_json: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_KEY }} credentials_json: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_KEY }}
- name: Set up Cloud SDK (Windows) - name: Set up Cloud SDK (Windows)
uses: google-github-actions/setup-gcloud@62d4898025f6041e16b1068643bfc5a696863587 uses: google-github-actions/setup-gcloud@v2.1.0
if: matrix.platform == 'windows' if: matrix.platform == 'windows'
with: with:
install_components: 'gcloud' skip_install: true
project_id: ${{ secrets.GCLOUD_PROJECT_ID }} project_id: ${{ secrets.GCLOUD_PROJECT_ID }}
- name: Sign application (Windows) - name: Sign application (Windows)
if: matrix.platform == 'windows' if: matrix.platform == 'windows'

View File

@@ -1,11 +1,11 @@
import crypto from "crypto";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import { readFileSync, writeFileSync } from 'fs'; import * as ResEdit from "resedit";
// purposely not declared in package.json, the "pkg-fetch" will be // purposely not declared in package.json, the "pkg-fetch" will be
// implicitly installed by "pkg" dev dependency in correct version // implicitly installed by "pkg" dev dependency in correct version
import { need, system } from '@yao-pkg/pkg-fetch'; import { need, system } from '@yao-pkg/pkg-fetch';
import package_json from '../package.json' assert { type: "json" }; import package_json from '../package.json' assert { type: "json" };
import crypto from "crypto";
import {parseGitHubRef, getProductInfo} from "./version_helper.js"; import {parseGitHubRef, getProductInfo} from "./version_helper.js";
const { const {
@@ -27,9 +27,6 @@ function computeSha256(filePath) {
} }
async function fixBinary(name, bin_name, version) { async function fixBinary(name, bin_name, version) {
// unable to normally require, this is ES6 module
const ResEdit = await import('resedit');
if (package_json['pkg']['targets'].length !== 1) { if (package_json['pkg']['targets'].length !== 1) {
throw Error("Only one pkg target is supported"); throw Error("Only one pkg target is supported");
} }
@@ -39,6 +36,7 @@ async function fixBinary(name, bin_name, version) {
const nodeBinPath = await need({ const nodeBinPath = await need({
dryRun: false, dryRun: false,
forceBuild: false, forceBuild: false,
forceFetch: false,
nodeRange: package_json['pkg']['targets'][0], nodeRange: package_json['pkg']['targets'][0],
platform: hostPlatform, platform: hostPlatform,
arch: hostArch arch: hostArch
@@ -50,7 +48,7 @@ async function fixBinary(name, bin_name, version) {
}; };
// Modify .exe w/ ResEdit // Modify .exe w/ ResEdit
const data = readFileSync(nodeBinPath); const data = fs.readFileSync(nodeBinPath);
const executable = ResEdit.NtExecutable.from(data); const executable = ResEdit.NtExecutable.from(data);
const res = ResEdit.NtExecutableResource.from(executable); const res = ResEdit.NtExecutableResource.from(executable);
const vi = ResEdit.Resource.VersionInfo.fromEntries(res.entries)[0]; const vi = ResEdit.Resource.VersionInfo.fromEntries(res.entries)[0];
@@ -72,7 +70,7 @@ async function fixBinary(name, bin_name, version) {
vi.outputToResourceEntries(res.entries); vi.outputToResourceEntries(res.entries);
// Add icon // Add icon
const iconFile = ResEdit.Data.IconFile.from(readFileSync("halo.ico")); const iconFile = ResEdit.Data.IconFile.from(fs.readFileSync("halo.ico"));
ResEdit.Resource.IconGroupEntry.replaceIconsForResource( ResEdit.Resource.IconGroupEntry.replaceIconsForResource(
res.entries, res.entries,
1, 1,
@@ -83,17 +81,14 @@ async function fixBinary(name, bin_name, version) {
// Regenerate and write to .exe // Regenerate and write to .exe
res.outputResource(executable); res.outputResource(executable);
if (!fs.existsSync(".pkg-cache")){ if (!fs.existsSync(".pkg-cache")) {
fs.mkdirSync(".pkg-cache"); fs.mkdirSync(".pkg-cache");
} }
const nodeBinBase = path.basename(nodeBinPath); const nodeBinBase = path.basename(nodeBinPath);
const nodeHashKey = nodeBinBase.replace('fetched-', 'node-'); const nodeBuiltKey = nodeBinBase.replace('fetched-', 'built-');
const outPath = path.join(".pkg-cache", nodeBinBase); const outPath = path.join(".pkg-cache", nodeBuiltKey);
writeFileSync(outPath, Buffer.from(executable.generate())); fs.writeFileSync(outPath, Buffer.from(executable.generate()));
const fileHash = await computeSha256(outPath);
fs.appendFileSync('node_modules\\@yao-pkg\\pkg-fetch\\lib-es5\\expected.js', '\n/** PATCHED **/ if (process.env.PKG_PATCHED_BIN === "1") {exports.EXPECTED_HASHES[\'' + nodeHashKey + '\'] = \'' + fileHash + '\';}');
} }
async function doFixWinBinary(productType) { async function doFixWinBinary(productType) {
@@ -103,7 +98,6 @@ async function doFixWinBinary(productType) {
await fixBinary(name, binName, version); await fixBinary(name, binName, version);
// run pkg with: // run pkg with:
// $env:PKG_PATCHED_BIN = 1
// $env:PKG_CACHE_PATH = './.pkg-cache/' // $env:PKG_CACHE_PATH = './.pkg-cache/'
// $env:PKG_IGNORE_TAG = 1 // $env:PKG_IGNORE_TAG = 1
} }

View File

@@ -29,7 +29,7 @@
"bin": "entry_cli.js", "bin": "entry_cli.js",
"pkg": { "pkg": {
"targets": [ "targets": [
"node18" "node20"
], ],
"outputPath": "dist", "outputPath": "dist",
"assets": [ "assets": [