continuwuity/.forgejo/workflows/deploy-element.yml
Tom Foster b481ff31c0
Some checks failed
Checks / Build / Publish / Pre-commit & Formatting (pull_request) Successful in 31s
Deploy / Documentation / Build and Deploy Documentation (pull_request) Successful in 36s
Checks / Build / Publish / Clippy and Cargo Tests (pull_request) Successful in 3m21s
Checks / Build / Publish / Build linux/amd64 (pull_request) Failing after 3m41s
Checks / Build / Publish / Build linux/arm64 (pull_request) Failing after 4m12s
Checks / Build / Publish / Publish Multi-Platform (pull_request) Failing after 0s
ci: Consolidate workflows and optimise build pipeline performance
Merge rust-checks.yml and release-image.yml into unified ci-build.yml
workflow that runs faster and more efficiently. The previous setup ran
4+ parallel jobs immediately (format, clippy, test, builds), causing
resource contention. The new pipeline runs max 2 jobs in parallel at
each stage, catching lint/format issues quickly before attempting
expensive compilation.

Extract all Rust setup logic from both workflows into reusable
rust-with-cache composite action. This replaces 6 separate actions
(rust-toolchain, sccache, timelord, plus inline APT/cache steps) with
a single action that handles:
- Rust toolchain installation with component selection
- Cross-compilation configuration (previously scattered across
  release-image.yml)
- System dependency installation with proper error handling
- Comprehensive caching (sccache, cargo registry, cargo target, uv
  tools)
- Timeline tracking and performance monitoring

The previous release-image.yml had cross-compilation support but it
was implemented inline with complex environment variables. The new
rust-with-cache action centralises this with proper parameters for
pkg-config paths, foreign architecture setup, and toolchain selection.

Performance improvements make the pipeline fast enough to consolidate:
- Warmed sccache cache shared between check and build stages
- Optimised cargo target cache to exclude incremental/ and binaries
  (was caching entire target/ directory via buildkit-cache-dance)
- Add restore-keys fallback for better cache hit rates
- Parallel background tasks for Rust setup while APT runs
- Fail-fast on format/lint errors before expensive compilation
- Enable Haswell CPU optimisations for x86_64 builds (AVX2, FMA, etc.)
- Add cross-language LTO (Link-Time Optimisation) for better performance

Fix ARM64 cross-compilation reliability issues:
- Move APT installations from background to foreground (background
  processes would hang during package downloads despite
  DEBIAN_FRONTEND=noninteractive)
- Set proper pkg-config environment for cross-compilation
- Configure APT sources to ports.ubuntu.com for foreign architectures
- Replace hardened_malloc with jemalloc (ARM64 unsupported)

Modernisation from previous commit (b0ebdb59):
- prefligit renamed to prek (avoid typosquatting)
- Direct uvx rustup replacing custom rust-toolchain action
- Workflow renames: deploy-element, deploy-docs, docker-mirror
- Renovate configuration for .forgejo/ workflows
- fix-byte-order-marker replacing check-byte-order-marker

Docker improvements:
- Remove buildkit-cache-dance injection (now handled natively)
- Align tag naming between arch-specific and multi-platform builds
- Add branch- prefix for non-default branches
- Reserve latest-{arch} tags for version releases only
- Remove dynamic library extraction logic (ldd doesn't work for
  cross-compiled binaries; Rust --release produces mostly-static binaries)

Additional improvements based on maintainer feedback:
- Generate SBOM (Software Bill of Materials) for security compliance
- Include SBOM in uploaded build artefacts alongside binary

The consolidated pipeline completes in ~10 minutes with better
resource utilisation and clearer failure diagnostics. Both x86_64 and
ARM64 builds now work reliably with the centralised cross-compilation
configuration.
2025-08-15 22:50:41 +01:00

124 lines
3.8 KiB
YAML

name: Deploy Element Web
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
concurrency:
group: "element-${{ github.ref }}"
cancel-in-progress: true
jobs:
build-and-deploy:
name: 🏗️ Build and Deploy
runs-on: ubuntu-latest
steps:
- name: 📦 Setup Node.js
uses: https://github.com/actions/setup-node@v4
with:
node-version: "22"
- name: 🔨 Clone, setup, and build Element Web
run: |
echo "Cloning Element Web..."
git clone https://github.com/maunium/element-web
cd element-web
git checkout develop
git pull
echo "Cloning matrix-js-sdk..."
git clone https://github.com/matrix-org/matrix-js-sdk.git
echo "Installing Yarn..."
npm install -g yarn
echo "Installing dependencies..."
yarn install
echo "Preparing build environment..."
mkdir -p .home
echo "Cleaning up specific node_modules paths..."
rm -rf node_modules/@types/eslint-scope/ matrix-*-sdk/node_modules/@types/eslint-scope || echo "Cleanup paths not found, continuing."
echo "Getting matrix-js-sdk commit hash..."
cd matrix-js-sdk
jsver=$(git rev-parse HEAD)
jsver=${jsver:0:12}
cd ..
echo "matrix-js-sdk version hash: $jsver"
echo "Getting element-web commit hash..."
ver=$(git rev-parse HEAD)
ver=${ver:0:12}
echo "element-web version hash: $ver"
chmod +x ./build-sh
export VERSION="$ver-js-$jsver"
echo "Building Element Web version: $VERSION"
./build-sh
echo "Checking for build output..."
ls -la webapp/
- name: ⚙️ Create config.json
run: |
cat <<EOF > ./element-web/webapp/config.json
{
"default_server_name": "continuwuity.org",
"default_server_config": {
"m.homeserver": {
"base_url": "https://matrix.continuwuity.org"
}
},
"default_country_code": "GB",
"default_theme": "dark",
"mobile_guide_toast": false,
"show_labs_settings": true,
"room_directory": [
"continuwuity.org",
"matrixrooms.info"
],
"settings_defaults": {
"UIFeature.urlPreviews": true,
"UIFeature.feedback": false,
"UIFeature.voip": false,
"UIFeature.shareQrCode": false,
"UIFeature.shareSocial": false,
"UIFeature.locationSharing": false,
"enableSyntaxHighlightLanguageDetection": true
},
"features": {
"feature_pinning": true,
"feature_custom_themes": true
}
}
EOF
echo "Created ./element-web/webapp/config.json"
cat ./element-web/webapp/config.json
- name: 📤 Upload Artifact
uses: https://code.forgejo.org/actions/upload-artifact@v3
with:
name: element-web
path: ./element-web/webapp/
retention-days: 14
- name: 🛠️ Install Wrangler
run: npm install --save-dev wrangler@latest
- name: 🚀 Deploy to Cloudflare Pages
if: vars.CLOUDFLARE_PROJECT_NAME != ''
id: deploy
uses: https://github.com/cloudflare/wrangler-action@v3
with:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
command: >-
pages deploy ./element-web/webapp
--branch="${{ github.ref == 'refs/heads/main' && 'main' || github.head_ref || github.ref_name }}"
--commit-dirty=true
--project-name="${{ vars.CLOUDFLARE_PROJECT_NAME }}-element"