tauri-action

repository·dev·Indexed 23 days ago

https://github.com/tauri-apps/tauri-action

A specialized GitHub Action designed to automate the building and releasing of Tauri applications across macOS, Linux, and Windows. It handles the Tauri CLI build process, identifies platform-specific artifacts (such as .dmg, .msi, .deb, and .AppImage), and can optionally upload these bundles and updater JSON files to a GitHub Release.

Tokens
5.8K
Snippets
5
Records
29
Agent score
82%

What's inside tauri-action

  1. Manage GitHub Release uploads with `releaseId`, `tagName`, and `releaseName`

    dev

    The action uses these inputs to determine where to upload build artifacts:

    • releaseId: The specific ID of an existing release. If set, tagName and releaseName are ignored.
    • tagName: The tag name of the release to upload to or create. If this points to an existing release, the releaseDraft setting must match that release's status.
    • releaseName: Required to create a new release if tagName does not point to an existing one.

    Important Behaviors:

    • Build only (no upload): To build the app without uploading assets to a GitHub release (e.g., if you prefer using actions/upload-artifact), omit tagName, releaseName, and releaseId.
    • Updater URL behavior: If you provide a releaseId but omit tagName, the latest.json file (used by Tauri's updater) will point to releases/latest/download/<bundle>. Ensure your releases include updater bundles if using this method.
  2. Quickstart: Build and release Tauri apps with GitHub Actions

    dev

    The tauri-action automates building your Tauri application for macOS, Linux, and Windows, and can optionally upload the resulting bundles to a GitHub Release.

    Common use cases include:

    1. Testing the build pipeline.
    2. Uploading artifacts to an existing release.
    3. Creating a new release with Tauri artifacts.

    To use the action, you must provide a GITHUB_TOKEN in the env section of your workflow step.

    name: 'publish'
    
    on:
      push:
        branches:
          - release
    
    jobs:
      publish-tauri:
        permissions:
          contents: write
        strategy:
          fail-fast: false
          matrix:
            include:
              - platform: 'macos-latest'
                args: '--target aarch64-apple-darwin'
              - platform: 'macos-latest'
                args: '--target x86_64-apple-darwin'
              - platform: 'ubuntu-22.04'
                args: ''
              - platform: 'windows-latest'
                args: ''
    
        runs-on: ${{ matrix.platform }}
        steps:
          - uses: actions/checkout@v4
    
          - name: setup node
            uses: actions/setup-node@v4
            with:
              node-version: lts/*
    
          - name: install Rust stable
            uses: dtolnay/rust-toolchain@stable
            with:
              targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
    
          - name: install dependencies (ubuntu only)
            if: matrix.platform == 'ubuntu-22.04'
            run: |
              sudo apt-get update
              sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xdg-utils
    
          - name: install frontend dependencies
            run: yarn install
    
          - uses: tauri-apps/tauri-action@v1
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
            with:
              tagName: app-v__VERSION__
              releaseName: 'App v__VERSION__'
              releaseBody: 'See the assets to download this version and install.'
              releaseDraft: true
              prerelease: false
              args: ${{ matrix.args }}
  3. Configure `projectPath` for non-root Tauri apps

    dev

    If your Tauri application is not located in the root directory of your repository, you must use the projectPath input.

    Why this is necessary:

    • Without it, the action may use a global @tauri-apps/cli installation instead of your project's local CLI, which can cause conflicts with tauriScript or multiple tauri.conf.json files.
    • It ensures that relative paths provided via the --config flag are resolved correctly relative to the project directory.

    Requirement: The path provided to projectPath must NOT be gitignored.

  4. How the Tauri build process works

    dev

    The buildProject function automates the Tauri CLI build process and identifies the resulting platform-specific artifacts.

    1. Execution: It executes the tauri build command (or tauri android build / tauri ios build for mobile platforms) using the project's configuration.
    2. Artifact Discovery: After the build completes, it calculates the expected file paths for various bundles (e.g., .dmg, .msi, .deb, .apk, .ipa) based on the target platform, architecture, and build profile (debug or release).
    3. Validation: It returns a list of Artifact objects only for files that actually exist on the filesystem.
  5. Differentiate binaries using `[setup]`

    dev
    When using uploadPlainBinary, you can use the [setup] prefix to differentiate between different file types that share the same extension (e.g., distinguishing between an NSIS installer and a plain binary, both of which end in .exe).
  6. Use `uploadPlainBinary` for standalone binaries

    dev

    The uploadPlainBinary option allows uploading plain binaries.

    Warning: Use this with caution. Tauri does not officially support a portable mode, and standalone binaries for GUI applications are generally not supported on platforms other than Windows.

  7. Configure tauri-action with with-parameters

    dev

    The tauri-action accepts several configuration options via the with key in your GitHub Actions workflow.

    Release Identification

    • releaseId: The ID of the release to upload artifacts to. If set, tagName and releaseName are ignored.
    • tagName: The tag name of the release to upload/create (or the tag belonging to releaseId).
    • releaseName: The name of the release to create (required if releaseId and tagName are not used to find an existing release).
    • releaseCommitish: The branch or commit SHA the Git tag is created from.

    Release Content

    • releaseBody: The body of the release.
    • releaseDraft: Whether the release is a draft (default: false).
    • prerelease: Whether the release is a prerelease (default: false).
    • generateReleaseNotes: Uses GitHub's Release Notes API to generate title/body (default: false).

    Repository & API

    • owner: The account owner of the repository.
    • repo: The name of the repository.
    • githubBaseUrl: Base URL for the GitHub API (useful for Enterprise/self-hosted). Defaults to $GITHUB_API_URL or https://api.github.com.

    Build & Path Configuration

    • projectPath: Path to the root of the Tauri project (default: ./).
    • tauriScript: The script to execute the Tauri CLI (e.g., npm tauri or yarn tauri).
    • args: Additional arguments passed to the Tauri build command.
    • retryAttempts: Number of retries for build/upload failures (default: 0).

    Artifact & Updater Settings

    • uploadUpdaterJson: Whether to upload a JSON file for the Tauri updater (default: true).
    • updaterJsonPreferNsis: Whether to prefer NSIS bundles for the updater JSON (default: false).
    • uploadUpdaterSignatures: Whether to upload .sig files (default: true).
    • releaseAssetNamePattern: Naming pattern for uploaded assets using variables like [name], [version], [platform], [arch], [ext], etc.
    • uploadPlainBinary: Upload unbundled executable (Tauri v2+ only, requires --no-bundle flag).
    • uploadWorkflowArtifacts: Upload bundles as GitHub workflow artifacts (default: false).
    • workflowArtifactNamePattern: Naming pattern for workflow artifacts (default: [platform]-[arch]-[bundle]).

    Mobile (Experimental)

    • mobile: Set to android or ios to change the build command to android build or ios build. Note that you must manage system dependencies (Xcode, SDKs) manually.
  8. How the `latest.json` updater file is generated

    dev

    The latest.json file is a critical component for Tauri's auto-updater. It is a JSON file uploaded to your GitHub release that maps platform identifiers (like darwin-aarch64 or windows-x64-msi) to the download URL and the cryptographic signature of the corresponding installer.

    Key behaviors:

    • Platform Mapping: It uses a combination of OS and architecture (e.g., darwin-x86_64, linux-aarch64).
    • Signature Requirement: The action looks for .sig files matching your artifacts. If no signature files are found, the latest.json upload is skipped.
    • Universal macOS Builds: For macOS universal binaries, the action intelligently maps them to both darwin-aarch64 and darwin-x86_64 entries in the JSON to ensure compatibility across different Mac hardware.
    • Signature Priority: When multiple signatures exist, the action uses a priority system (influenced by the updaterJsonPreferNsis setting) to select the most appropriate signature for the updater JSON.
    • Asset Replacement: If a latest.json already exists in the release, the action deletes the old version and uploads the newly generated one to ensure the metadata is always up-to-date with the current release artifacts.
  9. Configure custom Tauri CLI scripts with `tauriScript`

    dev

    Use the tauriScript option to specify how the Tauri CLI should be invoked. Instead of the default command, the action executes ${tauriScript} <COMMAND> <ARGS>.

    This is useful if:

    • You have custom build scripts (e.g., desktop:build).
    • You use cargo install tauri-cli instead of a package manager.
    • You want to point to an absolute file path of a tauri-cli binary (note: the path must not contain spaces).