From ccf35c45b6ddc688a3adbc12002c627131d5a2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= Date: Tue, 9 Jul 2024 14:49:18 -0700 Subject: [PATCH] CI: Fix Windows halotools binaries branding (#336) --- .github/workflows/prod_build_cli.yml | 49 +++++++++++++--------------- cli/build_scripts/win_fix_binary.js | 24 +++++--------- cli/package.json | 2 +- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/.github/workflows/prod_build_cli.yml b/.github/workflows/prod_build_cli.yml index ecc7648..f74b090 100644 --- a/.github/workflows/prod_build_cli.yml +++ b/.github/workflows/prod_build_cli.yml @@ -72,6 +72,8 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20 + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' - name: Install dependencies (root) shell: bash run: | @@ -91,7 +93,6 @@ jobs: run: | cd cli ../node_modules/.bin/webpack - mv dist_webpack/* . mkdir build cp node_modules/@pokusew/pcsclite/build/Release/pcsclite.node build/pcsclite.node - name: Package HaLo CLI tool (Linux) @@ -99,54 +100,50 @@ jobs: shell: bash run: | cd 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 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 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 ./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 dist_webpack/entry_cli.bundle.js + 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 dist_webpack/entry_bridge.bundle.js + 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 dist_webpack/entry_gateway.bundle.js - name: Package HaLo CLI tool (Windows) if: matrix.platform == 'windows' shell: bash run: | cd cli - node build_scripts/ci_scripts.js --platform windows --product cli - cat halotools_version.json - export PKG_PATCHED_BIN='1' + node ./build_scripts/ci_scripts.js --platform windows --product cli export PKG_CACHE_PATH='./.pkg-cache/' 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) if: matrix.platform == 'windows' shell: bash run: | cd cli - node build_scripts/ci_scripts.js --platform windows --product bridge - export PKG_PATCHED_BIN='1' + node ./build_scripts/ci_scripts.js --platform windows --product bridge export PKG_CACHE_PATH='./.pkg-cache/' 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) if: matrix.platform == 'windows' shell: bash run: | cd cli - node build_scripts/ci_scripts.js --platform windows --product gateway - export PKG_PATCHED_BIN='1' + node ./build_scripts/ci_scripts.js --platform windows --product gateway export PKG_CACHE_PATH='./.pkg-cache/' 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) if: matrix.platform == 'macos' shell: bash run: | cd 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 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 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 ./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 dist_webpack/entry_cli.bundle.js + 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 dist_webpack/entry_bridge.bundle.js + 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 dist_webpack/entry_gateway.bundle.js mv "macos_bridge_app" "dist/HaLo CLI Bridge Server.app" mv "macos_pkgbuild_scripts" "dist/macos_pkgbuild_scripts" mv "Entitlements.plist" "dist/Entitlements.plist" @@ -226,14 +223,14 @@ jobs: sha256sum -c jsign.sum - name: Authenticate with gcloud (Windows) if: matrix.platform == 'windows' - uses: google-github-actions/auth@ef5d53e30bbcd8d0836f4288f5e50ff3e086997d + uses: google-github-actions/auth@v2.1.3 with: credentials_json: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_KEY }} - 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' with: - install_components: 'gcloud' + skip_install: true project_id: ${{ secrets.GCLOUD_PROJECT_ID }} - name: Sign application (Windows) if: matrix.platform == 'windows' diff --git a/cli/build_scripts/win_fix_binary.js b/cli/build_scripts/win_fix_binary.js index c67677c..32d4fb0 100644 --- a/cli/build_scripts/win_fix_binary.js +++ b/cli/build_scripts/win_fix_binary.js @@ -1,11 +1,11 @@ +import crypto from "crypto"; import path from "path"; 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 // implicitly installed by "pkg" dev dependency in correct version import { need, system } from '@yao-pkg/pkg-fetch'; import package_json from '../package.json' assert { type: "json" }; -import crypto from "crypto"; import {parseGitHubRef, getProductInfo} from "./version_helper.js"; const { @@ -27,9 +27,6 @@ function computeSha256(filePath) { } 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) { throw Error("Only one pkg target is supported"); } @@ -39,6 +36,7 @@ async function fixBinary(name, bin_name, version) { const nodeBinPath = await need({ dryRun: false, forceBuild: false, + forceFetch: false, nodeRange: package_json['pkg']['targets'][0], platform: hostPlatform, arch: hostArch @@ -50,7 +48,7 @@ async function fixBinary(name, bin_name, version) { }; // Modify .exe w/ ResEdit - const data = readFileSync(nodeBinPath); + const data = fs.readFileSync(nodeBinPath); const executable = ResEdit.NtExecutable.from(data); const res = ResEdit.NtExecutableResource.from(executable); const vi = ResEdit.Resource.VersionInfo.fromEntries(res.entries)[0]; @@ -72,7 +70,7 @@ async function fixBinary(name, bin_name, version) { vi.outputToResourceEntries(res.entries); // 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( res.entries, 1, @@ -83,17 +81,14 @@ async function fixBinary(name, bin_name, version) { // Regenerate and write to .exe res.outputResource(executable); - if (!fs.existsSync(".pkg-cache")){ + if (!fs.existsSync(".pkg-cache")) { fs.mkdirSync(".pkg-cache"); } const nodeBinBase = path.basename(nodeBinPath); - const nodeHashKey = nodeBinBase.replace('fetched-', 'node-'); - const outPath = path.join(".pkg-cache", nodeBinBase); - 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 + '\';}'); + const nodeBuiltKey = nodeBinBase.replace('fetched-', 'built-'); + const outPath = path.join(".pkg-cache", nodeBuiltKey); + fs.writeFileSync(outPath, Buffer.from(executable.generate())); } async function doFixWinBinary(productType) { @@ -103,7 +98,6 @@ async function doFixWinBinary(productType) { await fixBinary(name, binName, version); // run pkg with: - // $env:PKG_PATCHED_BIN = 1 // $env:PKG_CACHE_PATH = './.pkg-cache/' // $env:PKG_IGNORE_TAG = 1 } diff --git a/cli/package.json b/cli/package.json index 99d7c21..e2450e8 100644 --- a/cli/package.json +++ b/cli/package.json @@ -29,7 +29,7 @@ "bin": "entry_cli.js", "pkg": { "targets": [ - "node18" + "node20" ], "outputPath": "dist", "assets": [