mirror of
https://github.com/tauri-apps/tauri-action.git
synced 2026-01-31 00:35:20 +01:00
fix: Use octokit to download latest.json instead (#322)
* fix: Use octokit to download latest.json instead * fix: increase perpage limit when requesting assets * fix: remove leftover console.log
This commit is contained in:
8
packages/action/dist/index.js
vendored
8
packages/action/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -11,15 +11,14 @@ export default async function uploadAssets(
|
||||
throw new Error('GITHUB_TOKEN is required')
|
||||
}
|
||||
|
||||
|
||||
|
||||
const github = getOctokit(process.env.GITHUB_TOKEN)
|
||||
|
||||
const existingAssets = (
|
||||
await github.rest.repos.listReleaseAssets({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
release_id: releaseId
|
||||
release_id: releaseId,
|
||||
per_page: 50
|
||||
})
|
||||
).data
|
||||
|
||||
|
||||
@@ -1,94 +1,113 @@
|
||||
import { getOctokit, context } from "@actions/github";
|
||||
import { resolve } from "path";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import uploadAssets from "./upload-release-assets";
|
||||
import fetch from "node-fetch";
|
||||
import { arch, platform } from "os";
|
||||
import { getAssetName } from "./utils";
|
||||
import { Artifact } from "@tauri-apps/action-core";
|
||||
import { getOctokit, context } from '@actions/github'
|
||||
import { resolve } from 'path'
|
||||
import { readFileSync, writeFileSync } from 'fs'
|
||||
import uploadAssets from './upload-release-assets'
|
||||
import fetch from 'node-fetch'
|
||||
import { arch, platform } from 'os'
|
||||
import { getAssetName } from './utils'
|
||||
import { Artifact } from '@tauri-apps/action-core'
|
||||
|
||||
export default async function uploadVersionJSON({
|
||||
version,
|
||||
notes,
|
||||
releaseId,
|
||||
artifacts,
|
||||
artifacts
|
||||
}: {
|
||||
version: string;
|
||||
notes: string;
|
||||
releaseId: number;
|
||||
artifacts: Artifact[];
|
||||
version: string
|
||||
notes: string
|
||||
releaseId: number
|
||||
artifacts: Artifact[]
|
||||
}) {
|
||||
if (process.env.GITHUB_TOKEN === undefined) {
|
||||
throw new Error("GITHUB_TOKEN is required");
|
||||
throw new Error('GITHUB_TOKEN is required')
|
||||
}
|
||||
|
||||
const github = getOctokit(process.env.GITHUB_TOKEN);
|
||||
const github = getOctokit(process.env.GITHUB_TOKEN)
|
||||
|
||||
const versionFilename = "latest.json";
|
||||
const versionFile = resolve(process.cwd(), versionFilename);
|
||||
const versionFilename = 'latest.json'
|
||||
const versionFile = resolve(process.cwd(), versionFilename)
|
||||
const versionContent = {
|
||||
version,
|
||||
notes,
|
||||
pub_date: new Date().toISOString(),
|
||||
platforms: {},
|
||||
};
|
||||
platforms: {}
|
||||
}
|
||||
|
||||
const assets = await github.rest.repos.listReleaseAssets({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
release_id: releaseId,
|
||||
});
|
||||
const asset = assets.data.find((e) => e.name === versionFilename);
|
||||
per_page: 50
|
||||
})
|
||||
const asset = assets.data.find((e) => e.name === versionFilename)
|
||||
|
||||
if (asset) {
|
||||
versionContent.platforms = (
|
||||
(await (await fetch(asset.browser_download_url)).json()) as any
|
||||
).platforms;
|
||||
const assetData = (
|
||||
await github.request(
|
||||
'GET /repos/{owner}/{repo}/releases/assets/{asset_id}',
|
||||
{
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
asset_id: asset.id,
|
||||
headers: {
|
||||
accept: 'application/octet-stream'
|
||||
}
|
||||
}
|
||||
)
|
||||
).data as any as ArrayBuffer
|
||||
|
||||
versionContent.platforms = JSON.parse(
|
||||
Buffer.from(assetData).toString()
|
||||
).platforms
|
||||
|
||||
// https://docs.github.com/en/rest/releases/assets#update-a-release-asset
|
||||
await github.rest.repos.deleteReleaseAsset({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
release_id: releaseId,
|
||||
asset_id: asset.id,
|
||||
});
|
||||
asset_id: asset.id
|
||||
})
|
||||
}
|
||||
|
||||
const sigFile = artifacts.find((s) => s.path.endsWith(".sig"));
|
||||
const assetNames = new Set(artifacts.map((p) => getAssetName(p.path)));
|
||||
const sigFile = artifacts.find((s) => s.path.endsWith('.sig'))
|
||||
const assetNames = new Set(artifacts.map((p) => getAssetName(p.path)))
|
||||
const downloadUrl = assets.data
|
||||
.filter((e) => assetNames.has(e.name))
|
||||
.find(
|
||||
(s) => s.name.endsWith(".tar.gz") || s.name.endsWith(".zip")
|
||||
)?.browser_download_url;
|
||||
(s) => s.name.endsWith('.tar.gz') || s.name.endsWith('.zip')
|
||||
)?.browser_download_url
|
||||
|
||||
let os = platform() as string;
|
||||
if (os === "win32") os = "windows";
|
||||
let os = platform() as string
|
||||
if (os === 'win32') os = 'windows'
|
||||
|
||||
if (downloadUrl && sigFile) {
|
||||
let arch = sigFile.arch;
|
||||
let arch = sigFile.arch
|
||||
arch === 'amd64' || arch === 'x86_64' || arch === 'x64'
|
||||
? 'x86_64'
|
||||
: arch === 'x86' || arch === 'i386'
|
||||
? 'i686'
|
||||
: arch === 'arm'
|
||||
? 'armv7'
|
||||
: arch === 'arm64'
|
||||
? 'aarch64'
|
||||
: arch
|
||||
? 'i686'
|
||||
: arch === 'arm'
|
||||
? 'armv7'
|
||||
: arch === 'arm64'
|
||||
? 'aarch64'
|
||||
: arch
|
||||
|
||||
// https://github.com/tauri-apps/tauri/blob/fd125f76d768099dc3d4b2d4114349ffc31ffac9/core/tauri/src/updater/core.rs#L856
|
||||
versionContent.platforms[`${os}-${arch}`] = {
|
||||
signature: readFileSync(sigFile.path).toString(),
|
||||
url: downloadUrl,
|
||||
};
|
||||
url: downloadUrl
|
||||
}
|
||||
} else {
|
||||
const missing = downloadUrl ? 'Signature' : sigFile ? 'Asset' : 'Asset and signature'
|
||||
const missing = downloadUrl
|
||||
? 'Signature'
|
||||
: sigFile
|
||||
? 'Asset'
|
||||
: 'Asset and signature'
|
||||
console.warn(`${missing} not found for the updater JSON.`)
|
||||
}
|
||||
|
||||
writeFileSync(versionFile, JSON.stringify(versionContent, null, 2));
|
||||
writeFileSync(versionFile, JSON.stringify(versionContent, null, 2))
|
||||
|
||||
console.log(`Uploading ${versionFile}...`);
|
||||
await uploadAssets(releaseId, [{ path: versionFile, arch: '' }]);
|
||||
console.log(`Uploading ${versionFile}...`)
|
||||
await uploadAssets(releaseId, [{ path: versionFile, arch: '' }])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user