-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1283 from hydralauncher/ci/testing-build-webhook
ci: testing upload build script
- Loading branch information
Showing
5 changed files
with
1,188 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}); | ||
} | ||
}); |
Oops, something went wrong.