1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00
Files
browser/apps/desktop/scripts/build-macos-extension.js
Nathan Ansel d70d81dec6 [BRE-266] Fixes autofill extension signing (#13229)
* Applies patch to enable the autofill extension

* Fixes the zip command

* Updates the signing identity

* Fixes a typo in a github action

* Moves the security command to a previous action

* Updates workflow to work on the PR branch

* Updates the workflow to build from this branch

* Forces native module build

* Adds profile to extension building

* Enables the autofill production config

* List the profiles

* Copies the autofill provisioning profile to Xcode

* Updates the provisioning profile used for the autofill extension

* Alters how the provisioning profile is provided to xcodebuild

* Adds a mas build with the autofill extension

* Print variables

* Removes spaces from the config file

* Updates all provisioning profile installation steps

* Adds a new provisioning profiles location

* Updates the inherited entitlements

* Passes in identity and provisioning profile in after sign call

* Removes mac dev cert from keychain

* Undoes after sign changes

* Adds resign step to workflow

* Fixes the codesign call

* Adds profile argument to electron builder

* Adds resign step to mas builds

* Removes resign step

* Enable debug messages for electron builder signing

* Copies autofill profile instead of desktop

* Add autofill extension to signIgnore list in electron-builder config

* Comment out if in test flight

* Bump version

* Moves the autofill extension building to after pack

* Update version

* Fixes windows and linux builds

* Forces native build

* Removes installation of unrelated certificates

* Comments out synchronous function call

* Update autofill project configuration

* Adds ls command to debug framework

* Moves the extension build script back

* Updates mac developer id provisioning profile

* Updates build location for autofill extension release versions

* Removes unnecessary extension build call

* Updates the version number

* Debug signing

* Removes team identifier from mac entitlements

* Adds new inherited entitlements for mac

* Updates the version number

* Debug version number

* Removes check for creating fastlane secrets

* Readds check for cache before building

* Reverts workflow changes in build-desktop.yml

* Cleans up after-sign and extension build script

* Removes installation of unnecessary mac signing certs

---------

Co-authored-by: Michal Checinski <mchecinski@bitwarden.com>
2025-04-22 09:24:18 -05:00

105 lines
3.6 KiB
JavaScript

/* eslint-disable @typescript-eslint/no-require-imports, no-console */
const child = require("child_process");
const { exit } = require("process");
const fse = require("fs-extra");
const paths = {
macosBuild: "./macos/build",
extensionBuildDebug: "./macos/build/Debug/autofill-extension.appex",
extensionBuildReleaseAppStore: "./macos/build/ReleaseAppStore/autofill-extension.appex",
extensionBuildReleaseDeveloper: "./macos/build/ReleaseDeveloper/autofill-extension.appex",
extensionDistDir: "./macos/dist",
extensionDist: "./macos/dist/autofill-extension.appex",
macOsProject: "./macos/desktop.xcodeproj",
};
exports.default = buildMacOs;
async function buildMacOs() {
console.log("### Building Autofill Extension");
if (fse.existsSync(paths.macosBuild)) {
fse.removeSync(paths.macosBuild);
}
if (fse.existsSync(paths.extensionDistDir)) {
fse.removeSync(paths.extensionDistDir);
}
let configuration;
let codeSignIdentity;
let provisioningProfileSpecifier;
let buildDirectory;
const configurationArgument = process.argv[2];
if (configurationArgument !== undefined) {
// Use the configuration passed in to determine the configuration file.
if (configurationArgument == "mas-dev") {
configuration = "Debug";
codeSignIdentity = "Apple Development";
provisioningProfileSpecifier = "Bitwarden Desktop Autofill Development 2024";
buildDirectory = paths.extensionBuildDebug;
} else if (configurationArgument == "mas") {
configuration = "ReleaseAppStore";
codeSignIdentity = "3rd Party Mac Developer Application";
provisioningProfileSpecifier = "Bitwarden Desktop Autofill App Store 2024";
buildDirectory = paths.extensionBuildReleaseAppStore;
} else if (configurationArgument == "mac") {
configuration = "ReleaseDeveloper";
codeSignIdentity = "Developer ID Application";
provisioningProfileSpecifier = "Bitwarden Desktop Autofill Extension Developer Dis";
buildDirectory = paths.extensionBuildReleaseDeveloper;
} else {
console.log("### Unable to determine configuration, skipping Autofill Extension build");
return;
}
} else {
console.log("### No configuration argument found, skipping Autofill Extension build");
return;
}
const proc = child.spawn("xcodebuild", [
"-project",
paths.macOsProject,
"-alltargets",
"-configuration",
configuration,
"CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO",
"OTHER_CODE_SIGN_FLAGS='--timestamp'",
// While these arguments are defined in the `configuration` file above, xcodebuild has a bug in it currently that requires these arguments
// be explicitly defined in this call.
`CODE_SIGN_IDENTITY=${codeSignIdentity}`,
`PROVISIONING_PROFILE_SPECIFIER=${provisioningProfileSpecifier}`,
]);
stdOutProc(proc);
await new Promise((resolve, reject) =>
proc.on("close", (code) => {
if (code > 0) {
console.error("xcodebuild failed with code", code);
return reject(new Error(`xcodebuild failed with code ${code}`));
}
console.log("xcodebuild success");
resolve();
}),
);
fse.mkdirSync(paths.extensionDistDir);
fse.copySync(buildDirectory, paths.extensionDist);
// Delete the build dir, otherwise MacOS will load the extension from there instead of the Bitwarden.app bundle
fse.removeSync(paths.macosBuild);
}
function stdOutProc(proc) {
proc.stdout.on("data", (data) => console.log(data.toString()));
proc.stderr.on("data", (data) => console.error(data.toString()));
}
buildMacOs()
.then(() => console.log("macOS build complete"))
.catch((err) => {
console.error("macOS build failed", err);
exit(-1);
});