Skip to content

Commit 5c77f37

Browse files
committed
ci: add web cache version build script automation
1 parent 8ba3d92 commit 5c77f37

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

.github/workflows/patch-version-bump.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
add-paths: |
3737
package.json
3838
src/config.json
39+
src-node/package.json
40+
src/index.html
3941
body: |
4042
Bump patch version to ${{ env.PHOENIX_VERSION }}
4143
- Auto-generated by `patch-version-bump.yml` action

.github/workflows/yearly-major-version-bump.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
add-paths: |
3434
package.json
3535
src/config.json
36+
src-node/package.json
37+
src/index.html
3638
body: |
3739
Bump patch version to ${{ env.PHOENIX_VERSION }}
3840
- Auto-generated by `patch-version-bump.yml` action

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test/thirdparty/jasmine-reporters
5656

5757
# ignore compiled files
5858
/dist
59+
/dist-web-cache
5960
/dist-test
6061
/distToDeploy
6162
/src/.index.html

gulpfile.js/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ function makeDistNonJS() {
100100
.pipe(dest('dist'));
101101
}
102102

103+
function makeDistWebCache() {
104+
return new Promise((resolve)=> {
105+
fs.rmSync("./dist/web-cache", {recursive: true, force: true});
106+
fs.rmSync("./dist-web-cache", {recursive: true, force: true});
107+
fs.cpSync("./dist", "./dist-web-cache", {
108+
recursive: true,
109+
force: true
110+
});
111+
let config = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
112+
fs.mkdirSync("./dist/web-cache");
113+
fs.renameSync("./dist-web-cache", `./dist/web-cache/${config.apiVersion}`);
114+
resolve();
115+
});
116+
}
117+
103118
function serve() {
104119
return src('.')
105120
.pipe(webserver({
@@ -184,20 +199,38 @@ function _majorVersionBumpConfigFile(fileName) {
184199
fs.writeFileSync(fileName, JSON.stringify(config, null, 4));
185200
}
186201

202+
function _patchIndexHTML() {
203+
let indexHtmlPath = './src/index.html';
204+
let config = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
205+
let indexHTML = fs.readFileSync(indexHtmlPath, 'utf8');
206+
let version = config.apiVersion;
207+
const replaceStr = '<script>window.PHOENIX_APP_CACHE_VERSION="LATEST";</script>';
208+
if(!indexHTML.includes(replaceStr)){
209+
throw new Error("Expected index.html to include "+ replaceStr);
210+
}
211+
indexHTML = indexHTML.replace(replaceStr,
212+
`<script>window.PHOENIX_APP_CACHE_VERSION="${version}";</script>`);
213+
fs.writeFileSync(indexHtmlPath, indexHTML);
214+
}
215+
187216
function patchVersionBump() {
217+
// adding anything here should be added to patch-version-bump.yml and yearly-major-version-bump.yml
188218
return new Promise((resolve)=> {
189219
_patchBumpConfigFile('./package.json');
190220
_patchBumpConfigFile('./src-node/package.json');
191221
_patchBumpConfigFile('./src/config.json');
222+
_patchIndexHTML();
192223
resolve();
193224
});
194225
}
195226

196227
function majorVersionBump() {
228+
// adding anything here should be added to patch-version-bump.yml and yearly-major-version-bump.yml
197229
return new Promise((resolve)=> {
198230
_majorVersionBumpConfigFile('./package.json');
199231
_majorVersionBumpConfigFile('./src-node/package.json');
200232
_majorVersionBumpConfigFile('./src/config.json');
233+
_patchIndexHTML();
201234
resolve();
202235
});
203236
}
@@ -636,6 +669,7 @@ exports.releaseStaging = series(cleanDist, exports.build, makeBracketsConcatJS,
636669
exports.releaseProd = series(cleanDist, exports.build, makeBracketsConcatJS, _compileLessSrc,
637670
makeDistNonJS, makeJSDist, _renameBracketsConcatAsBracketsJSInDist, _patchMinifiedCSSInDistIndex, releaseProd,
638671
createDistCacheManifest, createDistTest, _cleanReleaseBuildArtefactsInSrc);
672+
exports.releaseWebCache = series(makeDistWebCache);
639673
exports.serve = series(exports.build, serve);
640674
exports.zipTestFiles = series(zipTestFiles);
641675
exports.serveExternal = series(exports.build, serveExternal);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@
6767
"release:dev": "gulp releaseDev",
6868
"release:staging": "gulp releaseStaging",
6969
"release:prod": "gulp releaseProd",
70+
"_releaseWebCache": "gulp releaseWebCache",
7071
"_patchVersionBump": "gulp patchVersionBump",
7172
"_majorVersionBump": "gulp majorVersionBump",
7273
"serve": "http-server . -p 8000 -c-1",
7374
"serveWithWebCache": "http-server ./src -p 8000 -c-1",
74-
"serveExternal": "http-server . -p 8000 -a 0.0.0.0 --log-ip true -c-1",
75+
"serveExternal": "npm run _releaseWebCache && http-server . -p 8000 -a 0.0.0.0 --log-ip true -c-1",
7576
"createJSDocs": "gulp createJSDocs && git add docs",
7677
"_translateStrings": "gulp translateStrings",
7778
"_minify": "r.js -o require.min.config.js && echo this is untested see https://stackoverflow.com/questions/14337970/minifying-requirejs-javascript-codebase-to-a-single-file"

src/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
</style>
4949
<!-- start inline javascript and non module bootstrap scripts. you must add module scripts to the
5050
javascript module section only!!-->
51+
<!-- The app cache version is set by the pipeline version update script. Do not update manually.-->
52+
<script>window.PHOENIX_APP_CACHE_VERSION="LATEST";</script>
53+
<!-- The app cache version is set by the pipeline version update script. Do not update manually.-->
5154
<script>
5255
if(location.href.startsWith("tauri://") || location.href.startsWith('https://tauri.localhost')){
5356
const errorMessage = `You should use custom protocol phtauri:// instead of tauri protocol ${location.href} .`;

0 commit comments

Comments
 (0)