Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Chocolatey script checks hash #376

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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