Closed juancho0202 closed 4 months ago
There is a small chance that in the future we can count on an official github-pages solution for this https://github.com/actions/deploy-pages/pull/61
The pull request with the GitHub Action to generate a preview has been already merged:
It currently deploys the wrong folder here: https://github.com/openscd/open-scd/blob/main/.github/workflows/pr-preview.yml#L33
I've already fixed it. It needs to deploy from /packages/distribution/build
.
The next problem is that OpenSCD ist deployed under a path like .../pr-preview/pr-4/
and it should load files from this subfolder but it tries to load the files from the root.
The next step to set a base URL at build time so it loads the correct files.
The solution is make the referenced files' path adjustable.
With snowpack we can set the base URL: buildOptions.baseUrl
Then we can use %PUBLIC_URL%
to reference files:
- <script type="module" src="/main.js"></script>
+ <script type="module" src="%PUBLIC_URL%/main.js"></script>
To change this from the outside we can configure snowpack in snowpack.config.mjs
like this:
buildOptions: {
baseUrl: process.env.PUBLIC_URL || '/',
},
and set the path in when we start the build process eg.:
PUBLIC_URL=open-scd/pr-preview/pr-1 npm run-script build
the reference to built-in plug-ins in plugins.ts
we can figure out dynamically dependent on where OpenSCD is deployed:
const path = location.origin + location.pathname + plugin
The next step is to fix the failing tests, because of the changed plugin paths.
The tests were failing because the pluginIds
in the tests were still relative paths but OpenSCD now generates absolute paths and OpenSCD could not find them in local storage.
The final problem was that GitHub Pages, by default, does not server files from folders that start with _
. It has something to do with jekyll, but it was an easy fix because you can disable jekyll with a .nojekyll
file at root level.
As a stakeholder of the open-scd project I would like to test functional behavior of the PRs in a temporary URL which features a copy of OpenSCD made with the code in the branch of the pull request.
Acceptance Criteria: