From ba484070aef75d62194f13122968b8727223cd7a Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Fri, 23 Aug 2024 14:05:13 +0800 Subject: [PATCH] add checksum --- .github/workflows/build.yml | 16 ++++++++++++++-- package.json | 1 + scripts/checksum.mjs | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 scripts/checksum.mjs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cff21e1..b001de4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,12 +44,15 @@ jobs: npm_config_arch: ${{ matrix.arch }} npm_config_target_arch: ${{ matrix.arch }} run: pnpm build:win --${{ matrix.arch }} + - name: Generate checksums + run: pnpm checksum setup.exe portable.7z - name: Upload Artifacts if: startsWith(github.ref, 'refs/heads/') uses: actions/upload-artifact@v4 with: name: Windows ${{ matrix.arch }} path: | + dist/*.sha256 dist/*setup.exe dist/*portable.7z if-no-files-found: error @@ -97,12 +100,15 @@ jobs: npm_config_arch: ${{ matrix.arch }} npm_config_target_arch: ${{ matrix.arch }} run: pnpm build:linux --${{ matrix.arch }} + - name: Generate checksums + run: pnpm checksum .deb .rpm - name: Upload Artifacts if: startsWith(github.ref, 'refs/heads/') uses: actions/upload-artifact@v4 with: name: Linux ${{ matrix.arch }} path: | + dist/*.sha256 dist/*.deb dist/*.rpm if-no-files-found: error @@ -150,18 +156,24 @@ jobs: npm_config_arch: ${{ matrix.arch }} npm_config_target_arch: ${{ matrix.arch }} run: pnpm build:mac --${{ matrix.arch }} + - name: Generate checksums + run: pnpm checksum .dmg - name: Upload Artifacts if: startsWith(github.ref, 'refs/heads/') uses: actions/upload-artifact@v4 with: name: MacOS ${{ matrix.arch }} - path: dist/*.dmg + path: | + dist/*.sha256 + dist/*.dmg if-no-files-found: error - name: Publish Release if: startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v2 with: - files: dist/*.dmg + files: | + *.sha256 + dist/*.dmg body_path: changelog.md token: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index c7dc6fa..51950e5 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "typecheck": "npm run typecheck:node && npm run typecheck:web", "prepare": "node scripts/prepare.mjs", "updater": "node scripts/updater.mjs", + "checksum": "node scripts/checksum.mjs", "dev": "electron-vite dev", "postinstall": "electron-builder install-app-deps", "build:win": "electron-vite build && electron-builder --publish never --win", diff --git a/scripts/checksum.mjs b/scripts/checksum.mjs new file mode 100644 index 0000000..58d8fac --- /dev/null +++ b/scripts/checksum.mjs @@ -0,0 +1,13 @@ +import { readFileSync, readdirSync, writeFileSync } from 'fs' +import { createHash } from 'crypto' +const files = readdirSync('dist') + +for (const file of files) { + for (const ext of process.argv.slice(2)) { + if (file.endsWith(ext)) { + const content = readFileSync(`dist/${file}`) + const checksum = createHash('sha256').update(content, 'utf8').digest('hex') + writeFileSync(`dist/${file}.sha256`, checksum) + } + } +}