Skip to content

Commit

Permalink
Fix release upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Sep 22, 2024
1 parent 5000e29 commit 4e07bbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/new-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install
run: pnpm install --filter=overlayed-root
- name: Download draft binaries
- name: Download Release Binaries
uses: actions/github-script@v7
with:
script: |
Expand All @@ -50,7 +50,7 @@ jobs:
if (tag) {
context.ref = tag
}
await script({ github, context }, "stable", )
await script({ github, context }, "stable")
env:
# NOTE: we need this to download the bins
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 10 additions & 9 deletions scripts/actions/upload-to-r2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ export const script = async ({ github, context }, channel) => {

/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
async function uploadStableArtifacts({ github, context }) {
console.log(`[${context.ref}] Fetching release...`);
const tag = context.ref.replace("refs/tags/", "");
console.log(`[${tag}] Fetching release...`);
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.ref,
tag
});

const artifacts = release.data.assets;

console.log(`[${context.ref}] Found ${artifacts.length} artifacts in the release`);
console.log(`[${tag}] Found ${artifacts.length} artifacts in the release`);

const releaseBinDir = path.join(ASSET_DIR, "stable", context.ref);
const releaseBinDir = path.join(ASSET_DIR, "stable", tag);

// make the dir for version
fs.mkdirSync(releaseBinDir, { recursive: true });

// download all the artifacts from the build
for (const artifact of artifacts) {
console.log(`[${context.ref}] Downloading stable artifact ${artifact.name}`);
console.log(`[${tag}] Downloading stable artifact ${artifact.name}`);
fetch(artifact.browser_download_url)
.then(res => res.arrayBuffer())
.then(data => {
Expand All @@ -59,21 +60,21 @@ async function uploadStableArtifacts({ github, context }) {

try {
// upload to r2
console.log(`[${context.ref}] Starting upload to R2...`);
console.log(`[${tag}] Starting upload to R2...`);
for (const file of fs.readdirSync(releaseBinDir)) {
const assetFilePath = path.join(releaseBinDir, file);
const fileStream = fs.createReadStream(assetFilePath);

const uploadBinsCommand = new PutObjectCommand({
Bucket: R2_BUCKET,
Key: `stable/${context.ref}/${file}`,
Key: `stable/${tag}/${file}`,
Body: fileStream,
});

console.log(`[${context.ref}] ${file} starting upload...`);
console.log(`[${tag}] ${file} starting upload...`);
await client.send(uploadBinsCommand);

console.log(`[${context.ref}] ${file} uploaded successfully`);
console.log(`[${tag}] ${file} uploaded successfully`);
}

} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ switch (arg) {
await uploadBinsToR2({ github, context }, "canary");
break;
case "upload-stable":
context.ref = "v0.6.1";
context.ref = "refs/tags/v0.6.2";
await uploadBinsToR2({ github, context }, "stable");
break;
default:
Expand Down

0 comments on commit 4e07bbd

Please sign in to comment.