ci: enhance CNAME handling and simplify deployment #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flutter Web | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: '3.22.3' | |
channel: 'stable' | |
- name: Install dependencies | |
run: flutter pub get | |
# 清理所有 CNAME 文件 | |
- name: Clean up old domain configurations | |
run: | | |
find . -name "CNAME" -delete | |
- name: Build web | |
run: flutter build web --release | |
# 确保构建目录中没有 CNAME | |
- name: Verify no CNAME exists | |
run: | | |
rm -f build/web/CNAME | |
echo "Checking for any remaining CNAME files..." | |
find . -name "CNAME" | |
- name: Upload Build Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: web-build | |
path: build/web/ | |
retention-days: 30 | |
- name: Create Release Archive | |
run: | | |
cd build/web | |
zip -r ../../json2dart-web.zip . | |
cd ../.. | |
- name: Get current date | |
id: date | |
run: echo "BUILD_DATE=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
if: github.ref == 'refs/heads/main' | |
with: | |
artifacts: "json2dart-web.zip" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: build_${{ env.BUILD_DATE }} | |
name: Build ${{ env.BUILD_DATE }} | |
body: | | |
JSON to Dart Converter Web Build | |
Build Date: ${{ env.BUILD_DATE }} | |
# 使用 force_orphan 确保完全清理旧的部署 | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
if: github.ref == 'refs/heads/main' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./build/web | |
force_orphan: true # 完全清理旧的部署历史 | |
cname: '' # 确保不设置 CNAME |