Skip to content

Commit

Permalink
Merge pull request #43 from balena-io-modules/drivelist
Browse files Browse the repository at this point in the history
Update resin-device-operations to v2
  • Loading branch information
thgreasi authored Apr 9, 2024
2 parents 1a38ed1 + df57ac4 commit 62e97bf
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 125 deletions.
50 changes: 50 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
name: "Test custom"
description: "Custom test step to run during a pull request"
# this inputs are always provided by flowzone, so they must always be defined on the composite action
inputs:
json:
description: "JSON stringified object containing all the inputs from the calling workflow"
required: true
secrets:
description: "JSON stringified object containing all the secrets from the calling workflow"
required: true
runs:
using: "composite"
steps:
- name: Setup Node.js 18
if: ${{ fromJSON(env.os_value)[0] == 'ubuntu-20.04' }}
uses: actions/setup-node@v3
with:
node-version: 18

- name: Setup Node.js lts
if: ${{ fromJSON(env.os_value)[0] != 'ubuntu-20.04' }}
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Install dependencies
shell: bash
run: |
if [ -e package-lock.json ]; then
npm ci
else
npm i
fi
- name: Run custom node tests
shell: bash
run: |
# os_value is a JSON array of runner labels but we are only looking at the first element
echo "OS: ${{ fromJSON(env.os_value)[0] }}"
node -v
npm -v
export TEST_EMAIL_KEY=${{ format('TEST_EMAIL{0}', fromJSON('{"windows-2019":"","ubuntu-20.04":"_1","macos-12":"_2"}')[fromJSON(env.os_value)[0]]) }}
export TEST_EMAIL=${{ fromJSON(inputs.secrets)[ format('TEST_EMAIL{0}', fromJSON('{"windows-2019":"","ubuntu-20.04":"_1","macos-12":"_2"}')[fromJSON(env.os_value)[0]]) ] }}
export TEST_PASSWORD=${{ fromJSON(inputs.secrets).TEST_PASSWORD }}
echo "TEST_EMAIL_KEY: [ ${TEST_EMAIL_KEY} ]"
echo "TEST_EMAIL: [ ${TEST_EMAIL} ]"
npm test
23 changes: 23 additions & 0 deletions .github/workflows/flowzone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Flowzone

on:
pull_request:
types: [opened, synchronize, closed]
branches: [main, master]
# allow external contributions to use secrets within trusted code
pull_request_target:
types: [opened, synchronize, closed]
branches: [main, master]

jobs:
flowzone:
name: Flowzone
uses: product-os/flowzone/.github/workflows/flowzone.yml@master
# prevent duplicate workflows and only allow one `pull_request` or `pull_request_target` for
# internal or external contributions respectively
if: |
(github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request') ||
(github.event.pull_request.head.repo.full_name != github.repository && github.event_name == 'pull_request_target')
secrets: inherit
with:
custom_runs_on: '[["windows-2019"],["ubuntu-20.04"],["macos-12"]]'
24 changes: 0 additions & 24 deletions appveyor.yml

This file was deleted.

84 changes: 0 additions & 84 deletions circle.yml

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
},
"scripts": {
"build": "gulp build && npm run readme",
"pretest": "npm run build",
"test": "gulp test && coffee tests/e2e.coffee",
"prepublish": "require-npm4-to-publish",
"test": "([ \"$GITHUB_WORKFLOW\" = 'Flowzone' ] && [ \"$GITHUB_JOB\" = 'npm_test' ] && echo \"Skipping 'npm test' in flowzone in favor of the custom test action!\") || (npm run build && npm run test:all)",
"test:all": "gulp test && coffee tests/e2e.coffee",
"prepare": "npm run build",
"readme": "jsdoc2md --template doc/README.hbs build/init.js > README.md"
},
"author": "Juan Cruz Viotti <juan@balena.io>",
"license": "Apache-2.0",
"engines": {
"node": ">=18"
},
"devDependencies": {
"balena-sdk": "^12.27.0",
"coffeescript": "^1.12.7",
"dotenv": "^4.0.0",
"etcher-sdk": "^9.0.8",
"gulp": "^4.0.2",
"gulp-coffee": "^2.3.5",
"gulp-coffeelint": "^0.5.0",
Expand All @@ -40,7 +43,6 @@
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^2.5.3",
"mochainon": "^1.0.0",
"require-npm4-to-publish": "^1.0.0",
"wary": "^1.1.1"
},
"dependencies": {
Expand All @@ -49,7 +51,7 @@
"bluebird": "^3.7.2",
"lodash": "^4.17.15",
"reconfix": "1.0.0-v0-1-0-fork-46760acff4d165f5238bfac5e464256ef1944476",
"resin-device-operations": "^1.7.0",
"resin-device-operations": "^2.0.0",
"rindle": "^1.3.4",
"string-to-stream": "^1.1.1"
}
Expand Down
57 changes: 45 additions & 12 deletions tests/e2e.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fs = Promise.promisifyAll(require('fs'))
wary = require('wary')

settings = require('balena-settings-client')
etcherSdk = require('etcher-sdk')
sdk = require('balena-sdk')({
apiUrl: settings.get('apiUrl')
})
Expand Down Expand Up @@ -170,14 +171,52 @@ wary.it 'should not trigger a state event when configuring a raspberry pi',
.then ->
m.chai.expect(spy).to.not.have.been.called

mockBlockDeviceFromFile = (path) ->
drive = {
raw: path,
device: path,
devicePath: path,
displayName: path,
icon: 'some icon',
isSystem: false,
description: 'some description',
mountpoints: [],
size: fs.statSync(path).size,
isReadOnly: false,
busType: 'UNKNOWN',
error: null,
blockSize: 512,
busVersion: null,
enumerator: 'fake',
isCard: null,
isRemovable: true,
isSCSI: false,
isUAS: null,
isUSB: true,
isVirtual: false,
logicalBlockSize: 512,
partitionTableType: null,
};
device = new etcherSdk.sourceDestination.BlockDevice({
drive,
unmountOnSuccess: false,
write: true,
direct: false,
})

device._open = () ->
etcherSdk.sourceDestination.File.prototype._open.call(device)
device._close = () ->
etcherSdk.sourceDestination.File.prototype._close.call(device)

device

wary.it 'should initialize a raspberry pi image',
raspberrypi: RASPBERRYPI_OS1
random: RANDOM
, (images) ->

drive =
raw: images.random
size: fs.statSync(images.random).size
drive = mockBlockDeviceFromFile(images.random)

sdk.models.device.get(DEVICES.raspberrypi.id).then (device) ->
getManifest(device.device_type).then (manifest) ->
Expand All @@ -196,9 +235,7 @@ wary.it 'should initialize a raspberry pi image containing a device type',
random: RANDOM
, (images) ->

drive =
raw: images.random
size: fs.statSync(images.random).size
drive = mockBlockDeviceFromFile(images.random)

sdk.models.device.get(DEVICES.raspberrypi.id).then (device) ->
# make sure the device-type.json file is read from the image
Expand All @@ -218,9 +255,7 @@ wary.it 'should emit state events when initializing a raspberry pi',
random: RANDOM
, (images) ->

drive =
raw: images.random
size: fs.statSync(images.random).size
drive = mockBlockDeviceFromFile(images.random)

spy = m.sinon.spy()

Expand All @@ -243,9 +278,7 @@ wary.it 'should emit burn events when initializing a raspberry pi',
random: RANDOM
, (images) ->

drive =
raw: images.random
size: fs.statSync(images.random).size
drive = mockBlockDeviceFromFile(images.random)

spy = m.sinon.spy()

Expand Down

0 comments on commit 62e97bf

Please sign in to comment.