From b534ea68dbc1132de2d1ea90766b7a1e64b422ea Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Wed, 3 Apr 2024 17:31:35 -0400 Subject: [PATCH] Feature/squashfs (#356) * shorten link * Add zip to squash * squashfs signing * Format * add secrets * release fix * revert testing * check for needed commands * changelog --- .github/workflows/release.yml | 9 ++++++-- CHANGELOG.md | 4 +++- docs/RELEASING.md | 9 +------- package.json | 4 +--- playlet-app/package.json | 6 +++-- playlet-lib/package.json | 6 +++-- tools/sign-package.js | 22 +++++++++++++++--- tools/sign-released-package.js | 34 ---------------------------- tools/squash-fs.js | 41 ++++++++++++++++++++++++++++++++++ 9 files changed, 80 insertions(+), 55 deletions(-) delete mode 100644 tools/sign-released-package.js create mode 100644 tools/squash-fs.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58b07b7e..a8e29cb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,12 @@ jobs: run: npm run test:build - name: Build Playlet - run: npm run build:release:ci + run: npm run build:release + env: + ROKU_DEV_TARGET: ${{ secrets.ROKU_DEV_TARGET }} + ROKU_DEV_TARGET_PORT: ${{ secrets.ROKU_DEV_TARGET_PORT }} + ROKU_DEVPASSWORD: ${{ secrets.ROKU_DEVPASSWORD }} + ROKU_SIGN_PASSWORD: ${{ secrets.ROKU_SIGN_PASSWORD }} - name: Use Java 21 uses: actions/setup-java@v4 @@ -70,6 +75,6 @@ jobs: run: sleep 10 - name: Create Canary release - run: gh release create canary ./release/playlet.zip ./release/playlet-lib.zip --notes-file docs/canary-changelog.md --prerelease --title Canary + run: gh release create canary ./release/playlet.zip ./release/playlet.squashfs.pkg ./release/playlet-lib.zip ./release/playlet-lib.squashfs.pkg --notes-file docs/canary-changelog.md --prerelease --title Canary env: GH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fa451c5..faf98edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing worth mentioning yet. +### Added + +- Squashfs signed build artifacts to releases ## [0.22.3] - 2024-03-31 diff --git a/docs/RELEASING.md b/docs/RELEASING.md index 6d7c8792..f8b61997 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -40,11 +40,4 @@ These are mostly the steps when releasing a new version: ## Playlet -For releasing to the store (when needed), this is done following a Playlet lib release: - -- Switch to main branch and pull changes, **including tags** - **match commit corresponding to the release.** -- `npm run build:release:ci` - - This makes sure to have a valid app in the staging folder -- `npm run sign-released-package` - - This should create the signed package under `release/playlet.pkg` -- Upload to dashboard, and schedule a release (takes a couple of days) +For releasing to the store (when needed), signed packages are attached to Github releases, ready to publish diff --git a/package.json b/package.json index bf3a60c7..63f7bcb7 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,7 @@ "prebuild": "rm -rf dist", "build:dev": "npm run build:web && npm run build:lib:dev && npm run build:app:dev", "build:prod": "npm run build:web && npm run build:lib:prod && npm run build:app:prod", - "build:release": "npm run build:release:ci && npm run sign-package", - "build:release:ci": "npm run format:fix && npm run lint:fix && npm run version-sync && npm run manifest-git-hash && npm run build:prod", + "build:release": "npm run format:fix && npm run lint:fix && npm run version-sync && npm run manifest-git-hash && npm run build:prod", "build:app:dev": "cd playlet-app && npm run build:dev", "build:app:prod": "cd playlet-app && npm run build:prod", "build:lib:dev": "cd playlet-lib && npm run build:dev", @@ -59,7 +58,6 @@ "test:build:lib": "cd playlet-lib && npm run test:build", "version-sync": "node tools/version-sync.js", "manifest-git-hash": "node tools/update-manifest-git-hash.js", - "sign-package": "node tools/sign-package.js", "sign-released-package": "node tools/sign-released-package.js", "screenshot": "node tools/screenshot.js", "profile-sync": "node tools/profile-sync.js", diff --git a/playlet-app/package.json b/playlet-app/package.json index c600e8b7..ba5ce878 100644 --- a/playlet-app/package.json +++ b/playlet-app/package.json @@ -3,12 +3,14 @@ "version": "0.22.3", "description": "Unofficial YouTube client for Roku", "scripts": { - "prebuild": "rm -rf build/playlet-app", + "prebuild": "rm -rf ../build/playlet-app", "prebuild:dev": "npm run prebuild", "prebuild:prod": "npm run prebuild", "build:dev": "bsc --create-package --debug --sourceMap=true --lintConfig ../config/bslint.jsonc", "build:prod": "bsc --create-package --sourceMap=false --lintConfig ../config/bslint.jsonc", - "postbuild:prod": "mkdir -p ../release && cp ../dist/playlet-app.zip ../release/playlet.zip", + "postbuild:prod": "mkdir -p ../release && cp ../dist/playlet-app.zip ../release/playlet.zip && npm run squash-fs && npm run sign-package", + "squash-fs": "node ../tools/squash-fs.js --in-file ../release/playlet.zip --out-file ../release/playlet.squashfs.zip", + "sign-package": "node ../tools/sign-package.js --out-file playlet.squashfs.zip --out-dir ../release --staging-dir ../build/playlet-app", "lint": "bslint --project bsconfig.lint.json --lintConfig ../config/bslint.jsonc", "lint:fix": "npm run lint -- --fix", "format:base": "bsfmt \"src/**/*.brs\" \"src/**/*.bs\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" \"!**/*.transpiled/**\" \"!**/*.transpiled.*\" --bsfmt-path ../config/bsfmt.jsonc", diff --git a/playlet-lib/package.json b/playlet-lib/package.json index 41e05b7f..63366dcd 100644 --- a/playlet-lib/package.json +++ b/playlet-lib/package.json @@ -3,14 +3,16 @@ "version": "0.22.3", "description": "Unofficial YouTube client for Roku", "scripts": { - "prebuild": "rm -rf build/playlet-lib", + "prebuild": "rm -rf ../build/playlet-lib", "prebuild:dev": "npm run prebuild", "prebuild:prod": "npm run prebuild", "build:dev": "bsc --create-package --debug --sourceMap=true --lintConfig ../config/bslint.jsonc", "build:prod": "bsc --create-package --sourceMap=false --lintConfig ../config/bslint.jsonc", "postbuild": "mkdir -p ../release && mkdir -p ../playlet-app/src/lib && cp ../dist/playlet-lib.zip ../playlet-app/src/lib/playlet-lib.zip", "postbuild:dev": "npm run postbuild", - "postbuild:prod": "npm run postbuild && cp ../dist/playlet-lib.zip ../release/playlet-lib.zip", + "postbuild:prod": "npm run postbuild && cp ../dist/playlet-lib.zip ../release/playlet-lib.zip && npm run squash-fs && npm run sign-package", + "squash-fs": "node ../tools/squash-fs.js --in-file ../release/playlet-lib.zip --out-file ../release/playlet-lib.squashfs.zip", + "sign-package": "node ../tools/sign-package.js --out-file playlet-lib.squashfs.zip --out-dir ../release --staging-dir ../build/playlet-lib", "lint": "bslint --project bsconfig.lint.json --lintConfig ../config/bslint.jsonc", "lint:fix": "npm run lint -- --fix", "format:base": "bsfmt \"src/**/*.brs\" \"src/**/*.bs\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" \"!**/*.transpiled/**\" \"!**/*.transpiled.*\" --bsfmt-path ../config/bsfmt.jsonc", diff --git a/tools/sign-package.js b/tools/sign-package.js index a17a8d8e..fe3cb867 100644 --- a/tools/sign-package.js +++ b/tools/sign-package.js @@ -3,16 +3,32 @@ const getEnvVars = require('./get-env-vars'); const rokuDeploy = require('roku-deploy'); +const { ArgumentParser } = require('argparse'); const config = getEnvVars(['ROKU_DEV_TARGET', 'ROKU_DEVPASSWORD', 'ROKU_SIGN_PASSWORD']); +const parser = new ArgumentParser({ + description: 'Sign package' +}); + +parser.add_argument('--out-file', { help: 'A zip file to sign' }); +parser.add_argument('--out-dir', { help: 'Folder of the zip file' }); +parser.add_argument('--staging-dir', { help: 'Path to the staging directory' }); + +const args = parser.parse_args(); + +const outFile = args.out_file; +const outDir = args.out_dir; +const stagingDir = args.staging_dir; + const options = { host: config.ROKU_DEV_TARGET, + packagePort: config.ROKU_DEV_TARGET_PORT || 80, password: config.ROKU_DEVPASSWORD, - outDir: 'release', - outFile: 'playlet.zip', + outDir: outDir, + outFile: outFile, failOnCompileError: true, - stagingDir: 'build/playlet-app', + stagingDir: stagingDir, retainStagingDir: true, signingPassword: config.ROKU_SIGN_PASSWORD, }; diff --git a/tools/sign-released-package.js b/tools/sign-released-package.js deleted file mode 100644 index d2c7ed91..00000000 --- a/tools/sign-released-package.js +++ /dev/null @@ -1,34 +0,0 @@ -// Description: pulls the release zip from github, signs it and retrieves it from the Roku device - -const shell = require('shelljs'); - -if (!shell.which('git')) { - shell.echo('Sorry, this script requires git'); - shell.exit(1); -} - -shell.exec('git fetch --tags --force'); - -// get current commit hash -const gitCommitHash = shell.exec('git rev-parse HEAD').stdout.trim(); - -// get current tag -const gitTags = shell.exec(`git tag --contains ${gitCommitHash}`) - .stdout.trim() - .split('\n') - .map(tag => tag.trim()); - -const expectedGitTag = `v${require('../package.json').version}`; -if (gitTags.length === 0) { - console.error(`No git tag found. Signing anyway...`); -} -if (!gitTags.includes(expectedGitTag)) { - console.error(`Expected git tag ${expectedGitTag} but found [${gitTags.join(",")}]. Signing anyway...`); -} - -// download playlet.zip from github -const zipUrl = `https://github.com/iBicha/playlet/releases/download/${expectedGitTag}/playlet.zip` -shell.exec(`curl --fail -L -o release/playlet.zip "${zipUrl}"`); - -// sign the package -shell.exec('node tools/sign-package.js'); diff --git a/tools/squash-fs.js b/tools/squash-fs.js new file mode 100644 index 00000000..77949b70 --- /dev/null +++ b/tools/squash-fs.js @@ -0,0 +1,41 @@ +const shell = require('shelljs'); +const { ArgumentParser } = require('argparse') + +if (!shell.which('unzip')) { + shell.echo('Sorry, this script requires unzip'); + shell.exit(1); +} + +if (!shell.which('mksquashfs')) { + shell.echo('Sorry, this script requires mksquashfs'); + shell.exit(1); +} + +const parser = new ArgumentParser({ + description: 'Convert a zip file to a squashfs file' +}); + +parser.add_argument('--in-file', { help: 'A zip file to squash' }); +parser.add_argument('--out-file', { help: 'A squashfs file to create' }); + +const args = parser.parse_args(); + +const inFile = args.in_file; +const outFile = args.out_file; + +const fs = require('fs'); + +const { execSync } = require('child_process'); + +// Create a temporary directory +const tempDir = fs.mkdtempSync('squash-fs-'); + +// Unzip the file +execSync(`unzip ${inFile} -d ${tempDir}`); + +execSync(`mksquashfs ${tempDir} ${outFile} -force-uid 500 -force-gid 500 -comp zstd -b 32768 -Xcompression-level 22`); + +// Remove the temporary directory +execSync(`rm -rf ${tempDir}`); + +console.log(`Created squashfs file: ${outFile}`); \ No newline at end of file