All checks were successful
Build Slideshow App / build (amd64, , linux) (push) Successful in 1m24s
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 1m20s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 1m23s
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m26s
190 lines
5.6 KiB
YAML
190 lines
5.6 KiB
YAML
name: Build Slideshow App
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- '*'
|
|
|
|
env:
|
|
APP_NAME: slideshowApp
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- os: windows
|
|
arch: amd64
|
|
ext: .exe
|
|
- os: linux
|
|
arch: amd64
|
|
ext: ""
|
|
- os: linux
|
|
arch: arm64
|
|
ext: ""
|
|
- os: linux
|
|
arch: arm
|
|
arm_version: 7
|
|
ext: ""
|
|
|
|
steps:
|
|
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Ensure latest Go is installed in /data/go
|
|
run: |
|
|
export GOROOT=/data/go/go
|
|
export PATH=$GOROOT/bin:$PATH
|
|
export GOCACHE=/data/gocache
|
|
export GOMODCACHE=/data/gomodcache
|
|
mkdir -p $GOCACHE $GOMODCACHE
|
|
|
|
if [ ! -x "$GOROOT/bin/go" ]; then
|
|
echo "Go not found in $GOROOT, downloading latest stable..."
|
|
|
|
GO_VERSION=$(curl -s https://go.dev/VERSION?m=text | head -n1)
|
|
echo "Latest version is $GO_VERSION"
|
|
|
|
mkdir -p /data/go
|
|
curl -sSL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tar.gz
|
|
tar -C /data/go -xzf /tmp/go.tar.gz
|
|
else
|
|
echo "Using cached Go from $GOROOT"
|
|
fi
|
|
|
|
go version
|
|
|
|
- name: Download Go dependencies
|
|
run: |
|
|
export GOROOT=/data/go/go
|
|
export PATH=$GOROOT/bin:$PATH
|
|
export GOCACHE=/data/gocache
|
|
export GOMODCACHE=/data/gomodcache
|
|
mkdir -p $GOCACHE $GOMODCACHE
|
|
go mod download
|
|
|
|
- name: Build binary
|
|
run: |
|
|
export GOROOT=/data/go/go
|
|
export PATH=$GOROOT/bin:$PATH
|
|
export GOCACHE=/data/gocache
|
|
export GOMODCACHE=/data/gomodcache
|
|
mkdir -p $GOCACHE $GOMODCACHE
|
|
|
|
OUTPUT="${APP_NAME}"
|
|
if [ -n "${{ matrix.arm_version }}" ]; then
|
|
export GOARM=${{ matrix.arm_version }}
|
|
fi
|
|
|
|
OUTPUT="${OUTPUT}${{ matrix.ext }}"
|
|
echo "Building $OUTPUT"
|
|
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
|
|
shell: bash
|
|
|
|
- name: Create Debian Package
|
|
if: matrix.os == 'linux'
|
|
run: |
|
|
# 1. Setup Variables
|
|
VERSION=${GITHUB_REF_NAME#v} # Extracts 1.0.0 from v1.0.0
|
|
ARCH=${{ matrix.arch }}
|
|
if [ "$ARCH" == "arm" ]; then ARCH="armhf"; fi
|
|
|
|
PKG_NAME="slideshowapp"
|
|
BUILD_DIR="${PKG_NAME}_${VERSION}_${ARCH}"
|
|
|
|
# 2. Create Directory Structure
|
|
mkdir -p $BUILD_DIR/usr/bin
|
|
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
|
|
mkdir -p $BUILD_DIR/etc/systemd/system
|
|
mkdir -p $BUILD_DIR/DEBIAN
|
|
|
|
# 3. Copy Files
|
|
cp ${APP_NAME} $BUILD_DIR/usr/bin/$PKG_NAME
|
|
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
|
chmod +x $BUILD_DIR/usr/bin/$PKG_NAME
|
|
|
|
# 4. Handle .env (Copy as a .template so it doesn't overwrite existing ones)
|
|
if [ -f ".env" ]; then
|
|
cp .env $BUILD_DIR/usr/share/$PKG_NAME/.env.template
|
|
else
|
|
echo "PORT=8080" > $BUILD_DIR/usr/share/$PKG_NAME/.env.template
|
|
fi
|
|
|
|
# 5. Create the systemd Service File
|
|
cat <<EOF > $BUILD_DIR/etc/systemd/system/$PKG_NAME.service
|
|
[Unit]
|
|
Description=Slideshow Application Service
|
|
After=graphical.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
Environment=DISPLAY=:0
|
|
Environment=XAUTHORITY=/home/youruser/.Xauthority
|
|
ExecStart=/usr/bin/$PKG_NAME
|
|
WorkingDirectory=/usr/share/$PKG_NAME
|
|
Restart=always
|
|
User=root
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# 6. Create Control File
|
|
cat <<EOF > $BUILD_DIR/DEBIAN/control
|
|
Package: $PKG_NAME
|
|
Version: $VERSION
|
|
Section: utils
|
|
Priority: optional
|
|
Architecture: $ARCH
|
|
Maintainer: Your Name <you@example.com>
|
|
Description: Slideshow Application
|
|
EOF
|
|
|
|
# 7. Optional: Add post-install script to enable service automatically
|
|
echo "create service"
|
|
cat <<EOF > $BUILD_DIR/DEBIAN/postinst
|
|
#!/bin/sh
|
|
# Check if .env exists in the target share folder
|
|
if [ ! -f "/usr/share/$PKG_NAME/.env" ]; then
|
|
echo "Creating new .env from template..."
|
|
cp /usr/share/$PKG_NAME/.env.template /usr/share/$PKG_NAME/.env
|
|
else
|
|
echo ".env already exists, skipping template copy to preserve settings."
|
|
fi
|
|
|
|
echo "reload"
|
|
systemctl daemon-reload
|
|
echo "enable service"
|
|
systemctl enable $PKG_NAME.service
|
|
echo "start service"
|
|
systemctl start $PKG_NAME.service
|
|
EOF
|
|
chmod 555 $BUILD_DIR/DEBIAN/postinst
|
|
|
|
# 8. Build .deb
|
|
dpkg-deb --build $BUILD_DIR
|
|
shell: bash
|
|
|
|
# Upload for Windows (Binary + Web folder)
|
|
- name: Upload Windows Artifact
|
|
if: matrix.os == 'windows'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ${{ env.APP_NAME }}-windows
|
|
path: |
|
|
${{ env.APP_NAME }}.exe
|
|
./web
|
|
|
|
# Upload for Linux (Binary + .deb)
|
|
- name: Upload Linux Artifact
|
|
if: matrix.os == 'linux'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ${{ env.APP_NAME }}-linux-${{ matrix.arch }}
|
|
path: |
|
|
${{ env.APP_NAME }}
|
|
*.deb
|