Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retry #900 #964

Merged
merged 24 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/retry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
action: patch
---

Add retry mechanism for failed builds to improve CI reliability
6 changes: 3 additions & 3 deletions .github/fixtures/example-with-tauri-v2/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
1 change: 1 addition & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ jobs:
releaseDraft: true
args: ${{ matrix.args }}
updaterJsonKeepUniversal: true
retryAttempts: 1

- name: Frontend-only Project
uses: ./
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,17 @@ These inputs are only used if your GitHub repository does not contain an existin

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 |
| `updaterJsonPreferNsis` | false | whether the action will use the NSIS (setup.exe) or WiX (.msi) bundles for the updater JSON if both types exist | bool | `false`. May be changed to `true` for projects using `tauri@v2` in the future. |
| `updaterJsonKeepUniversal` | false | whether the updater JSON file should include universal macOS builds as darwin-universal on top of using it 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 | |
| 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 |
| `updaterJsonPreferNsis` | false | whether the action will use the NSIS (setup.exe) or WiX (.msi) bundles for the updater JSON if both types exist | bool | `false`. May be changed to `true` for projects using `tauri@v2` in the future. |
| `updaterJsonKeepUniversal` | false | whether the updater JSON file should include universal macOS builds as darwin-universal on top of using it 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 | |
| `retryAttempts` | false | The number of times to re-try building the app if the initial build fails. For now this only affects `tauri build` but may include the upload steps in the future. | number | 0 |

### Release Configuration

Expand Down
40 changes: 21 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,45 @@ inputs:
description: 'The body of the release to create'
releaseDraft:
description: 'Whether the release to create is a draft or not'
default: false
default: 'false'
prerelease:
description: 'Whether the release to create is a prerelease or not'
default: false
default: 'false'
releaseCommitish:
description: 'Any branch or commit SHA the Git tag is created from, unused if the Git tag already exists. Default: SHA of current commit'
projectPath:
description: 'path to the root of the project that will be built'
description: 'Path to the root of the project that will be built'
default: '.'
distPath:
description: 'path to the distributable folder with your index.html and JS/CSS'
description: 'Path to the distributable folder with your index.html and JS/CSS'
iconPath:
description: 'path to the PNG icon to use as app icon, relative to the projectPath'
description: 'Path to the PNG icon to use as app icon, relative to the projectPath'
appName:
description: 'the app name to inject when initializing the Tauri app. Required if the name is not set via the `--config` flag.'
description: 'The app name to inject when initializing the Tauri app. Required if the name is not set via the `--config` flag.'
appVersion:
description: 'the app version to inject when initializing the Tauri app. Required if the version is not set via the `--config` flag.'
description: 'The app version to inject when initializing the Tauri app. Required if the version is not set via the `--config` flag.'
includeDebug:
description: 'whether to include a debug build or not'
default: false
description: 'Whether to include a debug build or not'
default: 'false'
includeRelease:
description: 'whether to include a release build or not'
default: true
description: 'Whether to include a release build or not'
default: 'true'
includeUpdaterJson:
description: 'whether to upload a static JSON file for the updater using GitHub Releases as the CDN'
default: true
description: 'Whether to upload a static JSON file for the updater using GitHub Releases as the CDN'
default: 'true'
updaterJsonPreferNsis:
description: 'whether the action will use the NSIS (setup.exe) or WiX (.msi) bundles for the updater JSON if both types exist. Will default to false. May default to true for apps using tauri@v2 in the future.'
description: 'Whether the action will use the NSIS (setup.exe) or WiX (.msi) bundles for the updater JSON if both types exist. Will default to false. May default to true for apps using tauri@v2 in the future.'
updaterJsonKeepUniversal:
description: 'whether the updater JSON file should add universal macOS as darwin-universal on top of using it in the darwin-aarch64 and darwin-x86_64 fields if no native builds exist.'
default: false
description: 'Whether the updater JSON file should add universal macOS as darwin-universal on top of using it in the darwin-aarch64 and darwin-x86_64 fields if no native builds exist.'
default: 'false'
tauriScript:
description: 'the script to run to build the Tauri app'
description: 'The script to run to build the Tauri app'
args:
description: 'arguments for the tauri command'
description: 'Arguments for the `tauri build` command'
retryAttempts:
description: 'The number of times to re-try building the app if the initial build fails. For now this only affects `tauri build` but may include the upload steps in the future.'
bundleIdentifier:
description: 'the bundle identifier to inject when initializing the Tauri app'
description: 'The bundle identifier to inject when initializing the Tauri app'
owner:
description: 'The account owner of the repository'
repo:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@actions/core": "1.11.1",
"@actions/github": "6.0.0",
"@iarna/toml": "2.2.5",
"execa": "9.5.1",
"execa": "^9.5.2",
"globby": "14.0.2",
"json5": "2.2.3",
"string-argv": "0.3.2",
Expand Down
34 changes: 18 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function buildProject(
debug: boolean,
buildOpts: BuildOptions,
initOpts: InitOptions,
retryAttempts: number,
): Promise<Artifact[]> {
const runner = await getRunner(root, buildOpts.tauriScript);

Expand Down Expand Up @@ -73,6 +74,7 @@ export async function buildProject(
process.env.TAURI_BUNDLER_DMG_IGNORE_CI ?? 'true',
}
: undefined,
retryAttempts,
);

// on Linux, the app product name is converted to kebab-case and `()[]{}` will be removed
Expand Down
20 changes: 17 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function run(): Promise<void> {
const updaterJsonKeepUniversal = core.getBooleanInput(
'updaterJsonKeepUniversal',
);
const retryAttempts = parseInt(core.getInput('retryAttempts') || '0', 10);
const tauriScript = core.getInput('tauriScript');
const args = stringArgv(core.getInput('args'));
const bundleIdentifier = core.getInput('bundleIdentifier');
Expand Down Expand Up @@ -84,14 +85,27 @@ async function run(): Promise<void> {

const releaseArtifacts: Artifact[] = [];
const debugArtifacts: Artifact[] = [];

if (includeRelease) {
releaseArtifacts.push(
...(await buildProject(projectPath, false, buildOptions, initOptions)),
...(await buildProject(
projectPath,
false,
buildOptions,
initOptions,
retryAttempts,
)),
);
}
if (includeDebug) {
debugArtifacts.push(
...(await buildProject(projectPath, true, buildOptions, initOptions)),
...(await buildProject(
projectPath,
true,
buildOptions,
initOptions,
retryAttempts,
)),
);
}
const artifacts = releaseArtifacts.concat(debugArtifacts);
Expand All @@ -117,7 +131,7 @@ async function run(): Promise<void> {
const info = getInfo(projectPath, targetInfo, configArg);
core.setOutput('appVersion', info.version);

// Other steps may benfit from this so we do this whether or not we want to upload it.
// Other steps may benefit from this so we do this whether or not we want to upload it.
if (targetInfo.platform === 'macos') {
let i = 0;
for (const artifact of artifacts) {
Expand Down
7 changes: 6 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
execCommand,
getTauriDir,
hasDependency,
retry,
usesBun,
usesPnpm,
usesYarn,
Expand All @@ -24,6 +25,7 @@ class Runner {
commandOptions: string[],
cwd?: string,
env?: Record<string, string>,
retryAttempts: number = 0,
): Promise<void> {
const args: string[] = [];

Expand All @@ -41,7 +43,10 @@ class Runner {

args.push(...commandOptions);

return execCommand(this.bin, args, { cwd }, env);
return retry(
() => execCommand(this.bin, args, { cwd }, env),
retryAttempts + 1,
) as Promise<void>;
}
}

Expand Down
Loading
Loading