diff --git a/.github/workflows/publish-windows.yml b/.github/workflows/publish-windows.yml index c81119cc..22ca002a 100644 --- a/.github/workflows/publish-windows.yml +++ b/.github/workflows/publish-windows.yml @@ -43,6 +43,8 @@ jobs: run: node .\utils\upload-artifact.js electronim-win-x64.zip application/zip - name: Upload Portable exe run: node .\utils\upload-artifact.js electronim-win-x64.exe application/octet-stream + - name: Prepare Chocolatey + run: node .\utils\prepare-chocolatey.js - name: Chocolatey Push run: | powershell diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c28bb8a8..5dc3df9a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -108,6 +108,8 @@ jobs: run: | node .\utils\prepare-electron-builder.js npm run build:win + - name: Prepare Chocolatey + run: node .\utils\prepare-chocolatey.js - name: Choco Script tests run: | powershell diff --git a/build-config/chocolateyInstall.ps1 b/build-config/chocolateyInstall.ps1 index e989d5c4..29eecf3c 100644 --- a/build-config/chocolateyInstall.ps1 +++ b/build-config/chocolateyInstall.ps1 @@ -1,5 +1,6 @@ $packageName = 'electronim' $file = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\electronim-win-x64.zip" +$hash = 1337 $unzipLocation = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\electronim" @@ -7,5 +8,7 @@ Install-ChocolateyZipPackage ` -PackageName $packageName ` -File $file ` -UnzipLocation $unzipLocation ` + -Checksum $hash ` + -ChecksumType 'SHA256' ` Install-BinFile -Name $packageName -Path 'electronim.exe' diff --git a/utils/prepare-chocolatey.js b/utils/prepare-chocolatey.js new file mode 100644 index 00000000..f6e21ba6 --- /dev/null +++ b/utils/prepare-chocolatey.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node +/* eslint-disable no-console */ +const crypto = require('crypto'); +const fs = require('fs'); +const path = require('path'); +const errorHandler = require('./error-handler'); + +const license = () => { + const packageLicense = path.join(__dirname, '..', 'LICENSE'); + const packageLicenseTxt = path.join(__dirname, '..', 'build-config', 'LICENSE.txt'); + fs.copyFileSync(packageLicense, packageLicenseTxt); +}; + +const calculateHash = () => { + const windowsPackage = path.join(__dirname, '..', 'dist', 'electronim-win-x64.zip'); + const fileBuffer = fs.readFileSync(windowsPackage); + const hashSum = crypto.createHash('sha256'); + hashSum.update(fileBuffer); + const hash = hashSum.digest('hex').toUpperCase(); + const chocolateyInstall = path.resolve(__dirname, '..', 'build-config', 'chocolateyInstall.ps1'); + fs.writeFileSync(chocolateyInstall, fs.readFileSync(chocolateyInstall).toString() + .replace(/\$hash = .+$/gm, `$hash = "${hash}"`) + ); +}; + +const prepareChocolatey = () => { + license(); + calculateHash(); +}; + +process.on('unhandledRejection', errorHandler); +prepareChocolatey(); diff --git a/utils/prepare-electron-builder.js b/utils/prepare-electron-builder.js index e21a4110..df599cab 100755 --- a/utils/prepare-electron-builder.js +++ b/utils/prepare-electron-builder.js @@ -12,15 +12,8 @@ const electronToDevDependencies = () => { fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson)); }; -const licenseForChocolatey = () => { - const packageLicense = path.join(__dirname, '..', 'LICENSE'); - const packageLicenseTxt = path.join(__dirname, '..', 'build-config', 'LICENSE.txt'); - fs.copyFileSync(packageLicense, packageLicenseTxt); -}; - const prepareElectronBuilder = () => { electronToDevDependencies(); - licenseForChocolatey(); }; process.on('unhandledRejection', errorHandler);