ci: switch to static site deployment via Gitea Pages
Build and Deploy / build-and-deploy (push) Failing after 54s
Build and Deploy / build-and-deploy (push) Failing after 54s
- Replaced Docker image build/push with static site publishing using peaceiris/actions-gh-pages. - Updated Vite configuration to use /lit-examples/ as the base path. - Enhanced mpaHtmlPlugin to correctly prefix assets with the base path in subfolders. - Updated CI permissions to allow content writing for deployment.
This commit is contained in:
@@ -15,7 +15,7 @@ jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
@@ -43,34 +43,11 @@ jobs:
|
||||
run: bazel build //...
|
||||
|
||||
- name: Build Site
|
||||
run: pnpm run build
|
||||
run: pnpm run build --base=/lit-examples/
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to registry
|
||||
uses: docker/login-action@v4
|
||||
- name: Deploy Docs
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.GIT_TOKEN }}
|
||||
|
||||
- name: Get image metadata
|
||||
id: meta
|
||||
run: |
|
||||
NAME=$(node -p "require('./package.json').name.toLowerCase()")
|
||||
OWNER=$(echo "${{ gitea.actor }}" | tr '[:upper:]' '[:lower:]')
|
||||
echo "name=${NAME}" >> $GITHUB_OUTPUT
|
||||
echo "owner=${OWNER}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ steps.meta.outputs.owner }}/${{ steps.meta.outputs.name }}:latest
|
||||
${{ env.REGISTRY }}/${{ steps.meta.outputs.owner }}/${{ steps.meta.outputs.name }}:${{ github.sha }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
force_orphan: true
|
||||
publish_dir: dist
|
||||
|
||||
+6
-4
@@ -42,7 +42,7 @@ function getHtmlEntries() {
|
||||
}
|
||||
|
||||
// Vite plugin to rewrite HTML absolute assets to be subfolder-scoped
|
||||
const mpaHtmlPlugin = () => {
|
||||
const mpaHtmlPlugin = (base = '/') => {
|
||||
return {
|
||||
name: 'mpa-html-plugin',
|
||||
transformIndexHtml: {
|
||||
@@ -53,7 +53,7 @@ const mpaHtmlPlugin = () => {
|
||||
const subfolder = parts[0];
|
||||
|
||||
let transformed = html
|
||||
// Rewrite absolute src/href paths like "/src/main.ts" to "/subfolder/src/main.ts"
|
||||
// Rewrite absolute src/href paths like "/src/main.ts" to "/base/subfolder/src/main.ts"
|
||||
.replace(/(src|href)="\/([^"]+)"/g, (match, attr, path) => {
|
||||
if (path.startsWith('http://') || path.startsWith('https://')) {
|
||||
return match;
|
||||
@@ -61,7 +61,8 @@ const mpaHtmlPlugin = () => {
|
||||
if (path.startsWith(subfolder)) {
|
||||
return match;
|
||||
}
|
||||
return `${attr}="/${subfolder}/${path}"`;
|
||||
const prefix = base === '/' ? '' : base.replace(/\/$/, '');
|
||||
return `${attr}="${prefix}/${subfolder}/${path}"`;
|
||||
});
|
||||
|
||||
// Clean up platform-specific non-module scripts like capacitor.js which fail Vite build
|
||||
@@ -156,7 +157,8 @@ const externalizeMissingPlugin = () => {
|
||||
};
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [mpaHtmlPlugin(), tsResolvePlugin(), externalizeMissingPlugin()],
|
||||
base: '/lit-examples/',
|
||||
plugins: [mpaHtmlPlugin('/lit-examples/'), tsResolvePlugin(), externalizeMissingPlugin()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'lit/decorators': 'lit/decorators.js',
|
||||
|
||||
Reference in New Issue
Block a user