Skip to content

Commit e5bccf9

Browse files
committed
Set up uploading source maps to github pages
1 parent bf68ce1 commit e5bccf9

File tree

3 files changed

+91
-9
lines changed

3 files changed

+91
-9
lines changed

.github/workflows/release.yml

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ jobs:
1212

1313
steps:
1414
# Initialization
15-
- uses: actions/checkout@v4
15+
- name: Checkout release branch w/submodules
16+
uses: actions/checkout@v5
1617
with:
1718
submodules: recursive
19+
- name: Checkout source maps branch
20+
uses: actions/checkout@v5
21+
with:
22+
path: source-maps
23+
ref: source-maps
24+
- name: Set up committer info
25+
run: |
26+
git config --global user.name "github-actions[bot]"
27+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
1828
- uses: actions/setup-node@v4
1929
with:
2030
node-version: '18'
@@ -38,8 +48,14 @@ jobs:
3848

3949
# Create Firefox artifacts
4050
- name: Create Firefox artifacts
41-
run: npm run build:firefox
51+
run: npm run build:firefox -- --env ghpSourceMaps
4252
- run: mkdir ./builds
53+
- name: Move Firefox source maps to source map repo
54+
run: |
55+
VERSION=`jq -r '.version' ./dist/manifest.json`
56+
mkdir -p "./source-maps/firefox/$VERSION/"
57+
mv -v ./dist/**/*.js.map "./source-maps/firefox/$VERSION/"
58+
cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/firefox/$VERSION/"
4359
- name: Zip Artifacts
4460
run: cd ./dist ; zip -r ../builds/FirefoxExtension.zip *
4561
- name: Upload FirefoxExtension to release
@@ -52,7 +68,13 @@ jobs:
5268

5369
# Create Chrome artifacts
5470
- name: Create Chrome artifacts
55-
run: npm run build:chrome
71+
run: npm run build:chrome -- --env ghpSourceMaps
72+
- name: Move Chrome source maps to source map repo
73+
run: |
74+
VERSION=`jq -r '.version' ./dist/manifest.json`
75+
mkdir -p "./source-maps/chrome/$VERSION/"
76+
mv -v ./dist/**/*.js.map "./source-maps/chrome/$VERSION/"
77+
cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/chrome/$VERSION/"
5678
- name: Zip Artifacts
5779
run: cd ./dist ; zip -r ../builds/ChromeExtension.zip *
5880
- name: Upload ChromeExtension to release
@@ -67,7 +89,13 @@ jobs:
6789
- name: Clear dist for Edge
6890
run: rm -rf ./dist
6991
- name: Create Edge artifacts
70-
run: npm run build:edge
92+
run: npm run build:edge -- --env ghpSourceMaps
93+
- name: Move Edge source maps to source map repo
94+
run: |
95+
VERSION=`jq -r '.version' ./dist/manifest.json`
96+
mkdir -p "./source-maps/edge/$VERSION/"
97+
mv -v ./dist/**/*.js.map "./source-maps/edge/$VERSION/"
98+
cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/edge/$VERSION/"
7199
- name: Zip Artifacts
72100
run: cd ./dist ; zip -r ../builds/EdgeExtension.zip *
73101
- name: Upload EdgeExtension to release
@@ -80,7 +108,13 @@ jobs:
80108

81109
# Create Safari artifacts
82110
- name: Create Safari artifacts
83-
run: npm run build:safari
111+
run: npm run build:safari -- --env ghpSourceMaps
112+
- name: Move Safari source maps to source map repo
113+
run: |
114+
VERSION=`jq -r '.version' ./dist/manifest.json`
115+
mkdir -p "./source-maps/safari/$VERSION/"
116+
mv -v ./dist/**/*.js.map "./source-maps/safari/$VERSION/"
117+
cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/safari/$VERSION/"
84118
- name: Zip Artifacts
85119
run: cd ./dist ; zip -r ../builds/SafariExtension.zip *
86120
- name: Upload SafariExtension to release
@@ -93,7 +127,13 @@ jobs:
93127

94128
# Create Beta artifacts (Builds with the name changed to beta)
95129
- name: Create Chrome Beta artifacts
96-
run: npm run build:chrome -- --env stream=beta
130+
run: npm run build:chrome -- --env stream=beta --env ghpSourceMaps
131+
- name: Move Chrome Beta source maps to source map repo
132+
run: |
133+
VERSION=`jq -r '.version' ./dist/manifest.json`
134+
mkdir -p "./source-maps/chrome-beta/$VERSION/"
135+
mv -v ./dist/**/*.js.map "./source-maps/chrome-beta/$VERSION/"
136+
cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/chrome-beta/$VERSION/"
97137
- name: Zip Artifacts
98138
run: cd ./dist ; zip -r ../builds/ChromeExtensionBeta.zip *
99139
- name: Upload ChromeExtensionBeta to release
@@ -106,11 +146,17 @@ jobs:
106146

107147
# Firefox Beta
108148
- name: Create Firefox Beta artifacts
109-
run: npm run build:firefox -- --env stream=beta --env autoupdate
149+
run: npm run build:firefox -- --env stream=beta --env autoupdate --env ghpSourceMaps
110150
- uses: actions/upload-artifact@v4
111151
with:
112152
name: FirefoxExtensionBeta
113153
path: dist
154+
- name: Move Firefox Beta source maps to source map repo
155+
run: |
156+
VERSION=`jq -r '.version' ./dist/manifest.json`
157+
mkdir -p "./source-maps/firefox-beta/$VERSION/"
158+
mv -v ./dist/**/*.js.map "./source-maps/firefox-beta/$VERSION/"
159+
cp -v ./dist/**/*.js.LICENSE.txt "./source-maps/firefox-beta/$VERSION/"
114160
- name: Zip Artifacts
115161
run: cd ./dist ; zip -r ../builds/FirefoxExtensionBeta.zip *
116162

@@ -135,11 +181,21 @@ jobs:
135181
path: ./web-ext-artifacts/FirefoxSignedInstaller.xpi
136182
repo-token: ${{ secrets.GITHUB_TOKEN }}
137183

184+
- name: Commit & push new source maps
185+
if: always()
186+
run: |
187+
VERSION=`jq -r '.version' ./dist/manifest.json`
188+
cd ./source-maps
189+
git add .
190+
git commit -m "Publish source maps for version $VERSION"
191+
git push
192+
138193
- name: Prepare new github pages deployment
139194
shell: python
140195
run: |
141196
from pathlib import Path
142197
import json
198+
import shutil
143199
import os
144200
145201
# config stuff
@@ -176,6 +232,13 @@ jobs:
176232
}
177233
(ghp_dir / "updates.json").write_text(json.dumps(updates))
178234
235+
# copy in source maps
236+
def only_sourcemaps(cur, ls):
237+
if '/' in cur:
238+
return []
239+
return set(ls) - {"chrome", "chrome-beta", "edge", "firefox", "firefox-beta", "safari"}
240+
shutil.copytree("source-maps", ghp_dir, ignore=only_sourcemaps, dirs_exist_ok=True)
241+
179242
- name: Upload new github pages deployment
180243
uses: actions/upload-pages-artifact@v3
181244
with:

webpack/webpack.manifest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class BuildManifest {
4242
apply() {
4343
const distFolder = path.resolve(__dirname, "../dist/");
4444
const distManifestFile = path.resolve(distFolder, "manifest.json");
45+
const [owner, repo_name] = (process.env.GITHUB_REPOSITORY ?? "ajayyy/SponsorBlock").split("/");
4546

4647
// Add missing manifest elements
4748
if (this.options.browser.toLowerCase() === "firefox") {
@@ -66,7 +67,6 @@ class BuildManifest {
6667
}
6768

6869
if (this.options.autoupdate === true && this.options.browser.toLowerCase() === "firefox") {
69-
const [owner, repo_name] = process.env.GITHUB_REPOSITORY.split("/");
7070
manifest.browser_specific_settings.gecko.update_url = `https://${owner.toLowerCase()}.github.io/${repo_name}/updates.json`;
7171
}
7272

webpack/webpack.prod.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const { SourceMapDevToolPlugin } = require('webpack');
23
const { merge } = require('webpack-merge');
34
const common = require('./webpack.common.js');
45

6+
function createGHPSourceMapURL(env) {
7+
const manifest = require("../manifest/manifest.json");
8+
const version = manifest.version;
9+
const [owner, repo_name] = (process.env.GITHUB_REPOSITORY ?? "ajayyy/SponsorBlock").split("/");
10+
return `https://${owner.toLowerCase()}.github.io/${repo_name}/${env.browser}${env.stream === "beta" ? "-beta" : ""}/${version}/`;
11+
}
12+
513
module.exports = env => {
614
let mode = "production";
715
env.mode = mode;
816

917
return merge(common(env), {
1018
mode,
11-
devtool: "source-map",
19+
...(env.ghpSourceMaps
20+
? {
21+
devtool: false,
22+
plugins: [new SourceMapDevToolPlugin({
23+
publicPath: createGHPSourceMapURL(env),
24+
filename: '[file].map[query]',
25+
})],
26+
}
27+
: {
28+
devtool: "source-map",
29+
}
30+
),
1231
});
1332
};

0 commit comments

Comments
 (0)