### Install and Sign in to Snapcraft for Electron Builder Source: https://github.com/samuelmeuli/action-electron-builder/blob/master/README.md This snippet demonstrates how to set up Snapcraft for building and releasing Linux applications using the `action-snapcraft` GitHub Action. It requires a `snapcraft_token` secret and is intended to be run before the `action-electron-builder` step, specifically on Ubuntu. ```yaml - name: Install Snapcraft uses: samuelmeuli/action-snapcraft@v1 # Only install Snapcraft on Ubuntu if: startsWith(matrix.os, 'ubuntu') with: # Log in to Snap Store snapcraft_token: "${{ secrets.snapcraft_token }}" ``` -------------------------------- ### Snapcraft Integration for Linux Builds with Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt This configuration enables publishing Linux Electron applications to the Snap Store. It first installs the Snapcraft action and then uses the Electron Builder action. A `snapcraft_token` obtained from the Snapcraft dashboard is required and should be stored as a repository secret. ```yaml - name: Install Snapcraft uses: samuelmeuli/action-snapcraft@v1 if: startsWith(matrix.os, 'ubuntu') with: snapcraft_token: ${{ secrets.snapcraft_token }} - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} ``` -------------------------------- ### Basic GitHub Action Workflow Configuration for Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt This snippet demonstrates the fundamental setup for the Electron Builder action within a GitHub Actions workflow. It checks out the repository, sets up Node.js, and then uses the action to build and release the Electron app. The build is triggered on every push, and releases occur when a version tag is pushed. ```yaml name: Build/release on: push jobs: release: runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] steps: - name: Check out Git repository uses: actions/checkout@v1 - name: Install Node.js, NPM and Yarn uses: actions/setup-node@v1 with: node-version: 10 - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} ``` -------------------------------- ### Orchestrate Build and Release: runAction (JavaScript) Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt The main entry point function that orchestrates the entire build and release process. It handles input parsing, dependency installation, build execution, and release publishing. It relies on other helper functions like `getPlatform`, `getInput`, `setEnv`, and `run`. It retries the build process up to `maxAttempts`. ```javascript const { execSync } = require("child_process"); const { existsSync, readFileSync } = require("fs"); const { join } = require("path"); const runAction = () => { const platform = getPlatform(); const release = getInput("release", true) === "true"; const pkgRoot = getInput("package_root", true); const buildScriptName = getInput("build_script_name", true); const skipBuild = getInput("skip_build") === "true"; const useVueCli = getInput("use_vue_cli") === "true"; const args = getInput("args") || ""; const maxAttempts = Number(getInput("max_attempts") || "1"); const pkgJsonPath = join(pkgRoot, "package.json"); const pkgLockPath = join(pkgRoot, "package-lock.json"); const useNpm = existsSync(pkgLockPath); if (!existsSync(pkgJsonPath)) { exit(``package.json` file not found at path "${pkgJsonPath}"`); } setEnv("GH_TOKEN", getInput("github_token", true)); if (platform === "mac") { setEnv("CSC_LINK", getInput("mac_certs")); setEnv("CSC_KEY_PASSWORD", getInput("mac_certs_password")); } else if (platform === "windows") { setEnv("CSC_LINK", getInput("windows_certs")); setEnv("CSC_KEY_PASSWORD", getInput("windows_certs_password")); } setEnv("ADBLOCK", true); run(useNpm ? "npm install" : "yarn", pkgRoot); if (!skipBuild) { if (useNpm) { run(`npm run ${buildScriptName} --if-present`, pkgRoot); } else { const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8")); if (pkgJson.scripts && pkgJson.scripts[buildScriptName]) { run(`yarn run ${buildScriptName}`, pkgRoot); } } } const cmd = useVueCli ? "vue-cli-service electron:build" : "electron-builder"; for (let i = 0; i < maxAttempts; i += 1) { try { run( `${useNpm ? "npx --no-install" : "yarn run"} ${cmd} --${platform} ${ release ? "--publish always" : "" } ${args}`, appRoot, ); break; } catch (err) { if (i < maxAttempts - 1) { log(`Attempt ${i + 1} failed:`); log(err); } else { throw err; } } } }; ``` -------------------------------- ### Prepare for macOS App Notarization with Electron Builder Source: https://github.com/samuelmeuli/action-electron-builder/blob/master/README.md This snippet shows the steps to prepare for macOS app notarization using GitHub Actions. It involves creating a private key file from GitHub secrets (`api_key`, `api_key_id`) and setting environment variables for `action-electron-builder`. ```yaml - name: Prepare for app notarization if: startsWith(matrix.os, 'macos') # Import Apple API key for app notarization on macOS run: | mkdir -p ~/private_keys/ echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8 ``` ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: # ... env: # macOS notarization API key API_KEY_ID: "${{ secrets.api_key_id }}" API_KEY_ISSUER_ID: "${{ secrets.api_key_issuer_id }}" ``` -------------------------------- ### GitHub Workflow for Building/Releasing Electron App Source: https://github.com/samuelmeuli/action-electron-builder/blob/master/README.md This YAML configuration sets up a GitHub Actions workflow to build and optionally release an Electron application. It runs on multiple operating systems, checks out the repository, sets up Node.js, and uses the electron-builder action. The release process is triggered by Git tags. ```yaml name: Build/release on: push jobs: release: runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] steps: - name: Check out Git repository uses: actions/checkout@v1 - name: Install Node.js, NPM and Yarn uses: actions/setup-node@v1 with: node-version: 10 - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: # GitHub token, automatically provided to the action # (No need to define this secret in the repo settings) github_token: ${{ secrets.github_token }} # If the commit is tagged with a version (e.g. "v1.0.0"), # release the app after building release: ${{ startsWith(github.ref, 'refs/tags/v') }} ``` -------------------------------- ### Complete Multi-Platform Release Workflow with Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt A full production-ready workflow combining code signing, notarization, and Snapcraft integration for all three major platforms (macOS, Ubuntu, Windows). It includes proper secret management and conditional execution for a robust release process. ```yaml name: Build/release on: push: branches: - main tags: - 'v*' jobs: release: runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] steps: - name: Check out Git repository uses: actions/checkout@v1 - name: Install Node.js, NPM and Yarn uses: actions/setup-node@v1 with: node-version: 14 - name: Prepare for app notarization (macOS) if: startsWith(matrix.os, 'macos') run: | mkdir -p ~/private_keys/ echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8 - name: Install Snapcraft (Linux) uses: samuelmeuli/action-snapcraft@v1 if: startsWith(matrix.os, 'ubuntu') with: snapcraft_token: ${{ secrets.snapcraft_token }} - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} mac_certs: ${{ secrets.mac_certs }} mac_certs_password: ${{ secrets.mac_certs_password }} windows_certs: ${{ secrets.windows_certs }} windows_certs_password: ${{ secrets.windows_certs_password }} max_attempts: "2" env: API_KEY_ID: ${{ secrets.api_key_id }} API_KEY_ISSUER_ID: ${{ secrets.api_key_issuer_id }} ``` -------------------------------- ### Configure Windows Code Signing for Electron Builder Source: https://github.com/samuelmeuli/action-electron-builder/blob/master/README.md This snippet illustrates how to configure the action-electron-builder for Windows code signing. It requires the Windows certificates and their password to be stored as GitHub secrets named `windows_certs` and `windows_certs_password`. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: # ... windows_certs: "${{ secrets.windows_certs }}" windows_certs_password: "${{ secrets.windows_certs_password }}" ``` -------------------------------- ### Configure macOS Code Signing for Electron Builder Source: https://github.com/samuelmeuli/action-electron-builder/blob/master/README.md This snippet shows how to configure the action-electron-builder to use code signing certificates for macOS applications. It requires base64-encoded certificates and their password to be stored as GitHub secrets. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: # ... mac_certs: "${{ secrets.mac_certs }}" mac_certs_password: "${{ secrets.mac_certs_password }}" ``` -------------------------------- ### Windows Code Signing Configuration for Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt This snippet configures Windows code signing for Electron applications. It utilizes base64-encoded certificate files and passwords stored as repository secrets to sign Windows executables using authenticode. This ensures the integrity and authenticity of the Windows build. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} windows_certs: ${{ secrets.windows_certs }} windows_certs_password: ${{ secrets.windows_certs_password }} ``` -------------------------------- ### Detect Operating System: getPlatform (JavaScript) Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Determines the current operating system and returns a normalized platform identifier compatible with electron-builder's platform flags. It maps Node.js's `process.platform` values to simpler strings like 'mac', 'windows', or 'linux'. ```javascript const getPlatform = () => { switch (process.platform) { case "darwin": return "mac"; case "win32": return "windows"; default: return "linux"; } }; // Usage example const currentPlatform = getPlatform(); console.log(currentPlatform); // Output: "mac", "windows", or "linux" ``` -------------------------------- ### Retrieve GitHub Actions Input: getInput (JavaScript) Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Retrieves GitHub Actions input variables from environment variables, with optional validation for required inputs. It prefixes the input name with `INPUT_` and converts it to uppercase to access the corresponding environment variable. If a required input is missing, it exits the process. ```javascript const getInput = (name, required) => { const value = getEnv(`INPUT_${name}`); if (required && !value) { exit(`"${name}" input variable is not defined`); } return value; }; // Usage examples const githubToken = getInput("github_token", true); // Required const maxAttempts = getInput("max_attempts", false); // Optional const skipBuild = getInput("skip_build") === "true"; // Boolean parsing ``` -------------------------------- ### macOS Code Signing Configuration for Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt This configuration enables automatic code signing for macOS builds. It requires base64-encoded certificate files and their corresponding passwords to be provided as GitHub repository secrets. This is crucial for distributing macOS applications outside the Mac App Store. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} mac_certs: ${{ secrets.mac_certs }} mac_certs_password: ${{ secrets.mac_certs_password }} ``` -------------------------------- ### Execute Shell Commands: run (JavaScript) Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Executes shell commands synchronously with output streamed to the console in real-time. It uses `child_process.execSync` and ensures that the output is inherited and displayed immediately. The `cwd` option allows specifying the current working directory for the command. ```javascript const run = (cmd, cwd) => execSync(cmd, { encoding: "utf8", stdio: "inherit", cwd }); // Usage examples run("npm install", "/path/to/package/root"); run("yarn run build", "/path/to/app"); run("npx electron-builder --mac --publish always", "/path/to/app"); ``` -------------------------------- ### Custom Package Root Directory for Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt This configuration allows specifying a custom directory for the `package.json` file and for executing NPM/Yarn commands. This is particularly useful for monorepos or projects where the Electron application is nested within a subdirectory. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} package_root: "./packages/electron-app" ``` -------------------------------- ### Vue CLI Plugin Support for Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Enables building through the Vue CLI Electron Builder plugin instead of calling electron-builder directly. This executes 'vue-cli-service electron:build' instead of the standard electron-builder command. It's useful for projects already configured with Vue CLI. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} use_vue_cli: true ``` -------------------------------- ### Skip Build Script Execution with Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Bypasses the execution of the NPM build script before running electron-builder. This is useful when the build has already been completed in a previous step or when no build step is needed. It configures the action to skip the build process. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} skip_build: true ``` -------------------------------- ### Retry Mechanism for Unreliable Builds with Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Configures multiple build attempts to handle transient failures in network-dependent operations or flaky build processes. Each attempt is logged separately, providing resilience for CI/CD pipelines. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} max_attempts: "3" ``` -------------------------------- ### Pass Custom Arguments to Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Passes custom arguments to the electron-builder command for configuration overrides or additional options not covered by the action's inputs. This provides granular control over the build process. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} args: "--config.productName='MyApp' --config.appId=com.example.myapp" ``` -------------------------------- ### Custom Build Script Name for Electron Builder Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Overrides the default 'build' script name to execute a different NPM script before running electron-builder. The action checks if the specified script exists before attempting to run it. This allows for flexibility in naming build scripts. ```yaml - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: github_token: ${{ secrets.github_token }} release: ${{ startsWith(github.ref, 'refs/tags/v') }} build_script_name: "compile" ``` -------------------------------- ### Set Environment Variables: setEnv (JavaScript) Source: https://context7.com/samuelmeuli/action-electron-builder/llms.txt Sets environment variables with automatic uppercase conversion, only when values are provided. This is used for configuring electron-builder's required environment variables, such as authentication tokens or certificates. Values are converted to strings. ```javascript const setEnv = (name, value) => { if (value) { process.env[name.toUpperCase()] = value.toString(); } }; // Usage examples setEnv("GH_TOKEN", getInput("github_token", true)); setEnv("CSC_LINK", getInput("mac_certs")); // Only sets if mac_certs provided setEnv("CSC_KEY_PASSWORD", getInput("mac_certs_password")); setEnv("ADBLOCK", true); // Disables npm advertisements ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.