chore: add GitHub Actions workflows for deploying to GitHub Pages and PR previews

This commit is contained in:
insleker 2025-12-15 13:59:41 +08:00
parent 473b957587
commit 1394341935
2 changed files with 104 additions and 0 deletions

51
.github/workflows/gh-page-publish.yml vendored Normal file
View File

@ -0,0 +1,51 @@
name: Deploy to GitHub Pages
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- name: Install dependencies
run: flutter pub get
- name: Run build_runner
run: flutter pub run build_runner build --delete-conflicting-outputs
- name: Run tests
run: flutter test
- name: Build web
run: flutter build web --base-href /pdf_signature/ --release -O4 --wasm
- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/web
publish_branch: gh-pages
exclude_assets: 'pr-preview/**'

53
.github/workflows/pr-preview.yml vendored Normal file
View File

@ -0,0 +1,53 @@
name: Deploy PR Preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
concurrency: preview-${{ github.ref }}
permissions:
contents: write
pull-requests: write
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Flutter
if: github.event.action != 'closed'
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- name: Install dependencies
if: github.event.action != 'closed'
run: flutter pub get
- name: Run build_runner
if: github.event.action != 'closed'
run: flutter pub run build_runner build --delete-conflicting-outputs
- name: Run tests
if: github.event.action != 'closed'
run: flutter test
- name: Build web
if: github.event.action != 'closed'
run: flutter build web --base-href /pdf_signature/pr-preview/pr-${{ github.event.number }}/ --release -O4 --wasm
- name: Deploy preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./build/web/
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto