Skip to content

Commit

Permalink
Automated build and release (#88)
Browse files Browse the repository at this point in the history
* Create build.yml

* Create build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* build npm cache

* build step

* Build action

* Build action

* Build action

* Build action - fix env

* Build action ENV

* Action build test

* Unit test timeout

* Build action test

* Build action fix quote

* Action build debug

* Build release

Co-authored-by: sbs20@omicron.sbs20.com <sbs20@omicron.sbs20.com>
  • Loading branch information
sbs20 and sbs20@omicron.sbs20.com authored Oct 14, 2020
1 parent e368ab1 commit 08e9189
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 17 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Node.js CI

on:
workflow_dispatch:
push:
branches:
- development
- staging
- master

jobs:
build:
runs-on: ubuntu-latest

strategy:
max-parallel: 6
matrix:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

# Use nodejs cache
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
# Enable conversion to PDF
- run: sudo sed -i 's/policy domain="coder" rights="none" pattern="PDF"/policy domain="coder" rights="read | write" pattern="PDF"'/ /etc/ImageMagick-6/policy.xml

# Install packages and build
- run: npm install
- run: npm run server-lint
- run: npm run server-build
- run: npm run client-build
- run: npm run test
env:
CI: true
- run: npm run package

# We may need the package name for a release later (if not the dev branch and it's node 12)
- name: Retrieve package name
if: endsWith(matrix.node-version, '12.x') && !endsWith(github.ref, 'development')
run: |
echo "PACKAGE_NAME=$(ls ./release/)" >> $GITHUB_ENV
# Create a draft release if there's a package
- name: Create Release
id: create_release
if: env.PACKAGE_NAME
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: true

# Upload the release package
- name: Upload Release Asset
id: upload-release-asset
if: env.PACKAGE_NAME
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release/${{ env.PACKAGE_NAME }}
asset_name: ${{ env.PACKAGE_NAME }}
asset_content_type: application/gzip
35 changes: 22 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ gulp.task('clean', () => {
return del(['./dist/*']);
});

gulp.task('client-build', () => {
return run('npm run client-build').exec();
});

gulp.task('server-lint', () => {
return gulp.src(['./server/*.js', './config/config.js', './test/**/*.js', 'gulpfile.js'])
.pipe(linter())
Expand All @@ -84,15 +80,7 @@ gulp.task('server-build', () => {
.pipe(gulp.dest('./dist/'));
});

gulp.task('test', () => {
return run('npm run test').exec();
});

gulp.task('build', gulp.series(['clean', 'server-lint', 'client-build', 'server-build', 'test'], (done) => {
done();
}));

gulp.task('release', gulp.series(['build'], () => {
gulp.task('package', () => {
const filename = `scanservjs_v${version}_${dayjs().format('YYYYMMDD.HHmmss')}.tar`;
const shellFilter = filter('**/*.sh', {restore: true});
return gulp.src('./dist/**/*')
Expand All @@ -105,6 +93,27 @@ gulp.task('release', gulp.series(['build'], () => {
.pipe(tar(filename))
.pipe(gzip())
.pipe(gulp.dest('./release'));
});

/*
Development helpers below. These tasks rely on running a command line which is
not available in all circumstances.
*/

gulp.task('client-build', () => {
return run('npm run client-build').exec();
});

gulp.task('test', () => {
return run('npm run test').exec();
});

gulp.task('build', gulp.series(['clean', 'server-lint', 'client-build', 'server-build', 'test'], (done) => {
done();
}));

gulp.task('release', gulp.series(['build', 'package'], (done) => {
done();
}));

gulp.task('default', gulp.series(['build'], (done) => {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation. scanserv does not do image conversion or manipulation (beyond the bare minimum necessary for the purposes of browser preview) or OCR.",
"scripts": {
"serve": "nodemon --exec 'vue-cli-service serve'",
"server-lint": "gulp server-lint",
"server-build": "gulp server-build",
"client-build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"client-lint": "vue-cli-service lint",
"package": "gulp package",
"test": "mocha"
},
"main": "server/server.js",
Expand Down
9 changes: 6 additions & 3 deletions test/process.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ describe('Process', () => {
assert.strictEqual(png.length, 3451);
});

it('spawn: cat ./test/resource/logo.png | convert - -quality 50 jpg:-', async () => {
it('spawn: cat ./test/resource/logo.png | convert - -quality 50 jpg:-', async function () {
this.timeout(5000);
const png = await Process.spawn('cat ./test/resource/logo.png');
const jpg = await Process.spawn('convert - -quality 50 jpg:-', png);
// It should be about 4179 but different convert implementations may vary
assert.strictEqual(jpg.length > 4000, true);
});

it('chain: cat ./test/resource/logo.png | convert - -quality 50 jpg:-', async () => {
it('chain: cat ./test/resource/logo.png | convert - -quality 50 jpg:-', async function () {
this.timeout(5000);
const cmds = [
'cat ./test/resource/logo.png',
'convert - -quality 50 jpg:-'
Expand All @@ -68,7 +70,8 @@ describe('Process', () => {
assert.strictEqual(jpg.length > 4000, true);
});

it('chain: cat ./test/resource/logo.png | convert - pdf:-', async () => {
it('chain: cat ./test/resource/logo.png | convert - pdf:-', async function () {
this.timeout(5000);
const cmds = [
'cat ./test/resource/logo.png',
'convert - pdf:-'
Expand Down

0 comments on commit 08e9189

Please sign in to comment.