feat: Add GitHub Actions workflows for CI/CD

- Add cross-platform build workflow for macOS, Windows, Linux
- Add CI workflow with Rust code quality checks
- Add manual release workflow with automatic asset publishing
- Add dependency management workflow with security monitoring
- Update README with build status badges
- Remove unused Prettier/ESLint configurations
- Focus on Rust code quality and build verification
This commit is contained in:
2025-07-06 03:45:55 +08:00
parent 7e2dafa3d2
commit 2a49b081cb
10 changed files with 687 additions and 18 deletions

158
.github/README.md vendored Normal file
View File

@ -0,0 +1,158 @@
# GitHub Actions Workflows
This directory contains GitHub Actions workflows for automated CI/CD processes.
## Workflows Overview
### 🔨 `build.yml` - Build Desktop App
**Triggers:** Push to main/develop, Pull Requests, Releases
**Purpose:** Builds the desktop application for all supported platforms (macOS, Windows, Linux)
**Features:**
- Cross-platform builds (macOS Universal, Windows x64, Linux x64)
- Automatic artifact uploads
- Release asset publishing
- Caching for faster builds
**Artifacts:**
- **macOS**: DMG installer and .app bundle
- **Windows**: MSI and NSIS installers
- **Linux**: DEB package and AppImage
### 🧪 `ci.yml` - Continuous Integration
**Triggers:** Push to main/develop, Pull Requests
**Purpose:** Code quality checks and testing
**Features:**
- Frontend build verification
- Rust formatting and linting (rustfmt, clippy)
- Rust unit tests
- Security audits for both frontend and backend dependencies
### 🚀 `release.yml` - Manual Release
**Triggers:** Manual workflow dispatch
**Purpose:** Create tagged releases with built applications
**Features:**
- Manual version input
- Pre-release option
- Automatic release notes generation
- Cross-platform builds and uploads
- Comprehensive installation instructions
**Usage:**
1. Go to Actions tab in GitHub
2. Select "Release" workflow
3. Click "Run workflow"
4. Enter version (e.g., v1.0.0)
5. Choose if it's a pre-release
6. Click "Run workflow"
### 🔄 `dependencies.yml` - Dependency Management
**Triggers:** Weekly schedule (Mondays 9 AM UTC), Manual dispatch
**Purpose:** Automated dependency updates and security monitoring
**Features:**
- Weekly dependency updates
- Automatic PR creation for updates
- Security vulnerability detection
- Automatic issue creation for security alerts
## Setup Requirements
### Repository Secrets
No additional secrets are required beyond the default `GITHUB_TOKEN`.
### Branch Protection (Recommended)
Configure branch protection rules for `main` branch:
- Require status checks to pass before merging
- Require branches to be up to date before merging
- Include status checks: `lint-and-test`, `security-audit`
### Release Process
#### Automated (Recommended)
1. Merge changes to `main` branch
2. Use the manual release workflow to create a new release
3. The workflow will automatically build and upload all platform binaries
#### Manual
1. Create a new tag: `git tag v1.0.0`
2. Push the tag: `git push origin v1.0.0`
3. Create a release on GitHub
4. The build workflow will automatically attach binaries
## Platform-Specific Notes
### macOS
- Builds universal binaries (Intel + Apple Silicon)
- Requires macOS 13.0 or later
- DMG installer includes code signing (if certificates are configured)
### Windows
- Builds for x64 architecture
- Provides both MSI and NSIS installers
- Compatible with Windows 10 and later
### Linux
- Builds for x64 architecture
- Provides DEB package for Debian/Ubuntu
- Provides AppImage for universal Linux compatibility
- Requires WebKit2GTK and other system dependencies
## Troubleshooting
### Build Failures
1. Check the specific platform logs in the Actions tab
2. Ensure all dependencies are properly declared
3. Verify Tauri configuration is correct
### Security Audit Failures
1. Review the security report in the workflow logs
2. Update vulnerable dependencies
3. Consider using `pnpm audit --fix` for frontend issues
4. Use `cargo update` for Rust dependency updates
### Cache Issues
If builds are failing due to cache corruption:
1. Go to Actions tab
2. Click on "Caches" in the sidebar
3. Delete relevant caches
4. Re-run the workflow
## Customization
### Adding New Platforms
To add support for additional platforms, modify the `matrix` section in `build.yml`:
```yaml
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
target: 'aarch64-apple-darwin'
```
### Modifying Build Steps
Each workflow can be customized by:
1. Adding new steps
2. Modifying existing commands
3. Adding environment variables
4. Configuring different Node.js/Rust versions
### Adding Code Quality Tools (Optional)
If you want to add code quality tools in the future:
1. **ESLint**: Add ESLint configuration and dependencies for JavaScript/TypeScript linting
2. **Prettier**: Add Prettier for consistent code formatting
3. **TypeScript strict checking**: Enable stricter TypeScript rules and type checking
### Changing Schedule
Modify the `cron` expression in `dependencies.yml` to change the update frequency:
```yaml
schedule:
- cron: '0 9 * * 1' # Every Monday at 9 AM UTC
```

124
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,124 @@
name: Build Desktop App
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
release:
types: [ published ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target universal-apple-darwin'
target: 'universal-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
target: 'x86_64-unknown-linux-gnu'
- platform: 'windows-latest'
args: ''
target: 'x86_64-pc-windows-msvc'
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies (Ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: pnpm install
- name: Build frontend
run: pnpm build
- name: Build Tauri app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: ${{ matrix.args }}
- name: Upload artifacts (macOS)
if: matrix.platform == 'macos-latest'
uses: actions/upload-artifact@v4
with:
name: macos-app
path: |
src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg
src-tauri/target/universal-apple-darwin/release/bundle/macos/*.app
- name: Upload artifacts (Linux)
if: matrix.platform == 'ubuntu-22.04'
uses: actions/upload-artifact@v4
with:
name: linux-app
path: |
src-tauri/target/release/bundle/deb/*.deb
src-tauri/target/release/bundle/appimage/*.AppImage
- name: Upload artifacts (Windows)
if: matrix.platform == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: windows-app
path: |
src-tauri/target/release/bundle/msi/*.msi
src-tauri/target/release/bundle/nsis/*.exe
release:
if: github.event_name == 'release'
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -la
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
files: |
macos-app/**/*
linux-app/**/*
windows-app/**/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

99
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,99 @@
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: pnpm install
- name: Check Rust formatting
run: cargo fmt --all --check
working-directory: src-tauri
- name: Lint Rust code
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: src-tauri
- name: Run Rust tests
run: cargo test --all-features
working-directory: src-tauri
- name: Build frontend
run: pnpm build
- name: Check Tauri build
run: cargo check --all-targets --all-features
working-directory: src-tauri
security-audit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Run security audit
run: cargo audit
working-directory: src-tauri
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: Install frontend dependencies
run: pnpm install
- name: Run npm audit
run: pnpm audit --audit-level moderate

126
.github/workflows/dependencies.yml vendored Normal file
View File

@ -0,0 +1,126 @@
name: Update Dependencies
on:
schedule:
# Run every Monday at 9:00 AM UTC
- cron: '0 9 * * 1'
workflow_dispatch:
jobs:
update-dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Update frontend dependencies
run: |
pnpm update --latest
pnpm install
- name: Update Rust dependencies
run: |
cargo update
working-directory: src-tauri
- name: Check if build still works
run: |
pnpm build
cargo check --all-targets --all-features
working-directory: src-tauri
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update dependencies'
title: 'chore: update dependencies'
body: |
## Automated Dependency Update
This PR updates all dependencies to their latest versions.
### Changes
- Updated frontend dependencies via `pnpm update --latest`
- Updated Rust dependencies via `cargo update`
### Testing
- ✅ Frontend build passes
- ✅ Rust compilation check passes
Please review the changes and run full tests before merging.
branch: chore/update-dependencies
delete-branch: true
security-updates:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Check for security vulnerabilities
run: |
echo "## Frontend Security Audit" >> security-report.md
pnpm audit --audit-level moderate >> security-report.md || true
echo "## Rust Security Audit" >> security-report.md
cd src-tauri
cargo audit >> ../security-report.md || true
- name: Create security issue if vulnerabilities found
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('security-report.md', 'utf8');
if (report.includes('vulnerabilities') || report.includes('RUSTSEC')) {
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🔒 Security vulnerabilities detected',
body: `## Security Audit Report\n\n\`\`\`\n${report}\n\`\`\`\n\nPlease review and update the affected dependencies.`,
labels: ['security', 'dependencies']
});
}

140
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,140 @@
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v1.0.0)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
type: boolean
default: false
env:
CARGO_TERM_COLOR: always
jobs:
create-release:
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.id }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.version }}
release_name: Release ${{ github.event.inputs.version }}
draft: false
prerelease: ${{ github.event.inputs.prerelease }}
body: |
## Changes in this Release
- Auto-generated release for version ${{ github.event.inputs.version }}
## Downloads
Choose the appropriate installer for your operating system:
### macOS
- **DMG**: Universal binary for Intel and Apple Silicon Macs
### Windows
- **MSI**: Windows Installer package
- **EXE**: NSIS installer
### Linux
- **DEB**: Debian/Ubuntu package
- **AppImage**: Portable application
## Installation Notes
### macOS
1. Download the DMG file
2. Open the DMG and drag the app to Applications folder
3. On first launch, you may need to right-click and select "Open" due to Gatekeeper
### Windows
1. Download the MSI or EXE installer
2. Run the installer as administrator
3. Follow the installation wizard
### Linux
1. **DEB**: `sudo dpkg -i ambient-light-desktop_*.deb`
2. **AppImage**: Make executable and run directly
## System Requirements
- **macOS**: 13.0 or later
- **Windows**: Windows 10 or later
- **Linux**: Ubuntu 22.04 or equivalent
build-and-upload:
needs: create-release
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target universal-apple-darwin'
target: 'universal-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
target: 'x86_64-unknown-linux-gnu'
- platform: 'windows-latest'
args: ''
target: 'x86_64-pc-windows-msvc'
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies (Ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: pnpm install
- name: Build and release
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseId: ${{ needs.create-release.outputs.release_id }}
args: ${{ matrix.args }}

36
.gitignore vendored
View File

@ -1,3 +1,39 @@
node_modules
dist
.DS_Store
# IDE
.vscode/settings.json
.idea/
# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Coverage directory used by tools like istanbul
coverage/
*.lcov
# ESLint cache
.eslintcache
# Prettier cache
.prettiercache
# Build artifacts
src-tauri/target/
src-tauri/Cargo.lock
# OS generated files
Thumbs.db
ehthumbs.db
Desktop.ini

View File

@ -1,7 +0,0 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
node_modules/*
src-tauri

View File

@ -1,8 +0,0 @@
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: true,
printWidth: 90,
tabWidth: 2,
endOfLine: "auto",
};

3
.vscode/tasks.json vendored
View File

@ -12,9 +12,6 @@
"tauri",
"dev"
],
"problemMatcher": [
"$eslint-stylish"
],
"options": {
"env": {
"RUST_LOG": "info"

View File

@ -1,5 +1,9 @@
# Display Ambient Light Desktop App
[![Build](https://github.com/USERNAME/REPOSITORY/workflows/Build%20Desktop%20App/badge.svg)](https://github.com/USERNAME/REPOSITORY/actions/workflows/build.yml)
[![CI](https://github.com/USERNAME/REPOSITORY/workflows/CI/badge.svg)](https://github.com/USERNAME/REPOSITORY/actions/workflows/ci.yml)
[![Release](https://github.com/USERNAME/REPOSITORY/workflows/Release/badge.svg)](https://github.com/USERNAME/REPOSITORY/actions/workflows/release.yml)
A desktop application built with Tauri 2.0 for ambient light control, supporting multi-monitor screen sampling and LED strip control to create immersive ambient lighting effects.
## ✨ Features