Skip to content

Commit

Permalink
🤖 Chocolatey script checks hash
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Jan 8, 2024
1 parent c2bbdbc commit c7457a7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions build-config/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
$packageName = 'electronim'
$file = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\electronim-win-x64.zip"
$hash = 1337
$unzipLocation = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\electronim"


Install-ChocolateyZipPackage `
-PackageName $packageName `
-File $file `
-UnzipLocation $unzipLocation `
-Checksum $hash `
-ChecksumType 'SHA256' `

Install-BinFile -Name $packageName -Path 'electronim.exe'
32 changes: 32 additions & 0 deletions utils/prepare-chocolatey.js
Original file line number Diff line number Diff line change
@@ -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();
7 changes: 0 additions & 7 deletions utils/prepare-electron-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c7457a7

Please sign in to comment.