Add production build split and HACS release workflows

This commit is contained in:
2025-12-18 20:29:33 +10:00
parent 4fd97e6ed8
commit 5654fd2a36
7 changed files with 96 additions and 19 deletions
+33
View File
@@ -0,0 +1,33 @@
name: Build and Upload Release
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Build Card (Production)
run: |
chmod +x run.sh
./run.sh build npm prod
- name: Show dist contents (sanity check)
run: ls -la dist || true
- name: Upload build to release
uses: softprops/action-gh-release@v2
with:
files: dist/**
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+23
View File
@@ -0,0 +1,23 @@
name: HACS Validation
on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
permissions: {}
jobs:
validate-hacs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: HACS validation
uses: "hacs/action@main"
with:
category: "plugin"
+2 -1
View File
@@ -18,5 +18,6 @@ COPY src/ ./src/
# Default command: run the build # Default command: run the build
# This ensures the build runs when the container starts, not during image creation # This ensures the build runs when the container starts, not during image creation
CMD ["npm", "run", "build"] # Use BUILD_TARGET to allow running "watch" or other scripts
CMD ["sh", "-c", "npm run ${BUILD_TARGET:-build}"]
+1
View File
@@ -35,6 +35,7 @@
"@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6", "@rollup/plugin-typescript": "^11.1.6",
"rollup": "^2.79.1", "rollup": "^2.79.1",
"rollup-plugin-terser": "^7.0.2",
"typescript": "~5.3.3" "typescript": "~5.3.3"
}, },
"scripts": { "scripts": {
+10
View File
@@ -1,12 +1,16 @@
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'; import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript'; import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
const isProd = process.env.NODE_ENV === 'production';
export default { export default {
input: 'src/bom-local-radar-card.ts', input: 'src/bom-local-radar-card.ts',
output: { output: {
file: 'dist/bom-local-radar-card.js', file: 'dist/bom-local-radar-card.js',
format: 'es', format: 'es',
sourcemap: !isProd,
}, },
onwarn(warning, warn) { onwarn(warning, warn) {
if (warning.code === 'THIS_IS_UNDEFINED') { if (warning.code === 'THIS_IS_UNDEFINED') {
@@ -21,6 +25,12 @@ export default {
commonjs(), commonjs(),
typescript({ typescript({
tsconfig: './tsconfig.json', tsconfig: './tsconfig.json',
declaration: false,
}),
isProd && terser({
output: {
comments: false,
},
}), }),
], ],
// Dependencies are bundled (not external) so the card works in HA // Dependencies are bundled (not external) so the card works in HA
+19 -7
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Main entry point - works with or without npm # Main entry point - works with or without npm
# Usage: ./run.sh [build|test|clean] [docker] # Usage: ./run.sh [build|test|clean] [docker|npm] [prod]
set -e set -e
@@ -9,13 +9,20 @@ cd "$SCRIPT_DIR"
COMMAND="${1:-test}" COMMAND="${1:-test}"
BUILD_METHOD="${2:-}" BUILD_METHOD="${2:-}"
BUILD_TARGET="${3:-}"
# Build function - handles both npm and Docker # Build function - handles both npm and Docker
build_card() { build_card() {
local method="$1" local method="$1"
local target="$2"
# Auto-detect if not specified # Auto-detect if not specified
if [ -z "$method" ]; then if [ -z "$method" ] || [ "$method" = "prod" ]; then
# If the second arg was "prod", treat it as the target and auto-detect method
if [ "$method" = "prod" ]; then
target="prod"
fi
if command -v docker &> /dev/null; then if command -v docker &> /dev/null; then
method="docker" method="docker"
elif command -v npm &> /dev/null; then elif command -v npm &> /dev/null; then
@@ -27,16 +34,21 @@ build_card() {
fi fi
fi fi
# Set NODE_ENV for production builds
if [ "$target" = "prod" ]; then
export NODE_ENV=production
fi
if [ "$method" = "docker" ]; then if [ "$method" = "docker" ]; then
echo "🐳 Building with Docker..." echo "🐳 Building with Docker ($target)..."
if ! command -v docker &> /dev/null; then if ! command -v docker &> /dev/null; then
echo "❌ Error: docker not found" echo "❌ Error: docker not found"
exit 1 exit 1
fi fi
# Pass FORCE_REBUILD if set # Pass FORCE_REBUILD if set
FORCE_REBUILD="${FORCE_REBUILD:-0}" bash scripts/build-docker.sh FORCE_REBUILD="${FORCE_REBUILD:-0}" NODE_ENV="$NODE_ENV" bash scripts/build-docker.sh
else else
echo "🔨 Building with npm..." echo "🔨 Building with npm ($target)..."
if ! command -v npm &> /dev/null; then if ! command -v npm &> /dev/null; then
echo "❌ Error: npm not found" echo "❌ Error: npm not found"
echo " Install Node.js/npm or use: ./run.sh build docker" echo " Install Node.js/npm or use: ./run.sh build docker"
@@ -48,7 +60,7 @@ build_card() {
npm install npm install
fi fi
npm run build NODE_ENV="$NODE_ENV" npm run build
fi fi
} }
@@ -179,7 +191,7 @@ update_card() {
case "$COMMAND" in case "$COMMAND" in
build) build)
build_card "$BUILD_METHOD" build_card "$BUILD_METHOD" "$BUILD_TARGET"
;; ;;
test) test)
./scripts/test.sh ./scripts/test.sh
+8 -11
View File
@@ -38,18 +38,15 @@ fi
# Run the build container and copy file out # Run the build container and copy file out
echo "🔨 Running build..." echo "🔨 Running build..."
CONTAINER_ID=$(docker create bom-local-card-builder) # Pass NODE_ENV through to the container if set
docker start -a "$CONTAINER_ID" ENV_ARGS=""
if [ -n "$NODE_ENV" ]; then
echo " Setting NODE_ENV=$NODE_ENV"
ENV_ARGS="-e NODE_ENV=$NODE_ENV"
fi
# Ensure dist directory exists # Run the container (using volume for dist to get the output)
mkdir -p dist docker run --rm $ENV_ARGS -v "$(pwd)/dist:/build/dist" bom-local-card-builder
# Copy the built file from container
echo "📋 Copying built file from container..."
docker cp "$CONTAINER_ID:/build/dist/bom-local-radar-card.js" dist/bom-local-radar-card.js
# Remove the container
docker rm "$CONTAINER_ID" > /dev/null
# Check if build succeeded # Check if build succeeded
if [ ! -f "dist/bom-local-radar-card.js" ]; then if [ ! -f "dist/bom-local-radar-card.js" ]; then