-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
240 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import {unzip} from 'unzipit'; | ||
|
||
import * as github from './github.js'; | ||
import { | ||
parseArgs, | ||
} from './utils.js' | ||
|
||
async function downloadFileFromZip(url, filepath) { | ||
const res = await fetch(url); | ||
const zipData = await res.arrayBuffer(); | ||
const {entries} = await unzip(zipData); | ||
return Promise.all(Object.entries(entries).map(async ([name, entry]) => { | ||
const data = await entry.arrayBuffer(); | ||
const filename = path.join(filepath, name); | ||
console.log('downloaded:', filename); | ||
fs.mkdirSync(filepath, {recursive: true}); | ||
fs.writeFileSync(filename, new Uint8Array(data)); | ||
return filename; | ||
})); | ||
} | ||
|
||
const options = { | ||
repo: { type: 'string', inlineValue: true, required: true, description: 'owner/name of repo' }, | ||
run_id: { type: 'string', inlineValue: true, required: true, description: 'run_id from action' }, | ||
}; | ||
const { values: args } = parseArgs({ args: process.argv.slice(2), options }); | ||
|
||
/* | ||
const data = { | ||
"total_count": 3, | ||
"artifacts": [ | ||
{ | ||
"id": 2386423695, | ||
"node_id": "MDg6QXJ0aWZhY3QyMzg2NDIzNjk1", | ||
"name": "darwin-arm64.dawn.node", | ||
"size_in_bytes": 10841703, | ||
"url": "https://api.github.com/repos/greggman/node-webgpu/actions/artifacts/2386423695", | ||
"archive_download_url": "https://api.github.com/repos/greggman/node-webgpu/actions/artifacts/2386423695/zip", | ||
"expired": false, | ||
"created_at": "2025-01-04T23:01:06Z", | ||
"updated_at": "2025-01-04T23:01:06Z", | ||
"expires_at": "2025-04-04T22:49:48Z", | ||
"workflow_run": { | ||
"id": 12614358725, | ||
"repository_id": 911859581, | ||
"head_repository_id": 911859581, | ||
"head_branch": "main", | ||
"head_sha": "3bb7a9fec4559ddc789c424b92a92122ad09c1f4" | ||
} | ||
}, | ||
{ | ||
"id": 2386431784, | ||
"node_id": "MDg6QXJ0aWZhY3QyMzg2NDMxNzg0", | ||
"name": "linux-x64.dawn.node", | ||
"size_in_bytes": 120766916, | ||
"url": "https://api.github.com/repos/greggman/node-webgpu/actions/artifacts/2386431784", | ||
"archive_download_url": "https://api.github.com/repos/greggman/node-webgpu/actions/artifacts/2386431784/zip", | ||
"expired": false, | ||
"created_at": "2025-01-04T23:08:23Z", | ||
"updated_at": "2025-01-04T23:08:23Z", | ||
"expires_at": "2025-04-04T22:49:48Z", | ||
"workflow_run": { | ||
"id": 12614358725, | ||
"repository_id": 911859581, | ||
"head_repository_id": 911859581, | ||
"head_branch": "main", | ||
"head_sha": "3bb7a9fec4559ddc789c424b92a92122ad09c1f4" | ||
} | ||
}, | ||
{ | ||
"id": 2386436118, | ||
"node_id": "MDg6QXJ0aWZhY3QyMzg2NDM2MTE4", | ||
"name": "win32-x64.dawn.node", | ||
"size_in_bytes": 11265694, | ||
"url": "https://api.github.com/repos/greggman/node-webgpu/actions/artifacts/2386436118", | ||
"archive_download_url": "https://api.github.com/repos/greggman/node-webgpu/actions/artifacts/2386436118/zip", | ||
"expired": false, | ||
"created_at": "2025-01-04T23:12:55Z", | ||
"updated_at": "2025-01-04T23:12:55Z", | ||
"expires_at": "2025-04-04T22:49:48Z", | ||
"workflow_run": { | ||
"id": 12614358725, | ||
"repository_id": 911859581, | ||
"head_repository_id": 911859581, | ||
"head_branch": "main", | ||
"head_sha": "3bb7a9fec4559ddc789c424b92a92122ad09c1f4" | ||
} | ||
} | ||
] | ||
} | ||
*/ | ||
|
||
const [owner, repo] = args.repo.split('/'); | ||
const data = await github.getRunArtifacts({ | ||
owner, | ||
repo, | ||
run_id: args.run_id, | ||
}); | ||
const filenames = await Promise.all( | ||
data.artifacts | ||
.filter(({name}) => name?.endsWith('.node')) | ||
.map(({archive_download_url}) => downloadFileFromZip(archive_download_url, 'dist')) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
export async function getLatestRelease({owner, repo}) { | ||
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/releases/latest`, { | ||
function fail(msg) { | ||
throw new Error(msg); | ||
} | ||
|
||
async function fetchGithub(url, params) { | ||
url = `https://api.github.com/${url.replaceAll(/\{(.*?)\}/g, (_, id) => params[id] ?? fail(`no: ${id}`))}`; | ||
console.log(url); | ||
const res = await fetch(url, { | ||
headers: { | ||
'Accept': 'application/vnd.github+json', | ||
'X-GitHub-Api-Version': '2022-11-28', | ||
} | ||
}, | ||
}); | ||
return await res.json(); | ||
} | ||
|
||
export async function getLatestRelease(params) { | ||
return fetchGithub('repos/{owner}/{repo}/releases/latest', params); | ||
} | ||
|
||
export async function getLatestArtifacts(params) { | ||
return fetchGithub('repos/{owner}/{repo}/actions/artifacts', params); | ||
} | ||
|
||
export async function getRunArtifacts(params) { | ||
return fetchGithub('repos/{owner}/{repo}/actions/runs/{run_id}/artifacts', params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { createRequire } from 'module'; | ||
const require = createRequire(import.meta.url); | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
const dawnNodePath = join(__dirname, `${process.platform}-${process.arch}.node`); | ||
const { create, globals } = require(dawnNodePath); | ||
export { create, globals } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters