#219 update yaml checksum data for new installers (#235)

* #219 update release yaml checksum data

---------

Co-authored-by: neil <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-02-24 15:16:53 +08:00 committed by GitHub
parent 70abf03bc5
commit d8b5ee8980
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 40 deletions

55
.github/create-correct-release-yaml.js vendored Executable file
View file

@ -0,0 +1,55 @@
const { createHash } = require("crypto");
const { createReadStream, readFileSync, statSync, writeFileSync } = require("fs");
const path = require("path");
const yaml = require("yaml");
function getHashSum(file, encoding = "base64") {
return new Promise((resolve, reject) => {
const hash = createHash("sha512")
hash.on("error", reject).setEncoding(encoding)
createReadStream(file, { highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })
.on("error", reject)
.on("end", () => {
hash.end()
resolve(hash.read())
})
.pipe(hash, { end: false })
})
}
async function main() {
const args = process.argv;
const folderPath = args.pop();
const distPath = path.join(process.cwd(), folderPath);
const releaseYamlPath = path.join(distPath, "latest-mac.yml");
const releaseConfig = await readYaml(releaseYamlPath);
for(const file of releaseConfig.files) {
const filePath = path.join(distPath, file.url);
const [stat, hash] = await Promise.all([
statSync(filePath),
getHashSum(filePath),
]);
file.size = stat.size;
file.sha512 = hash;
if (file.path === releaseConfig.path) {
releaseConfig.sha512 = hash;
}
}
const updatedYaml = yaml.stringify(releaseConfig);
await writeFileSync(releaseYamlPath, updatedYaml, "utf-8");
}
async function readYaml(filePath) {
const releaseBuff = await readFileSync(filePath);
const raw = releaseBuff.toString("utf-8");
const config = yaml.parse(raw);
return config;
}
main();

View file

@ -1,32 +0,0 @@
const { createHash } = require("crypto");
const { createReadStream } = require("fs");
const file = "tea-0.0.2-arm64.dmg";
function hashFile(file, encoding = "base64") {
return new Promise((resolve, reject) => {
const hash = createHash("sha512")
hash.on("error", reject).setEncoding(encoding)
createReadStream(file, { highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })
.on("error", reject)
.on("end", () => {
hash.end()
resolve(hash.read())
})
.pipe(hash, { end: false })
})
}
// hashFile(file)
// .then((res) => {
// console.log("res",res)
// })
async function main() {
const args = process.argv;
const filePath = args.pop();
const hash = await hashFile(filePath);
console.log(hash);
}
main();

View file

@ -142,6 +142,7 @@ jobs:
- darwin+aarch64
steps:
- uses: teaxyz/setup@v0
- uses: actions/checkout@v3
- run: rm -rf ./*.{dmg,zip} || true
- uses: aws-actions/configure-aws-credentials@v1
with:
@ -238,6 +239,8 @@ jobs:
run: |
mv $x86dmg dist
mv $arm64dmg dist
tea pnpm install
tea +nodejs.org@18 node .github/create-correct-release-yaml.js ./dist
tar -czvf dist.tgz -C dist/ .
env:
x86dmg: ${{ steps.app_files.outputs.dmg_x86 }}

View file

@ -86,7 +86,7 @@ jobs:
esac
echo "build_platform=$BUILD_PLATFORM" >> $GITHUB_OUTPUT
echo "extension=$EXTENSION" >> $GITHUB_OUTPUT
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}

View file

@ -1,6 +1,6 @@
{
"name": "@tea/workspace",
"author": "neil molina <neil@tea.xyz>",
"author": "neil molina <neil@tea.xyz>",
"private": true,
"scripts": {
"dev": "pnpm --filter desktop exec pnpm electron",
@ -13,9 +13,12 @@
"modules/*"
]
},
"homepage": "https://tea.xyz",
"repository": {
"type": "git",
"url": "https://github.com/teaxyz/gui.git"
}
"homepage": "https://tea.xyz",
"repository": {
"type": "git",
"url": "https://github.com/teaxyz/gui.git"
},
"dependencies": {
"yaml": "^2.2.1"
}
}

View file

@ -3,7 +3,10 @@ lockfileVersion: 5.4
importers:
.:
specifiers: {}
specifiers:
yaml: ^2.2.1
dependencies:
yaml: 2.2.1
modules/desktop:
specifiers: