Skip to content

Commit

Permalink
feat: Handle universal macos in updater json, closes #444 (#447)
Browse files Browse the repository at this point in the history
* remove unused imports

* feat: Handle universal macos in updater json

* readme
  • Loading branch information
FabianLars committed May 3, 2023
1 parent 240732d commit 91a6560
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changes/macos-universal-target.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'action': patch
---

Correctly handle universal macOS builds in the updater JSON file. Unless disabled it will add the universal builds to the darwin-aarch64 and darwin-x86_64 fields instead of darwin-universal. It will always prefer native targets for the respective fields if they exist.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ These inputs are _typically_ only used if your GitHub repo does not contain an e

These inputs allow you to change how your Tauri project will be build.

| Name | Required | Description | Type | Default |
| -------------------- | :------: | ------------------------------------------------------------------------------------------------- | ------ | --------------------------- |
| `projectPath` | false | The path to the root of the tauri project relative to the current working directory | string | . |
| `includeDebug` | false | whether to include a debug build or not | bool | false |
| `includeRelease` | false | whether to include a release build or not | bool | true |
| `includeUpdaterJson` | false | whether to upload a JSON file for the updater or not (only relevant if the updater is configured) | bool | true |
| `tauriScript` | false | the script to execute the Tauri CLI. It must not include any args or commands like `build` | string | `npm run\|pnpm\|yarn tauri` |
| `args` | false | Additional arguments to the current build command | string | |
| Name | Required | Description | Type | Default |
| -------------------------- | :------: | ---------------------------------------------------------------------------------------------------------------------------- | ------ | --------------------------- |
| `projectPath` | false | The path to the root of the tauri project relative to the current working directory | string | . |
| `includeDebug` | false | whether to include a debug build or not | bool | false |
| `includeRelease` | false | whether to include a release build or not | bool | true |
| `includeUpdaterJson` | false | whether to upload a JSON file for the updater or not (only relevant if the updater is configured) | bool | true |
| `updaterJsonKeepUniversal` | false | whether the updater JSON file should include universal macOS builds as darwin-universal or in the aarch64 and x86_64 fields. | bool | false |
| `tauriScript` | false | the script to execute the Tauri CLI. It must not include any args or commands like `build` | string | `npm run\|pnpm\|yarn tauri` |
| `args` | false | Additional arguments to the current build command | string | |

### Release Configuration

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ inputs:
includeUpdaterJson:
description: 'whether to upload a static JSON file for the updater using GitHub Releases as the CDN'
default: true
updaterJsonKeepUniversal:
description: 'whether the updater JSON file should add universal macOS as darwin-universal. By default it will add darwin-aarch64 and darwin-x86_64 fields pointing to the universal build if no native builds exist.'
default: false
tauriScript:
description: 'the script to run to build the Tauri app'
args:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, existsSync, copyFileSync, writeFileSync } from 'fs';
import { existsSync } from 'fs';
import { join } from 'path';

import { initProject } from './init-project';
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { existsSync } from 'fs';
import { platform } from 'os';
import { join, resolve, dirname, basename } from 'path';
import { resolve, dirname, basename } from 'path';

import * as core from '@actions/core';
import stringArgv from 'string-argv';
Expand All @@ -24,6 +23,9 @@ async function run(): Promise<void> {
const includeRelease = core.getBooleanInput('includeRelease');
const includeDebug = core.getBooleanInput('includeDebug');
const includeUpdaterJson = core.getBooleanInput('includeUpdaterJson');
const updaterJsonKeepUniversal = core.getBooleanInput(
'updaterJsonKeepUniversal'
);
const tauriScript = core.getInput('tauriScript');
const args = stringArgv(core.getInput('args'));
const bundleIdentifier = core.getInput('bundleIdentifier');
Expand Down Expand Up @@ -153,6 +155,7 @@ async function run(): Promise<void> {
releaseId,
artifacts,
targetInfo,
updaterJsonKeepUniversal,
});
}
}
Expand Down
29 changes: 23 additions & 6 deletions src/upload-version-json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync, writeFileSync } from 'fs';
import { platform } from 'os';
import { resolve } from 'path';

import { getOctokit, context } from '@actions/github';
Expand Down Expand Up @@ -30,13 +29,15 @@ export async function uploadVersionJSON({
releaseId,
artifacts,
targetInfo,
updaterJsonKeepUniversal,
}: {
version: string;
notes: string;
tagName: string;
releaseId: number;
artifacts: Artifact[];
targetInfo: TargetInfo;
updaterJsonKeepUniversal: boolean;
}) {
if (process.env.GITHUB_TOKEN === undefined) {
throw new Error('GITHUB_TOKEN is required');
Expand Down Expand Up @@ -115,11 +116,27 @@ export async function uploadVersionJSON({
? 'aarch64'
: arch;

// https://github.com/tauri-apps/tauri/blob/fd125f76d768099dc3d4b2d4114349ffc31ffac9/core/tauri/src/updater/core.rs#L856
(versionContent.platforms[`${os}-${arch}`] as unknown) = {
signature: readFileSync(sigFile.path).toString(),
url: downloadUrl,
};
// Expected targets: https://github.com/tauri-apps/tauri/blob/fd125f76d768099dc3d4b2d4114349ffc31ffac9/core/tauri/src/updater/core.rs#L856
if (!updaterJsonKeepUniversal && os === 'darwin' && arch === 'universal') {
// Don't overwrite native builds
if (!versionContent.platforms['darwin-aarch64']) {
(versionContent.platforms['darwin-aarch64'] as unknown) = {
signature: readFileSync(sigFile.path).toString(),
url: downloadUrl,
};
}
if (!versionContent.platforms['darwin-x86_64']) {
(versionContent.platforms['darwin-x86_64'] as unknown) = {
signature: readFileSync(sigFile.path).toString(),
url: downloadUrl,
};
}
} else {
(versionContent.platforms[`${os}-${arch}`] as unknown) = {
signature: readFileSync(sigFile.path).toString(),
url: downloadUrl,
};
}

writeFileSync(versionFile, JSON.stringify(versionContent, null, 2));

Expand Down

0 comments on commit 91a6560

Please sign in to comment.