diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 83d8c09b..1d009c92 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,9 +12,19 @@ jobs: steps: # Initialization - - uses: actions/checkout@v4 + - name: Checkout release branch w/submodules + uses: actions/checkout@v5 with: submodules: recursive + - name: Checkout source maps branch + uses: actions/checkout@v5 + with: + path: source-maps + ref: source-maps + - name: Set up committer info + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - uses: actions/setup-node@v4 with: node-version: '18' @@ -38,8 +48,14 @@ jobs: # Create Firefox artifacts - name: Create Firefox artifacts - run: npm run build:firefox + run: npm run build:firefox -- --env ghpSourceMaps - run: mkdir ./builds + - name: Move Firefox source maps to source map repo + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + mkdir -p "./source-maps/firefox/$VERSION/" + mv -v ./dist/**/*.js.map "./source-maps/firefox/$VERSION/" + cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/firefox/$VERSION/" - name: Zip Artifacts run: cd ./dist ; zip -r ../builds/FirefoxExtension.zip * - name: Upload FirefoxExtension to release @@ -52,7 +68,13 @@ jobs: # Create Chrome artifacts - name: Create Chrome artifacts - run: npm run build:chrome + run: npm run build:chrome -- --env ghpSourceMaps + - name: Move Chrome source maps to source map repo + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + mkdir -p "./source-maps/chrome/$VERSION/" + mv -v ./dist/**/*.js.map "./source-maps/chrome/$VERSION/" + cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/chrome/$VERSION/" - name: Zip Artifacts run: cd ./dist ; zip -r ../builds/ChromeExtension.zip * - name: Upload ChromeExtension to release @@ -67,7 +89,13 @@ jobs: - name: Clear dist for Edge run: rm -rf ./dist - name: Create Edge artifacts - run: npm run build:edge + run: npm run build:edge -- --env ghpSourceMaps + - name: Move Edge source maps to source map repo + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + mkdir -p "./source-maps/edge/$VERSION/" + mv -v ./dist/**/*.js.map "./source-maps/edge/$VERSION/" + cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/edge/$VERSION/" - name: Zip Artifacts run: cd ./dist ; zip -r ../builds/EdgeExtension.zip * - name: Upload EdgeExtension to release @@ -80,7 +108,13 @@ jobs: # Create Safari artifacts - name: Create Safari artifacts - run: npm run build:safari + run: npm run build:safari -- --env ghpSourceMaps + - name: Move Safari source maps to source map repo + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + mkdir -p "./source-maps/safari/$VERSION/" + mv -v ./dist/**/*.js.map "./source-maps/safari/$VERSION/" + cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/safari/$VERSION/" - name: Zip Artifacts run: cd ./dist ; zip -r ../builds/SafariExtension.zip * - name: Upload SafariExtension to release @@ -93,7 +127,13 @@ jobs: # Create Beta artifacts (Builds with the name changed to beta) - name: Create Chrome Beta artifacts - run: npm run build:chrome -- --env stream=beta + run: npm run build:chrome -- --env stream=beta --env ghpSourceMaps + - name: Move Chrome Beta source maps to source map repo + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + mkdir -p "./source-maps/chrome-beta/$VERSION/" + mv -v ./dist/**/*.js.map "./source-maps/chrome-beta/$VERSION/" + cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/chrome-beta/$VERSION/" - name: Zip Artifacts run: cd ./dist ; zip -r ../builds/ChromeExtensionBeta.zip * - name: Upload ChromeExtensionBeta to release @@ -106,11 +146,17 @@ jobs: # Firefox Beta - name: Create Firefox Beta artifacts - run: npm run build:firefox -- --env stream=beta --env autoupdate + run: npm run build:firefox -- --env stream=beta --env autoupdate --env ghpSourceMaps - uses: actions/upload-artifact@v4 with: name: FirefoxExtensionBeta path: dist + - name: Move Firefox Beta source maps to source map repo + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + mkdir -p "./source-maps/firefox-beta/$VERSION/" + mv -v ./dist/**/*.js.map "./source-maps/firefox-beta/$VERSION/" + cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/firefox-beta/$VERSION/" - name: Zip Artifacts run: cd ./dist ; zip -r ../builds/FirefoxExtensionBeta.zip * @@ -135,11 +181,21 @@ jobs: path: ./web-ext-artifacts/FirefoxSignedInstaller.xpi repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Commit & push new source maps + if: always() + run: | + VERSION=`jq -r '.version' ./dist/manifest.json` + cd ./source-maps + git add . + git commit -m "Publish source maps for version $VERSION" + git push + - name: Prepare new github pages deployment shell: python run: | from pathlib import Path import json + import shutil import os # config stuff @@ -176,6 +232,13 @@ jobs: } (ghp_dir / "updates.json").write_text(json.dumps(updates)) + # copy in source maps + def only_sourcemaps(cur, ls): + if '/' in cur: + return [] + return set(ls) - {"chrome", "chrome-beta", "edge", "firefox", "firefox-beta", "safari"} + shutil.copytree("source-maps", ghp_dir, ignore=only_sourcemaps, dirs_exist_ok=True) + - name: Upload new github pages deployment uses: actions/upload-pages-artifact@v3 with: diff --git a/webpack/webpack.manifest.js b/webpack/webpack.manifest.js index b89bcce5..2b866498 100644 --- a/webpack/webpack.manifest.js +++ b/webpack/webpack.manifest.js @@ -42,6 +42,7 @@ class BuildManifest { apply() { const distFolder = path.resolve(__dirname, "../dist/"); const distManifestFile = path.resolve(distFolder, "manifest.json"); + const [owner, repo_name] = (process.env.GITHUB_REPOSITORY ?? "ajayyy/SponsorBlock").split("/"); // Add missing manifest elements if (this.options.browser.toLowerCase() === "firefox") { @@ -66,7 +67,6 @@ class BuildManifest { } if (this.options.autoupdate === true && this.options.browser.toLowerCase() === "firefox") { - const [owner, repo_name] = process.env.GITHUB_REPOSITORY.split("/"); manifest.browser_specific_settings.gecko.update_url = `https://${owner.toLowerCase()}.github.io/${repo_name}/updates.json`; } diff --git a/webpack/webpack.prod.js b/webpack/webpack.prod.js index 3099c67e..be80faf9 100644 --- a/webpack/webpack.prod.js +++ b/webpack/webpack.prod.js @@ -1,13 +1,32 @@ /* eslint-disable @typescript-eslint/no-var-requires */ +const { SourceMapDevToolPlugin } = require('webpack'); const { merge } = require('webpack-merge'); const common = require('./webpack.common.js'); +function createGHPSourceMapURL(env) { + const manifest = require("../manifest/manifest.json"); + const version = manifest.version; + const [owner, repo_name] = (process.env.GITHUB_REPOSITORY ?? "ajayyy/SponsorBlock").split("/"); + return `https://${owner.toLowerCase()}.github.io/${repo_name}/${env.browser}${env.stream === "beta" ? "-beta" : ""}/${version}/`; +} + module.exports = env => { let mode = "production"; env.mode = mode; return merge(common(env), { mode, - devtool: "source-map", + ...(env.ghpSourceMaps + ? { + devtool: false, + plugins: [new SourceMapDevToolPlugin({ + publicPath: createGHPSourceMapURL(env), + filename: '[file].map[query]', + })], + } + : { + devtool: "source-map", + } + ), }); };