Skip to content

Commit 5666b68

Browse files
Prithvi ShivaramanFabianLars
andauthored
feat: Retry Upload Step (#1030)
Co-authored-by: Fabian-Lars <github@fabianlars.de>
1 parent abaf88e commit 5666b68

6 files changed

Lines changed: 63 additions & 52 deletions

File tree

.changes/retry-upload.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
action: patch
3+
---
4+
5+
`retryAttempts` is now also applied to uploads.

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ inputs:
5151
args:
5252
description: 'Arguments for the `tauri build` command'
5353
retryAttempts:
54-
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.'
54+
description: 'The number of times to re-try building the app if the initial build fails or uploading assets if the upload fails.'
5555
bundleIdentifier:
5656
description: 'The bundle identifier to inject when initializing the Tauri app'
5757
owner:

dist/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,29 @@ async function run(): Promise<void> {
186186
}
187187

188188
if (releaseId) {
189-
await uploadReleaseAssets(owner, repo, releaseId, artifacts);
189+
await uploadReleaseAssets(
190+
owner,
191+
repo,
192+
releaseId,
193+
artifacts,
194+
retryAttempts,
195+
);
190196

191197
if (includeUpdaterJson) {
192-
await uploadVersionJSON({
198+
await uploadVersionJSON(
193199
owner,
194200
repo,
195-
version: info.version,
196-
notes: body,
201+
info.version,
202+
body,
197203
tagName,
198204
releaseId,
199-
artifacts:
200-
releaseArtifacts.length !== 0 ? releaseArtifacts : debugArtifacts,
205+
releaseArtifacts.length !== 0 ? releaseArtifacts : debugArtifacts,
201206
targetInfo,
202-
unzippedSig: info.unzippedSigs,
207+
info.unzippedSigs,
203208
updaterJsonPreferNsis,
204209
updaterJsonKeepUniversal,
205-
});
210+
retryAttempts,
211+
);
206212
}
207213
} else {
208214
console.log('No releaseId or tagName provided, skipping all uploads...');

src/upload-release-assets.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import fs from 'node:fs';
22

33
import { getOctokit } from '@actions/github';
44

5-
import { getAssetName } from './utils';
5+
import { getAssetName, retry } from './utils';
66
import type { Artifact } from './types';
77

88
export async function uploadAssets(
99
owner: string,
1010
repo: string,
1111
releaseId: number,
1212
assets: Artifact[],
13+
retryAttempts: number,
1314
) {
1415
if (process.env.GITHUB_TOKEN === undefined) {
1516
throw new Error('GITHUB_TOKEN is required');
@@ -58,15 +59,19 @@ export async function uploadAssets(
5859

5960
console.log(`Uploading ${assetName}...`);
6061

61-
await github.rest.repos.uploadReleaseAsset({
62-
headers,
63-
name: assetName,
64-
// https://github.com/tauri-apps/tauri-action/pull/45
65-
// @ts-expect-error error TS2322: Type 'Buffer' is not assignable to type 'string'.
66-
data: fs.createReadStream(asset.path),
67-
owner: owner,
68-
repo: repo,
69-
release_id: releaseId,
70-
});
62+
return retry(
63+
() =>
64+
github.rest.repos.uploadReleaseAsset({
65+
headers,
66+
name: assetName,
67+
// https://github.com/tauri-apps/tauri-action/pull/45
68+
// @ts-expect-error error TS2322: Type 'Buffer' is not assignable to type 'string'.
69+
data: fs.createReadStream(asset.path),
70+
owner: owner,
71+
repo: repo,
72+
release_id: releaseId,
73+
}),
74+
retryAttempts + 1,
75+
);
7176
}
7277
}

src/upload-version-json.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,20 @@ type VersionContent = {
2222
};
2323
};
2424

25-
export async function uploadVersionJSON({
26-
owner,
27-
repo,
28-
version,
29-
notes,
30-
tagName,
31-
releaseId,
32-
artifacts,
33-
targetInfo,
34-
unzippedSig,
35-
updaterJsonPreferNsis,
36-
updaterJsonKeepUniversal,
37-
}: {
38-
owner: string;
39-
repo: string;
40-
version: string;
41-
notes: string;
42-
tagName: string;
43-
releaseId: number;
44-
artifacts: Artifact[];
45-
targetInfo: TargetInfo;
46-
unzippedSig: boolean;
47-
updaterJsonPreferNsis: boolean;
48-
updaterJsonKeepUniversal: boolean;
49-
}) {
25+
export async function uploadVersionJSON(
26+
owner: string,
27+
repo: string,
28+
version: string,
29+
notes: string,
30+
tagName: string,
31+
releaseId: number,
32+
artifacts: Artifact[],
33+
targetInfo: TargetInfo,
34+
unzippedSig: boolean,
35+
updaterJsonPreferNsis: boolean,
36+
updaterJsonKeepUniversal: boolean,
37+
retryAttempts: number,
38+
) {
5039
if (process.env.GITHUB_TOKEN === undefined) {
5140
throw new Error('GITHUB_TOKEN is required');
5241
}
@@ -215,5 +204,11 @@ export async function uploadVersionJSON({
215204
});
216205
}
217206

218-
await uploadAssets(owner, repo, releaseId, [{ path: versionFile, arch: '' }]);
207+
await uploadAssets(
208+
owner,
209+
repo,
210+
releaseId,
211+
[{ path: versionFile, arch: '' }],
212+
retryAttempts,
213+
);
219214
}

0 commit comments

Comments
 (0)