action-electron-builder

repository·master·Indexed 20 days ago

https://github.com/samuelmeuli/action-electron-builder

A GitHub Action for automating the building and releasing of Electron applications using electron-builder (v22+). It supports multi-platform builds for macOS, Windows, and Linux, and provides integrated handling for code signing, macOS notarization, and Snapcraft integration. The action automatically detects the package manager (NPM or Yarn) and can be configured to run custom build scripts, use the Vue CLI plugin, and publish releases to GitHub based on version tags.

Tokens
2K
Snippets
4
Records
10
Agent score
22%

What's inside action-electron-builder

  1. How to release your Electron app

    master

    The action automatically creates a GitHub Release draft when it detects a version tag. To trigger a release:

    1. Update the version in package.json (e.g., 1.2.3).
    2. Commit the change: git commit -am v1.2.3.
    3. Tag the commit using the v*.*.* format: git tag v1.2.3.
    4. Push both changes and tags: git push && git push --tags.

    The release option in the workflow configuration (e.g., release: ${{ startsWith(github.ref, 'refs/tags/v') }}) determines if the app should be released after building.

  2. Configure macOS code signing

    master

    To sign your macOS app, you must provide your certificates via GitHub Secrets:

    1. Export your certificates into a single .p12 file with a password.
    2. Base64-encode the file: base64 -i certs.p12 -o encoded.txt.
    3. Add mac_certs (the content of encoded.txt) and mac_certs_password to your GitHub repository secrets.
    4. Pass them to the action in your workflow.
    - name: Build/release Electron app
      uses: samuelmeuli/action-electron-builder@v1
      with:
        # ...
        mac_certs: ${{ secrets.mac_certs }}
        mac_certs_password: ${{ secrets.mac_certs_password }}
  3. Configure Snapcraft for Linux builds

    master

    If you are building for Snapcraft, use the action-snapcraft action before the action-electron-builder step to install and sign in.

    - name: Install Snapcraft
      uses: samuelmeuli/action-snapcraft@v1
      if: startsWith(matrix.os, 'ubuntu')
      with:
        snapcraft_token: ${{ secrets.snapcraft_token }}
  4. Configure macOS app notarization

    master

    If you use electron-builder for notarization, you can automate the process in GitHub Actions:

    1. Set Secrets: Add api_key (the .p8 file content), api_key_id, and api_key_issuer_id to your GitHub repository secrets.
    2. Prepare Key: Add a step before the build step to write the API key to the expected path.
    3. Pass Environment Variables: Provide the ID and Issuer ID to the action via env.
    - name: Prepare for app notarization
      if: startsWith(matrix.os, 'macos')
      run: |
        mkdir -p ~/private_keys/
        echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8
    
    - name: Build/release Electron app
      uses: samuelmeuli/action-electron-builder@v1
      with:
        # ...
      env:
        API_KEY_ID: ${{ secrets.api_key_id }}
        API_KEY_ISSUER_ID: ${{ secrets.api_key_issuer_id }}
  5. Setup the Electron Builder Action

    master

    To use this action, follow these three steps:

    1. Configure electron-builder: Ensure your Electron app has electron-builder (v22+) installed and configured.
    2. Prepare your build script: If you need to compile code (e.g., TypeScript or Sass), define a build script in your package.json. Important: This script must not run electron-builder, as the action handles that step.
    3. Add a GitHub Workflow: Create a workflow file (e.g., .github/workflows/build.yml) to run the action on a matrix of operating systems (macOS, Ubuntu, Windows).
    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') }}
  6. Configure action options

    master

    You can customize the behavior of the action-electron-builder using the following input parameters:

    OptionDefaultDescription
    package_root.Directory where NPM/Yarn commands are run
    build_script_namebuildName of the NPM build script to run before electron-builder
    skip_build(not specified)Whether to skip the NPM build script
    use_vue_cli(not specified)Whether to run electron-builder via the Vue CLI plugin
    args""Additional arguments passed to the electron-builder command
    max_attempts1Maximum number of attempts for the build and release step
  7. How the action determines the package manager

    master

    The action automatically detects whether to use npm or yarn based on the presence of a lockfile in the package_root:

    • If package-lock.json exists, the action uses NPM.
    • If package-lock.json is absent, the action uses Yarn.

    This detection affects the dependency installation step (npm install vs yarn) and the execution of the build command.

  8. Code signing for macOS and Windows

    master

    To sign your Electron application during the build process, you must provide certificate information via the following inputs. The action automatically exports these to the environment variables required by electron-builder (CSC_LINK and CSC_KEY_PASSWORD).

    PlatformInput for CertificateInput for Password
    macOSmac_certsmac_certs_password
    Windowswindows_certswindows_certs_password
  9. Configure the electron-builder GitHub Action inputs

    master

    The action-electron-builder GitHub Action uses several input variables to control the build and release process. These inputs are mapped to environment variables used by electron-builder and the underlying build scripts.

    Required Inputs

    • package_root: The directory containing your package.json.
    • build_script_name: The name of the script in package.json to run before building (e.g., build).
    • github_token: A GitHub token used for publishing releases. This is copied to the GH_TOKEN environment variable.

    Optional Inputs

    • release: Set to true to publish the app after building. This adds the --publish always flag to the electron-builder command.
    • skip_build: Set to true to skip running the specified build_script_name.
    • use_vue_cli: Set to true to use vue-cli-service electron:build instead of electron-builder.
    • args: Additional command-line arguments to pass to electron-builder.
    • max_attempts: The number of times to retry the build command if it fails (defaults to 1).
    • app_root: The directory where the build command is executed. Defaults to package_root. (Note: This option is deprecated in favor of package_root).
    • mac_certs: Base64 encoded macOS certificate (mapped to CSC_LINK).
    • mac_certs_password: Password for the macOS certificate (mapped to CSC_KEY_PASSWORD).
    • windows_certs: Base64 encoded Windows certificate (mapped to CSC_LINK).
    • windows_certs_password: Password for the Windows certificate (mapped to CSC_KEY_PASSWORD).