Skip to content

Commit

Permalink
feat(ci): add GitHub action workflows for tests and release
Browse files Browse the repository at this point in the history
- download used NSIS plugins before build and use them from that local folder
- raise minimum node version (needed for building and using nodist) to 12
  • Loading branch information
Mairu committed May 17, 2022
1 parent f8db08d commit 55ea5d6
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 6 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'

jobs:
run-build:
runs-on: windows-2022
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- run: npm ci
- name: Copy Node.exe to repository directory
run: Copy-Item (Get-Command node.exe | Select-Object -ExpandProperty Definition) .
- run: npm test
- run: npm run build
- name: Create release draft
uses: ncipollo/release-action@v1
with:
artifacts: "build/out/NodistSetup-*.exe"
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: run-tests

on:
push:
branches:
- '**'
tags-ignore:
- '**'

jobs:
run-tests:
runs-on: windows-2022

strategy:
matrix:
node-versions: [16.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- name: Copy Node.exe to repository directory
run: Copy-Item (Get-Command node.exe | Select-Object -ExpandProperty Definition) .
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
/pkg
/test/tmp
/node.exe
/build/nsis_plugins
5 changes: 3 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"asi": false,
"laxcomma": true,
"node": true,
"esversion": 8,
"esversion": 11,
"bitwise": false,
"eqeqeq": true,
"immed": true,
Expand All @@ -15,5 +15,6 @@
"unused": true,
"trailing": true,
"smarttabs": true,
"strict": true
"strict": true,
"module": true
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ Testing also accepts env variables for using a mirror to download from, as well
Building nodist requires
* [go](https://golang.org) for compiling the shim
* [NSIS](http://nsis.sourceforge.net/Main_Page) v3 for compiling the installer
* NSIS plugins will be automatically downloaded before build:
* NSIS Plugin: [AccessControl](http://nsis.sourceforge.net/AccessControl_plug-in)
* NSIS Plugin: [EnVar Plugin](https://nsis.sourceforge.io/EnVar_plug-in)
* node.js for running the build script
Expand Down Expand Up @@ -298,6 +299,7 @@ v0.10.0
* Resolve symlinks for npm's node_modules to support npm >= 8
* Use octokit lib to access github, add NODIST_GITHUB_TOKEN env variable PR#246
* Fix `npm ls` to resolve correct version PR#240
* Minimal node version to build nodist raised to 12

v0.9.1
* Fix issue with deprecated call to Tar.Extract in the NPM handler.
Expand Down
11 changes: 8 additions & 3 deletions build/Nodist.template.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
!define REG_ROOT "HKLM"
!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${MAIN_APP_EXE}"
!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
!define PLUGINS_PATH ";PLUGINS_PATH;"

; HKLM (all users) vs HKCU (current user) defines
!define ENV_HKLM 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
Expand All @@ -27,6 +28,13 @@
!include "WinMessages.nsh"
!include "x64.nsh"

; add additional plugins
!addplugindir /x86-ansi "${PLUGINS_PATH}\Plugins\x86-ansi"
!addplugindir /x86-ansi "${PLUGINS_PATH}\Plugins\i386-ansi"
!addplugindir /x86-unicode "${PLUGINS_PATH}\Plugins\x86-unicode"
!addplugindir /x86-unicode "${PLUGINS_PATH}\Plugins\i386-unicode"
!addplugindir /amd64-unicode "${PLUGINS_PATH}\Plugins\amd64-unicode"

######################################################################

VIProductVersion "${VERSION}"
Expand All @@ -49,9 +57,6 @@ InstallDir "$PROGRAMFILES\Nodist"

######################################################################

!include "StrFunc.nsh"
${StrRep}

!include "MUI.nsh"

!define MUI_ABORTWARNING
Expand Down
4 changes: 4 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ P.all([
';VERSION;',
pkg.version
);
nsiTemplate = nsiTemplate.replace(
';PLUGINS_PATH;',
path.join(nodistDir, 'build', 'nsis_plugins'),
);
nsiTemplate = nsiTemplate.replace(
';ADD_FILES;',
installManifest.join('\n')
Expand Down
60 changes: 60 additions & 0 deletions build/fetch_nsis_plugins.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

import fs from 'fs';
import os from 'os';
import path from 'path';
import * as stream from 'stream';
import { fileURLToPath } from 'url';
import { promisify } from 'util';

import axios from 'axios';
import unzip from 'node-unzip-2';

const finished = promisify(stream.finished);

const plugins = [
'https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip',
'https://nsis.sourceforge.io/mediawiki/images/4/4a/AccessControl.zip'
];

async function downloadFile(url, outputLocation) {
const writer = fs.createWriteStream(outputLocation);

return axios.get(url, { responseType: 'stream' }).then(response => {
response.data.pipe(writer);
return finished(writer);
});
}

const dirname = path.dirname(fileURLToPath(import.meta.url));
const nsisPluginsDir = path.join(dirname, 'nsis_plugins');
const nsisPluginsInstalledFile = path.join(nsisPluginsDir, 'installed.txt');

if (fs.existsSync(nsisPluginsInstalledFile)) {
console.log('NSIS plugins installed already, skipping downloading plugins');
process.exit(0);
}

fs.mkdirSync(nsisPluginsDir);
const tmpDir = os.tmpdir();

Promise.all(
plugins.map(async (url) => {
const targetFileName = url.split('/').pop();
const targetPath = path.join(tmpDir, targetFileName);
await downloadFile(url, targetPath);
const readStream = fs.createReadStream(targetPath);
const unzipped = new Promise(function(resolve, reject) {
readStream.on('close', resolve);
readStream.on('error', reject);
});
readStream.pipe(unzip.Extract({ path: nsisPluginsDir }));
await unzipped;
return targetFileName;
})
).then((plugins) => {
fs.writeFileSync(nsisPluginsInstalledFile, 'plugins installed');
console.log('Finished downloading NSIS plugins');
plugins.forEach(plugin => console.log(` - ${plugin}`));
});

Loading

0 comments on commit 55ea5d6

Please sign in to comment.