fix: overwrite native builds if needed (#1186)

This commit is contained in:
Fabian-Lars
2025-11-16 15:18:37 +01:00
committed by GitHub
parent 6d11c279be
commit 1898cf45ee
5 changed files with 53 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
action: patch
---
Fiixed an issue that caused outdated signatures for macos universal builds in latest.json when re-running the action on the same release multiple times.
+4
View File
@@ -15,6 +15,10 @@ jobs:
include:
- platform: 'macos-latest'
args: '--verbose --target universal-apple-darwin --debug'
- platform: 'macos-latest'
args: '--verbose --target aarch64-apple-darwin --debug'
- platform: 'macos-latest'
args: '--verbose --target x86_64-apple-darwin --debug'
- platform: 'ubuntu-22.04'
args: '--verbose --debug'
- platform: 'windows-latest'
+1 -1
View File
File diff suppressed because one or more lines are too long
+39 -12
View File
@@ -23,6 +23,18 @@ type VersionContent = {
};
};
function ghAssetName(
artifact: Artifact,
releaseAssetNamePattern?: string,
): string {
return getAssetName(artifact, releaseAssetNamePattern)
.trim()
.replace(/[ ()[\]{}]/g, '.')
.replace(/\.\./g, '.')
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '');
}
export async function uploadVersionJSON(
owner: string,
repo: string,
@@ -117,13 +129,24 @@ export async function uploadVersionJSON(
// Assets matching artifacts generated by this action
const filteredAssets = [];
// We need to check for these so that we can non-destructively overwrite the relevant json entries with universal builds if needed
let hasNativeArm;
let hasNativeX64;
for (const artifact of artifacts) {
const assetName = getAssetName(artifact, releaseAssetNamePattern)
.trim()
.replace(/[ ()[\]{}]/g, '.')
.replace(/\.\./g, '.')
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '');
if (artifact.ext === '.app.tar.gz' && artifact.arch === 'universal') {
const arm = ghAssetName(
{ ...artifact, arch: 'aarch64' },
releaseAssetNamePattern,
);
const x86 = ghAssetName(
{ ...artifact, arch: 'x86_64' },
releaseAssetNamePattern,
);
hasNativeArm = downloadUrls.has(arm);
hasNativeX64 = downloadUrls.has(x86);
}
const assetName = ghAssetName(artifact, releaseAssetNamePattern);
const downloadUrl = downloadUrls.get(assetName);
if (downloadUrl) {
filteredAssets.push({
@@ -215,14 +238,16 @@ export async function uploadVersionJSON(
// This is our primary updater type we use for `{os}-{arch}`
if (idx === 0) {
if (os === 'darwin' && arch === 'universal') {
// Don't overwrite native builds
if (!versionContent.platforms['darwin-aarch64']) {
// Don't overwrite native builds unless outdated.
// hasNativeArm/x64 can be false while other jobs are overwriting artifacts,
// but we should still always end up with a working latest.json file.
if (!versionContent.platforms['darwin-aarch64'] || !hasNativeArm) {
(versionContent.platforms['darwin-aarch64'] as unknown) = {
signature: readFileSync(signatureFile.path).toString(),
url: updaterFileDownloadUrl,
};
}
if (!versionContent.platforms['darwin-x86_64']) {
if (!versionContent.platforms['darwin-x86_64'] || !hasNativeX64) {
(versionContent.platforms['darwin-x86_64'] as unknown) = {
signature: readFileSync(signatureFile.path).toString(),
url: updaterFileDownloadUrl,
@@ -237,14 +262,16 @@ export async function uploadVersionJSON(
// This is for the new `{os}-{arch}-{installer}` format
if (os === 'darwin' && arch === 'universal') {
// Don't overwrite native builds
if (!versionContent.platforms['darwin-aarch64-app']) {
// Don't overwrite native builds unless outdated.
// hasNativeArm/x64 can be false while other jobs are overwriting artifacts,
// but we should still always end up with a working latest.json file.
if (!versionContent.platforms['darwin-aarch64-app'] || !hasNativeArm) {
(versionContent.platforms['darwin-aarch64-app'] as unknown) = {
signature: readFileSync(signatureFile.path).toString(),
url: updaterFileDownloadUrl,
};
}
if (!versionContent.platforms['darwin-x86_64-app']) {
if (!versionContent.platforms['darwin-x86_64-app'] || !hasNativeX64) {
(versionContent.platforms['darwin-x86_64-app'] as unknown) = {
signature: readFileSync(signatureFile.path).toString(),
url: updaterFileDownloadUrl,
+4 -1
View File
@@ -21,7 +21,9 @@ export async function uploadWorkflowArtifacts(
if (artifact.ext === '.app') {
paths = globbySync('**/*', { cwd: artifact.path, absolute: true });
}
console.log(JSON.stringify(paths));
console.log(
"Handing it off to GitHub's uploadArtifact function. This will print a few unmanaged logs.",
);
await retry(
() =>
GHArtifact.uploadArtifact(
@@ -34,6 +36,7 @@ export async function uploadWorkflowArtifacts(
),
retryAttempts,
);
console.log('Workflow artifacts uploads DONE!');
}
}
}