From adb5d503d98213bfc8e162c817557df5cba06bfd Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 19 Sep 2022 11:08:34 -0400 Subject: [PATCH] [mv3] Add GitHub action to build mv3 separately form uBO --- .github/workflows/main.yml | 21 ------- .github/workflows/mv3.yml | 56 +++++++++++++++++++ .../mv3/extension/js/scripting-manager.js | 15 ++--- platform/mv3/make-rulesets.js | 35 ++++++++---- tools/make-mv3.sh | 16 +++--- 5 files changed, 91 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/mv3.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5363957b..5decfe6fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,18 +45,6 @@ jobs: tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }} tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }} tools/make-npm.sh ${{ steps.release_info.outputs.VERSION }} - - name: Build MV3 packages - run: | - tools/make-mv3.sh full - echo "MV3PACKAGE=$(basename $(ls dist/build/uBlock0_*.mv3.zip))" >> $GITHUB_ENV - cp dist/build/uBlock0.mv3/log.txt dist/chromium-mv3/ - - name: Commit MV3 build log file - # https://github.com/marketplace/actions/github-action-for-committing-changes-to-a-repository - uses: devops-infra/action-commit-push@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - commit_message: Update build log file - target_branch: master - name: Upload Chromium package uses: actions/upload-release-asset@v1 env: @@ -93,12 +81,3 @@ jobs: asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz asset_content_type: application/octet-stream - - name: Upload Chromium MV3 package - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/build/${{ env.MV3PACKAGE }} - asset_name: ${{ env.MV3PACKAGE }} - asset_content_type: application/octet-stream diff --git a/.github/workflows/mv3.yml b/.github/workflows/mv3.yml new file mode 100644 index 000000000..f07814acf --- /dev/null +++ b/.github/workflows/mv3.yml @@ -0,0 +1,56 @@ +name: GitHub CI + +on: workflow_dispatch + +permissions: + contents: read + +# I used the following project as template to get started: +# https://github.com/dessant/search-by-image/blob/master/.github/workflows/ci.yml + +jobs: + build: + permissions: + contents: write # for creating release + name: Build packages + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v3 + with: + persist-credentials: false + - name: Clone uAssets + run: | + git submodule update --depth 1 --init + # https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html + - name: Build uBOLite MV3 packages + run: | + tools/make-mv3.sh full + echo "PACKAGE=$(basename $(ls dist/build/uBOLite_*.mv3.zip))" >> $GITHUB_ENV + echo "TAGNAME=$(basename $(ls dist/build/uBOLite_*.mv3.zip) .mv3.zip)" >> $GITHUB_ENV + cp dist/build/uBOLite.mv3/log.txt dist/chromium-mv3/ + - name: Create GitHub release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag_name: ${{ env.TAGNAME }} + release_name: ${{ env.TAGNAME }} + prerelease: true + - name: Commit uBOLite MV3 build log file + # https://github.com/marketplace/actions/github-action-for-committing-changes-to-a-repository + uses: devops-infra/action-commit-push@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + commit_message: Update build log file + target_branch: master + - name: Upload uBOLite MV3 package + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/build/${{ env.PACKAGE }} + asset_name: ${{ env.PACKAGE }} + asset_content_type: application/octet-stream diff --git a/platform/mv3/extension/js/scripting-manager.js b/platform/mv3/extension/js/scripting-manager.js index ea56f1b0e..f7a0b6b55 100644 --- a/platform/mv3/extension/js/scripting-manager.js +++ b/platform/mv3/extension/js/scripting-manager.js @@ -31,7 +31,7 @@ import { parsedURLromOrigin } from './utils.js'; /******************************************************************************/ -const CSS_TYPE = '0'; +const CSS_TYPE = '0'; // jshint ignore:line const JS_TYPE = '1'; /******************************************************************************/ @@ -108,16 +108,9 @@ const toRegisterable = (fname, entry) => { if ( entry.excludeMatches ) { directive.excludeMatches = matchesFromHostnames(entry.excludeMatches); } - if ( fname.at(-1) === CSS_TYPE ) { - directive.js = [ - `/rulesets/css/${fname.slice(0,1)}/${fname.slice(1)}.js`, - ]; - directive.runAt = 'document_start'; - } else if ( fname.at(-1) === JS_TYPE ) { - directive.js = [ - `/rulesets/js/${fname}.js` - ]; - directive.runAt = 'document_start'; + directive.js = [ `/rulesets/js/${fname.slice(0,1)}/${fname.slice(1)}.js` ]; + directive.runAt = 'document_start'; + if ( fname.at(-1) === JS_TYPE ) { directive.world = 'MAIN'; } diff --git a/platform/mv3/make-rulesets.js b/platform/mv3/make-rulesets.js index 001de8e28..f53aa71ef 100644 --- a/platform/mv3/make-rulesets.js +++ b/platform/mv3/make-rulesets.js @@ -54,7 +54,6 @@ const commandLineArgs = (( ) => { const outputDir = commandLineArgs.get('output') || '.'; const cacheDir = `${outputDir}/../mv3-data`; const rulesetDir = `${outputDir}/rulesets`; -const cssDir = `${rulesetDir}/css`; const scriptletDir = `${rulesetDir}/js`; const env = [ 'chromium', 'ubol' ]; @@ -457,7 +456,7 @@ async function processCosmeticFilters(assetDetails, mapin) { } }; - let distinctResourceCount = 0; + const generatedFiles = []; for ( let i = 0; i < cssContentArray.length; i += contentPerFile ) { const slice = cssContentArray.slice(i, i + contentPerFile); @@ -481,8 +480,8 @@ async function processCosmeticFilters(assetDetails, mapin) { const fname = uid(patchedScriptlet) + '0'; if ( globalPatchedScriptletsSet.has(fname) === false ) { globalPatchedScriptletsSet.add(fname); - writeFile(`${cssDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {}); - distinctResourceCount += 1; + writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {}); + generatedFiles.push(fname); } for ( const entry of slice ) { addScriptingAPIResources( @@ -499,9 +498,14 @@ async function processCosmeticFilters(assetDetails, mapin) { ); } } - log(`CSS entries: ${distinctResourceCount}`); - return distinctResourceCount; + if ( generatedFiles.length !== 0 ) { + log(`CSS-related distinct filters: ${cssContentArray.length} distinct combined selectors`); + log(`CSS-related injectable files: ${generatedFiles.length}`); + log(`\t${generatedFiles}`); + } + + return cssContentArray.length; } /******************************************************************************/ @@ -575,8 +579,8 @@ async function processScriptletFilters(assetDetails, mapin) { y: new Set(), n: new Set(), }; + argsDetails.set(argsHash, hostnamesDetails); } - argsDetails.set(argsHash, hostnamesDetails); if ( entry.matches ) { for ( const hn of entry.matches ) { hostnamesDetails.y.add(hn); @@ -589,7 +593,7 @@ async function processScriptletFilters(assetDetails, mapin) { } } - let distinctResourceCount = 0; + const generatedFiles = []; const jsonReplacer = (k, v) => { if ( k === 'n' ) { @@ -637,8 +641,8 @@ async function processScriptletFilters(assetDetails, mapin) { const fname = uid(patchedScriptlet) + '1'; if ( globalPatchedScriptletsSet.has(fname) === false ) { globalPatchedScriptletsSet.add(fname); - writeFile(`${scriptletDir}/${fname}.js`, patchedScriptlet, {}); - distinctResourceCount += 1; + writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {}); + generatedFiles.push(fname); } for ( const details of argsDetails.values() ) { addScriptingAPIResources( @@ -655,9 +659,16 @@ async function processScriptletFilters(assetDetails, mapin) { ); } } - log(`Scriptlet entries: ${distinctResourceCount}`); - return distinctResourceCount; + if ( generatedFiles.length !== 0 ) { + const scriptletFilterCount = Array.from(scriptletDetails.values()) + .reduce((a, b) => a + b.size, 0); + log(`Scriptlet-related distinct filters: ${scriptletFilterCount}`); + log(`Scriptlet-related injectable files: ${generatedFiles.length}`); + log(`\t${generatedFiles}`); + } + + return generatedFiles.length; } /******************************************************************************/ diff --git a/tools/make-mv3.sh b/tools/make-mv3.sh index 24f563a53..9ef0ac08c 100755 --- a/tools/make-mv3.sh +++ b/tools/make-mv3.sh @@ -4,9 +4,9 @@ set -e -echo "*** uBlock0.mv3: Creating extension" +echo "*** uBOLite.mv3: Creating extension" -DES="dist/build/uBlock0.mv3" +DES="dist/build/uBOLite.mv3" if [ "$1" != "quick" ]; then rm -rf $DES @@ -21,7 +21,7 @@ mkdir -p $DES/css/fonts mkdir -p $DES/js mkdir -p $DES/img -echo "*** uBlock0.mv3: Copying common files" +echo "*** uBOLite.mv3: Copying common files" cp -R src/css/fonts/* $DES/css/fonts/ cp src/css/themes/default.css $DES/css/ cp src/css/common.css $DES/css/ @@ -34,7 +34,7 @@ cp src/js/i18n.js $DES/js/ cp LICENSE.txt $DES/ -echo "*** uBlock0.mv3: Copying mv3-specific files" +echo "*** uBOLite.mv3: Copying mv3-specific files" cp platform/mv3/extension/*.html $DES/ cp platform/mv3/extension/css/* $DES/css/ cp platform/mv3/extension/js/* $DES/js/ @@ -42,7 +42,7 @@ cp platform/mv3/extension/img/* $DES/img/ cp -R platform/mv3/extension/_locales $DES/ if [ "$1" != "quick" ]; then - echo "*** uBlock0.mv3: Generating rulesets" + echo "*** uBOLite.mv3: Generating rulesets" TMPDIR=$(mktemp -d) mkdir -p $TMPDIR cp platform/mv3/extension/manifest.json $DES/ @@ -57,12 +57,12 @@ if [ "$1" != "quick" ]; then rm -rf $TMPDIR fi -echo "*** uBlock0.mv3: extension ready" +echo "*** uBOLite.mv3: extension ready" echo "Extension location: $DES/" if [ "$1" = "full" ]; then - echo "*** uBlock0.mv3: Creating webstore package..." - PACKAGENAME=uBlock0_$(jq -r .version $DES/manifest.json).mv3.zip + echo "*** uBOLite.mv3: Creating webstore package..." + PACKAGENAME=uBOLite_$(jq -r .version $DES/manifest.json).mv3.zip TMPDIR=$(mktemp -d) mkdir -p $TMPDIR cp -R $DES/* $TMPDIR/