Skip to content

Commit

Permalink
Download via gh script
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Aug 19, 2024
1 parent 293afc4 commit bb977ab
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 35 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ jobs:
${{ runner.os }}-pnpm-store-
- name: Install
run: pnpm install --filter=overlayed-root
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: assets
pattern: overlayed-canary-*
merge-multiple: true
- run: ls -R assets
- name: Upload Canary Binary to R2
uses: actions/github-script@v7
with:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"@actions/github": "^6.0.0",
"@aws-sdk/client-s3": "^3.592.0",
"@types/github-script": "github:actions/github-script",
"dotenv": "^16.4.5",
"eslint": "^9.3.0",
"glob": "^10.3.10",
Expand Down
96 changes: 72 additions & 24 deletions pnpm-lock.yaml

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

25 changes: 22 additions & 3 deletions scripts/actions/upload-to-r2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@ import path from "path";

const { R2_BUCKET, R2_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY } = process.env;

// TODO: expand this to support the stable version too
export const script = async ({ context, assetDir }) => {
/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
export const script = async ({ github, context }, assetDir) => {
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId || "10445719576",
});

// download all the artifacts from the build
for (const artifact of artifacts.data.artifacts) {
console.log(`Downloading ${artifact.name}...`);
const { data } = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: "zip",
});

fs.writeFileSync(path.join(assetDir, `${artifact.name}`), Buffer.from(data));
}

console.log("Starting upload to R2...");
const client = new S3Client({
endpoint: `https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
Expand All @@ -23,7 +42,7 @@ export const script = async ({ context, assetDir }) => {

const uploadBinsCommand = new PutObjectCommand({
Bucket: R2_BUCKET,
Key: `canary/${file.replace(".zip", "")}`,
Key: `canary/${file}`,
Body: fileStream,
});

Expand Down
2 changes: 1 addition & 1 deletion scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ switch (arg) {
await patchCanaryVersion({ github, context });
break;
case "upload-r2":
await uploadBinsToR2({ context: { sha: "1212" }, assetDir: "assets" });
await uploadBinsToR2({ github, context }, "assets");
break;
default:
console.log("No script found, accepted answers are: create, download, upload, r2");
Expand Down

0 comments on commit bb977ab

Please sign in to comment.