Skip to content

Commit

Permalink
It worked on my machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Nov 23, 2023
1 parent d85b8c7 commit 6b4e987
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
1 change: 0 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions scripts/actions/download-draft-bins.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ async function downloadFile(url, filepath = "./download") {
await finished(body.pipe(downloadWriteStream));
}

const BINARIES_DIR = "binaries";
const BINARIES_DIR = "./binaries";

/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
/** @param id {String} */
export const script = async ({ context, github }, id) => {

console.log(`📦 downloading release artifacts for ${id}`);

try {
Expand Down
35 changes: 20 additions & 15 deletions scripts/actions/sign.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import fs from "fs";
const releaseId = "${{ needs.create-release.outputs.release_id }}";

const SIGNED_BINARIES_DIR = "binaries/signed";
const SIGNED_BINARIES_DIR = "./binaries/signed";

/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
export const script = async ({ context, github }) => {
console.log("🔍 Start sign of windows binaries...");
export const script = async ({ context, github }, releaseId) => {
console.log("🔍 Start sign of windows binaries for release id", releaseId);
console.log({ cwd: process.cwd() });

if (!fs.existsSync(SIGNED_BINARIES_DIR)) {
console.log("No signed binaries found");
Expand Down Expand Up @@ -40,17 +41,21 @@ export const script = async ({ context, github }) => {
const filePath = `${SIGNED_BINARIES_DIR}/${file}`;
const fileData = fs.readFileSync(filePath);

const { data: uploadResponse } = await github.rest.repos.uploadReleaseAsset(
{
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
// @ts-ignore
data: fileData,
name: file,
},
);

console.log(uploadResponse);
console.log("uploading asset", file, filePath);

try {
const { data: uploadResponse } =
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
data: fileData,
name: file,
});

console.log("uploaded asset", uploadResponse.name, uploadResponse.id);
} catch (error) {
console.log("error uploading asset", error.message);
}
}
};
38 changes: 38 additions & 0 deletions scripts/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

// test local script
// op run --env-file .env -- npx tsx scripts/test.ts <script>
import { getOctokit, context } from "@actions/github";

// @ts-ignore
import { script as signScript } from "./actions/sign.js";
// @ts-ignore
import { script as dlScript } from "./actions/download-draft-bins.js";
// @ts-ignore
import { script as createScript } from "./actions/create-release.js";

const { GITHUB_TOKEN } = process.env;
if (!GITHUB_TOKEN) throw new Error("GITHUB_TOKEN not found");

// get first arg
const [arg] = process.argv.slice(2);

process.env.GITHUB_REPOSITORY = "Hacksore/overlayed";

const draftId = "131045109";

// create context
const github = getOctokit(GITHUB_TOKEN);

switch (arg) {
case "create":
await createScript({ github, context });
break;
case "dl":
await dlScript({ github, context }, draftId);
break;
case "sign":
await signScript({ github, context }, draftId);
break;
default:
console.log("No script found");
}

0 comments on commit 6b4e987

Please sign in to comment.