tauri-apps / tauri-action

Build your Web application as a Tauri binary for macOS, Linux and Windows
https://tauri.app
MIT License
918 stars 149 forks source link

retry arg #900

Open louis030195 opened 1 month ago

louis030195 commented 1 month ago

keep having failed build that seem non deterministic

https://github.com/mediar-ai/screenpipe/actions/workflows/release-app.yml

usually:

having a way to retry would save me probably at least 1h a week because i release 3 version a day on average

louis030195 commented 4 days ago

failed to notarize on macos also, usually retry and it works

this feature would save me so much time

louis030195 commented 4 days ago

Here's a suggested change using the diff markdown syntax for adding a retry argument to the tauri-action:

diff --git a/src/index.ts b/src/index.ts
index 1234567..abcdef0 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -24,6 +24,7 @@ async function run(): Promise<void> {
     const includeDebug = core.getBooleanInput('includeDebug');
     const includeUpdaterJson = core.getBooleanInput('includeUpdaterJson');
     const updaterJsonKeepUniversal = core.getBooleanInput('updaterJsonKeepUniversal');
+    const retryAttempts = parseInt(core.getInput('retryAttempts') || '1', 10);
     const tauriScript = core.getInput('tauriScript');
     const args = stringArgv(core.getInput('args'));
     const bundleIdentifier = core.getInput('bundleIdentifier');
@@ -76,14 +77,22 @@ async function run(): Promise<void> {
     const releaseArtifacts: Artifact[] = [];
     const debugArtifacts: Artifact[] = [];
     if (includeRelease) {
-      releaseArtifacts.push(
-        ...(await buildProject(projectPath, false, buildOptions, initOptions)),
-      );
+      for (let attempt = 1; attempt <= retryAttempts; attempt++) {
+        try {
+          releaseArtifacts.push(
+            ...(await buildProject(projectPath, false, buildOptions, initOptions)),
+          );
+          break;
+        } catch (error) {
+          if (attempt === retryAttempts) throw error;
+          console.log(`Build attempt ${attempt} failed, retrying...`);
+        }
+      }
     }
     if (includeDebug) {
-      debugArtifacts.push(
-        ...(await buildProject(projectPath, true, buildOptions, initOptions)),
-      );
+      // Similar retry logic for debug build
+      // ...
+    }
     const artifacts = releaseArtifacts.concat(debugArtifacts);

     if (artifacts.length === 0) {

This change introduces a new retryAttempts input parameter and implements a retry mechanism for the build process. It will attempt to build the project up to the specified number of times before giving up.

To use this new feature, you would add a new input to your GitHub Action workflow:

- uses: tauri-apps/tauri-action@v0
  with:
    # ... other inputs ...
    retryAttempts: 3

This would allow the build to retry up to 3 times if it fails.