Deploy Web Flasher #25
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
| # GitHub Actions workflow for deploying the web flasher to GitHub Pages | |
| # 用于将网页烧录器部署到 GitHub Pages 的工作流 | |
| # | |
| # This workflow: | |
| # 1. Waits for build-firmware workflow to complete | |
| # 2. Downloads firmware artifacts | |
| # 3. Deploys to GitHub Pages | |
| # | |
| # 此工作流: | |
| # 1. 等待 build-firmware 工作流完成 | |
| # 2. 下载固件 artifacts | |
| # 3. 部署到 GitHub Pages | |
| name: Deploy Web Flasher | |
| on: | |
| # Trigger after build-firmware workflow completes | 在 build-firmware 工作流完成后触发 | |
| workflow_run: | |
| workflows: ["Build Firmware"] | |
| types: | |
| - completed | |
| branches: [main, master] | |
| # Also trigger on docs/flasher changes (no firmware rebuild needed) | |
| # 在 docs/flasher 更改时也触发(无需重新构建固件) | |
| push: | |
| branches: [main, master] | |
| paths: | |
| - 'docs/flasher/**' | |
| - '.github/workflows/deploy-flasher.yml' | |
| workflow_dispatch: # Allow manual trigger | 允许手动触发 | |
| # Allow only one concurrent deployment | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| # Deploy to GitHub Pages | 部署到 GitHub Pages | |
| deploy: | |
| # Only run if triggered by successful build or push/manual trigger | |
| # 仅在构建成功触发或 push/手动触发时运行 | |
| if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download firmware artifacts from workflow_run | |
| if: ${{ github.event_name == 'workflow_run' }} | |
| uses: dawidd6/action-download-artifact@v3 | |
| with: | |
| workflow: build-firmware.yml | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: all-firmware | |
| path: firmware-download/ | |
| - name: Download firmware artifacts (manual/push trigger) | |
| if: ${{ github.event_name != 'workflow_run' }} | |
| uses: dawidd6/action-download-artifact@v3 | |
| with: | |
| workflow: build-firmware.yml | |
| branch: main | |
| name: all-firmware | |
| path: firmware-download/ | |
| continue-on-error: true # May not exist if only docs changed | 如果只是 docs 更改可能不存在 | |
| - name: Prepare deployment directory | |
| run: | | |
| # Create deployment directory | 创建部署目录 | |
| mkdir -p deploy/flasher/firmware | |
| # Copy flasher HTML and assets | 复制烧录器 HTML 和资源 | |
| cp docs/flasher/index.html deploy/flasher/ | |
| cp docs/flasher/README.md deploy/flasher/ | |
| cp docs/flasher/firmware-config.yml deploy/flasher/ | |
| # Copy firmware binaries | 复制固件二进制文件 | |
| if [ -d "firmware-download" ]; then | |
| cp -r firmware-download/* deploy/flasher/firmware/ | |
| fi | |
| # Create index for root | 为根目录创建索引 | |
| cat > deploy/index.html << 'EOF' | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta http-equiv="refresh" content="0; url=flasher/"> | |
| <title>Redirecting...</title> | |
| </head> | |
| <body> | |
| <p>Redirecting to <a href="flasher/">Web Flasher</a>...</p> | |
| </body> | |
| </html> | |
| EOF | |
| echo "Deployment directory structure:" | |
| find deploy -type f | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: deploy/ | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |