Skip to content

Commit

Permalink
Merge pull request #1283 from hydralauncher/ci/testing-build-webhook
Browse files Browse the repository at this point in the history
ci: testing upload build script
  • Loading branch information
thegrannychaseroperation authored Dec 18, 2024
2 parents 55ed275 + 0ca6c2c commit 007731b
Show file tree
Hide file tree
Showing 5 changed files with 1,188 additions and 5 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Build

on: pull_request

env:
AWS_REGION: us-east-1

jobs:
build:
strategy:
Expand Down Expand Up @@ -65,6 +62,18 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAIN_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.MAIN_VITE_EXTERNAL_RESOURCES_URL }}

- name: Test Upload build
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_BUILDS_BUCKET_NAME: ${{ secrets.S3_BUILDS_BUCKET_NAME }}
BUILDS_URL: ${{ secrets.BUILDS_URL }}
BUILD_WEBHOOK_URL: ${{ secrets.BUILD_WEBHOOK_URL }}
GITHUB_ACTOR: ${{ github.actor }}
run: node scripts/upload-build.cjs

- name: Create artifact
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"start": "electron-vite preview",
"dev": "electron-vite dev",
"build": "npm run typecheck && electron-vite build",
"postinstall": "electron-builder install-app-deps && node ./postinstall.cjs",
"postinstall": "electron-builder install-app-deps && node ./scripts/postinstall.cjs",
"build:unpack": "npm run build && electron-builder --dir",
"build:win": "electron-vite build && electron-builder --win",
"build:mac": "electron-vite build && electron-builder --mac",
Expand Down Expand Up @@ -78,6 +78,7 @@
"zod": "^3.24.1"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.705.0",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@electron-toolkit/eslint-config-prettier": "^2.0.0",
Expand Down
File renamed without changes.
64 changes: 64 additions & 0 deletions scripts/upload-build.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const fs = require("node:fs");
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const path = require("node:path");
const packageJson = require("../package.json");

if (!process.env.BUILD_WEBHOOK_URL) {
console.log("No BUILD_WEBHOOK_URL provided, skipping upload");
process.exit(0);
}

const s3 = new S3Client({
region: "auto",
endpoint: process.env.S3_ENDPOINT,
forcePathStyle: true,
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
},
});

const dist = path.resolve(__dirname, "..", "dist");

const extensionsToUpload = [".deb", ".exe"];

fs.readdir(dist, async (err, files) => {
if (err) throw err;

const uploads = await Promise.all(
files
.filter((file) => extensionsToUpload.includes(path.extname(file)))
.map(async (file) => {
console.log(`⌛️ Uploading ${file}...`);
const fileName = `${new Date().getTime()}-${file}`;

const command = new PutObjectCommand({
Bucket: process.env.S3_BUILDS_BUCKET_NAME,
Key: fileName,
Body: fs.createReadStream(path.resolve(dist, file)),
});

await s3.send(command);

return {
url: `${process.env.BUILDS_URL}/${fileName}`,
name: fileName,
};
})
);

if (uploads.length > 0) {
await fetch(process.env.BUILD_WEBHOOK_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
uploads,
branchName: process.env.BRANCH_NAME,
version: packageJson.version,
githubActor: process.env.GITHUB_ACTOR,
}),
});
}
});
Loading

0 comments on commit 007731b

Please sign in to comment.