[mv3] Add GitHub action to build mv3 separately form uBO

This commit is contained in:
Raymond Hill 2022-09-19 11:08:34 -04:00
parent 6041757c3d
commit adb5d503d9
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
5 changed files with 91 additions and 52 deletions

View file

@ -45,18 +45,6 @@ jobs:
tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }} tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }}
tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }} tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }}
tools/make-npm.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 - name: Upload Chromium package
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:
@ -93,12 +81,3 @@ jobs:
asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz
asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz
asset_content_type: application/octet-stream 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

56
.github/workflows/mv3.yml vendored Normal file
View file

@ -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

View file

@ -31,7 +31,7 @@ import { parsedURLromOrigin } from './utils.js';
/******************************************************************************/ /******************************************************************************/
const CSS_TYPE = '0'; const CSS_TYPE = '0'; // jshint ignore:line
const JS_TYPE = '1'; const JS_TYPE = '1';
/******************************************************************************/ /******************************************************************************/
@ -108,16 +108,9 @@ const toRegisterable = (fname, entry) => {
if ( entry.excludeMatches ) { if ( entry.excludeMatches ) {
directive.excludeMatches = matchesFromHostnames(entry.excludeMatches); directive.excludeMatches = matchesFromHostnames(entry.excludeMatches);
} }
if ( fname.at(-1) === CSS_TYPE ) { directive.js = [ `/rulesets/js/${fname.slice(0,1)}/${fname.slice(1)}.js` ];
directive.js = [ directive.runAt = 'document_start';
`/rulesets/css/${fname.slice(0,1)}/${fname.slice(1)}.js`, if ( fname.at(-1) === JS_TYPE ) {
];
directive.runAt = 'document_start';
} else if ( fname.at(-1) === JS_TYPE ) {
directive.js = [
`/rulesets/js/${fname}.js`
];
directive.runAt = 'document_start';
directive.world = 'MAIN'; directive.world = 'MAIN';
} }

View file

@ -54,7 +54,6 @@ const commandLineArgs = (( ) => {
const outputDir = commandLineArgs.get('output') || '.'; const outputDir = commandLineArgs.get('output') || '.';
const cacheDir = `${outputDir}/../mv3-data`; const cacheDir = `${outputDir}/../mv3-data`;
const rulesetDir = `${outputDir}/rulesets`; const rulesetDir = `${outputDir}/rulesets`;
const cssDir = `${rulesetDir}/css`;
const scriptletDir = `${rulesetDir}/js`; const scriptletDir = `${rulesetDir}/js`;
const env = [ 'chromium', 'ubol' ]; 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 ) { for ( let i = 0; i < cssContentArray.length; i += contentPerFile ) {
const slice = cssContentArray.slice(i, i + contentPerFile); const slice = cssContentArray.slice(i, i + contentPerFile);
@ -481,8 +480,8 @@ async function processCosmeticFilters(assetDetails, mapin) {
const fname = uid(patchedScriptlet) + '0'; const fname = uid(patchedScriptlet) + '0';
if ( globalPatchedScriptletsSet.has(fname) === false ) { if ( globalPatchedScriptletsSet.has(fname) === false ) {
globalPatchedScriptletsSet.add(fname); globalPatchedScriptletsSet.add(fname);
writeFile(`${cssDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {}); writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {});
distinctResourceCount += 1; generatedFiles.push(fname);
} }
for ( const entry of slice ) { for ( const entry of slice ) {
addScriptingAPIResources( 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(), y: new Set(),
n: new Set(), n: new Set(),
}; };
argsDetails.set(argsHash, hostnamesDetails);
} }
argsDetails.set(argsHash, hostnamesDetails);
if ( entry.matches ) { if ( entry.matches ) {
for ( const hn of entry.matches ) { for ( const hn of entry.matches ) {
hostnamesDetails.y.add(hn); hostnamesDetails.y.add(hn);
@ -589,7 +593,7 @@ async function processScriptletFilters(assetDetails, mapin) {
} }
} }
let distinctResourceCount = 0; const generatedFiles = [];
const jsonReplacer = (k, v) => { const jsonReplacer = (k, v) => {
if ( k === 'n' ) { if ( k === 'n' ) {
@ -637,8 +641,8 @@ async function processScriptletFilters(assetDetails, mapin) {
const fname = uid(patchedScriptlet) + '1'; const fname = uid(patchedScriptlet) + '1';
if ( globalPatchedScriptletsSet.has(fname) === false ) { if ( globalPatchedScriptletsSet.has(fname) === false ) {
globalPatchedScriptletsSet.add(fname); globalPatchedScriptletsSet.add(fname);
writeFile(`${scriptletDir}/${fname}.js`, patchedScriptlet, {}); writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {});
distinctResourceCount += 1; generatedFiles.push(fname);
} }
for ( const details of argsDetails.values() ) { for ( const details of argsDetails.values() ) {
addScriptingAPIResources( 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;
} }
/******************************************************************************/ /******************************************************************************/

View file

@ -4,9 +4,9 @@
set -e 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 if [ "$1" != "quick" ]; then
rm -rf $DES rm -rf $DES
@ -21,7 +21,7 @@ mkdir -p $DES/css/fonts
mkdir -p $DES/js mkdir -p $DES/js
mkdir -p $DES/img 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 -R src/css/fonts/* $DES/css/fonts/
cp src/css/themes/default.css $DES/css/ cp src/css/themes/default.css $DES/css/
cp src/css/common.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/ 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/*.html $DES/
cp platform/mv3/extension/css/* $DES/css/ cp platform/mv3/extension/css/* $DES/css/
cp platform/mv3/extension/js/* $DES/js/ 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/ cp -R platform/mv3/extension/_locales $DES/
if [ "$1" != "quick" ]; then if [ "$1" != "quick" ]; then
echo "*** uBlock0.mv3: Generating rulesets" echo "*** uBOLite.mv3: Generating rulesets"
TMPDIR=$(mktemp -d) TMPDIR=$(mktemp -d)
mkdir -p $TMPDIR mkdir -p $TMPDIR
cp platform/mv3/extension/manifest.json $DES/ cp platform/mv3/extension/manifest.json $DES/
@ -57,12 +57,12 @@ if [ "$1" != "quick" ]; then
rm -rf $TMPDIR rm -rf $TMPDIR
fi fi
echo "*** uBlock0.mv3: extension ready" echo "*** uBOLite.mv3: extension ready"
echo "Extension location: $DES/" echo "Extension location: $DES/"
if [ "$1" = "full" ]; then if [ "$1" = "full" ]; then
echo "*** uBlock0.mv3: Creating webstore package..." echo "*** uBOLite.mv3: Creating webstore package..."
PACKAGENAME=uBlock0_$(jq -r .version $DES/manifest.json).mv3.zip PACKAGENAME=uBOLite_$(jq -r .version $DES/manifest.json).mv3.zip
TMPDIR=$(mktemp -d) TMPDIR=$(mktemp -d)
mkdir -p $TMPDIR mkdir -p $TMPDIR
cp -R $DES/* $TMPDIR/ cp -R $DES/* $TMPDIR/