Skip to content

Commit

Permalink
attempting to add bin info
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuczyn committed Nov 20, 2023
1 parent f5dcfcc commit 6c61561
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
66 changes: 43 additions & 23 deletions .github/actions/nym-hash-releases/create-hashes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@ import fetch from "node-fetch";
import { Octokit } from "@octokit/rest";
import fs from "fs";
import path from "path";
import { execSync } from "child_process";

function getBinInfo(path) {
// let's be super naive about it. add a+x bits on the file and try to run the command
try {
let mode = fs.statSync(path).mode
fs.chmodSync(path, mode | 0o111)

const raw = execSync(`${path} build-info --output=json`, { stdio: 'pipe', encoding: "utf8" });
const parsed = JSON.parse(raw)
return parsed
} catch (_) {
return undefined
}
}

async function run(assets, algorithm, filename, cache) {
if (!cache) {
console.warn("cache is set to 'false', but we we no longer support it")
}

try {
fs.mkdirSync('.tmp');
} catch(e) {
Expand All @@ -19,26 +38,25 @@ async function run(assets, algorithm, filename, cache) {

let buffer = null;
let sig = null;
if(cache) {
// cache in `${WORKING_DIR}/.tmp/`
const cacheFilename = path.resolve(`.tmp/${asset.name}`);
if(!fs.existsSync(cacheFilename)) {
console.log(`Downloading ${asset.browser_download_url}... to ${cacheFilename}`);
buffer = Buffer.from(await fetch(asset.browser_download_url).then(res => res.arrayBuffer()));
fs.writeFileSync(cacheFilename, buffer);
} else {
console.log(`Loading from ${cacheFilename}`);
buffer = Buffer.from(fs.readFileSync(cacheFilename));

// console.log('Reading signature from content');
// if(asset.name.endsWith('.sig')) {
// sig = fs.readFileSync(cacheFilename).toString();
// }
}
} else {
// fetch always

// cache in `${WORKING_DIR}/.tmp/`
const cacheFilename = path.resolve(`.tmp/${asset.name}`);
if(!fs.existsSync(cacheFilename)) {
console.log(`Downloading ${asset.browser_download_url}... to ${cacheFilename}`);
buffer = Buffer.from(await fetch(asset.browser_download_url).then(res => res.arrayBuffer()));
fs.writeFileSync(cacheFilename, buffer);
} else {
console.log(`Loading from ${cacheFilename}`);
buffer = Buffer.from(fs.readFileSync(cacheFilename));

// console.log('Reading signature from content');
// if(asset.name.endsWith('.sig')) {
// sig = fs.readFileSync(cacheFilename).toString();
// }
}

const binInfo = getBinInfo(cacheFilename)

if(!hashes[asset.name]) {
hashes[asset.name] = {};
}
Expand Down Expand Up @@ -99,6 +117,9 @@ async function run(assets, algorithm, filename, cache) {
if(kind) {
hashes[asset.name].kind = kind;
}
if(binInfo) {
hashes[asset.name].details = binInfo;
}

// process Tauri signature files
if(asset.name.endsWith('.sig')) {
Expand Down Expand Up @@ -169,9 +190,6 @@ export async function createHashesFromReleaseTagOrNameOrId({ releaseTagOrNameOrI
)
}

console.log("raw releases");
console.log(releases)

// process all releases by default
let releasesToProcess = releases;

Expand Down Expand Up @@ -216,7 +234,7 @@ export async function createHashesFromReleaseTagOrNameOrId({ releaseTagOrNameOrI
return { id, name, tag_name, componentName, componentVersion, assetCount: assets.length };
}));

for(const release of releasesToProcess) {
for(const release of releasesToProcess) {
const {id, name, tag_name, html_url, componentName, componentVersion} = release;

const hashes = await createHashes({ assets: release.assets, algorithm, filename, cache });
Expand All @@ -228,6 +246,8 @@ export async function createHashesFromReleaseTagOrNameOrId({ releaseTagOrNameOrI
assets: hashes,
};

console.log(output)

if(upload) {
console.log(`🚚 Uploading ${filename} to release name="${release.name}" id=${release.id} (${release.upload_url})...`);

Expand Down Expand Up @@ -257,6 +277,6 @@ export async function createHashesFromReleaseTagOrNameOrId({ releaseTagOrNameOrI
process.exit(-1);
}
}
}
}
}

12 changes: 7 additions & 5 deletions .github/workflows/publish-nym-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace
args: --release

- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: my-artifact
path: |
target/debug/nym-mixnode
target/debug/nym-api
target/release/nym-mixnode
target/release/nym-api
target/release/explorer-api
retention-days: 30

- id: create-release
Expand All @@ -85,8 +86,9 @@ jobs:
if: github.event_name == 'release'
with:
files: |
target/debug/nym-mixnode
target/debug/nym-api
target/release/nym-mixnode
target/release/nym-api
target/release/explorer-api
push-release-data-client:
if: ${{ (startsWith(github.ref, 'refs/tags/nym-binaries-') && github.event_name == 'release') || github.event_name == 'workflow_dispatch' }}
Expand Down

0 comments on commit 6c61561

Please sign in to comment.