Deploy Flutter Web to GitHub Pages #20
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: Deploy Flutter Web to GitHub Pages | |
| on: | |
| workflow_run: | |
| workflows: ["Build Web"] | |
| types: [completed] | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| paths: | |
| - "LICENSE.md" | |
| - "PRIVACY.md" | |
| - "CNAME" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Download web build artifact | |
| if: ${{ github.event_name == 'workflow_run' }} | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: web-build | |
| path: build/web | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Setup Flutter | |
| if: ${{ github.event_name != 'workflow_run' }} | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: "3.38.5" | |
| channel: "stable" | |
| cache: true | |
| - name: Build Web | |
| if: ${{ github.event_name != 'workflow_run' }} | |
| run: | | |
| flutter pub get | |
| flutter build web --release --base-href "/" | |
| - name: Copy documentation files | |
| run: | | |
| cp LICENSE.md build/web/ | |
| cp PRIVACY.md build/web/ | |
| - name: Create documentation index | |
| run: | | |
| cat > build/web/docs.html << 'EOF' | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Music Sharity - Documentation</title> | |
| <style> | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; | |
| max-width: 800px; | |
| margin: 50px auto; | |
| padding: 20px; | |
| line-height: 1.6; | |
| background: #f5f5f5; | |
| } | |
| .container { | |
| background: white; | |
| padding: 40px; | |
| border-radius: 8px; | |
| box-shadow: 0 2px 10px rgba(0,0,0,0.1); | |
| } | |
| h1 { | |
| color: #1976d2; | |
| border-bottom: 3px solid #1976d2; | |
| padding-bottom: 10px; | |
| } | |
| .doc-links { | |
| display: grid; | |
| gap: 20px; | |
| margin-top: 30px; | |
| } | |
| .doc-card { | |
| border: 2px solid #e0e0e0; | |
| border-radius: 8px; | |
| padding: 20px; | |
| text-decoration: none; | |
| color: inherit; | |
| transition: all 0.3s; | |
| } | |
| .doc-card:hover { | |
| border-color: #1976d2; | |
| box-shadow: 0 4px 12px rgba(25, 118, 210, 0.2); | |
| transform: translateY(-2px); | |
| } | |
| .doc-card h2 { | |
| margin: 0 0 10px 0; | |
| color: #1976d2; | |
| } | |
| .doc-card p { | |
| margin: 0; | |
| color: #666; | |
| } | |
| .back-link { | |
| display: inline-block; | |
| margin-top: 30px; | |
| color: #1976d2; | |
| text-decoration: none; | |
| } | |
| .back-link:hover { | |
| text-decoration: underline; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>📚 Music Sharity - Documentation</h1> | |
| <div class="doc-links"> | |
| <a href="license.html" class="doc-card"> | |
| <h2>📜 License</h2> | |
| <p>View the GPL v3 license terms for Music Sharity</p> | |
| </a> | |
| <a href="privacy.html" class="doc-card"> | |
| <h2>🔒 Privacy Policy</h2> | |
| <p>Learn how Music Sharity protects your privacy</p> | |
| </a> | |
| <a href="https://github.com/ByteRoast/music-sharity" class="doc-card" target="_blank"> | |
| <h2>💻 GitHub Repository</h2> | |
| <p>View the source code and contribute</p> | |
| </a> | |
| </div> | |
| <a href="/" class="back-link">← Back to Music Sharity App</a> | |
| </div> | |
| </body> | |
| </html> | |
| EOF | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Install marked | |
| run: npm install marked | |
| - name: Convert Markdown to HTML | |
| run: | | |
| node << 'SCRIPT' | |
| const fs = require('fs'); | |
| const { marked } = require('marked'); | |
| function convertToHTML(mdFile, title, outputFile) { | |
| const markdown = fs.readFileSync(mdFile, 'utf8'); | |
| const content = marked.parse(markdown); | |
| const html = `<!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>${title}</title> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5/github-markdown.min.css"> | |
| <style> | |
| body { | |
| max-width: 900px; | |
| margin: 40px auto; | |
| padding: 20px; | |
| background: #f5f5f5; | |
| font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"; | |
| } | |
| .markdown-body { | |
| background: white; | |
| padding: 40px; | |
| border-radius: 8px; | |
| box-shadow: 0 2px 10px rgba(0,0,0,0.1); | |
| color: #000000 !important; | |
| } | |
| .back-link { | |
| display: inline-block; | |
| margin-bottom: 20px; | |
| color: #1976d2; | |
| text-decoration: none; | |
| font-weight: 500; | |
| } | |
| .back-link:hover { | |
| text-decoration: underline; | |
| } | |
| .markdown-body table { | |
| border-collapse: collapse; | |
| width: 100%; | |
| margin: 20px 0; | |
| } | |
| .markdown-body table th, | |
| .markdown-body table td { | |
| border: 1px solid #ddd; | |
| padding: 12px; | |
| text-align: left; | |
| } | |
| .markdown-body table th { | |
| background-color: #f5f5f5; | |
| font-weight: 600; | |
| } | |
| .markdown-body table tr { | |
| background-color: #ffffff !important; | |
| } | |
| .markdown-body table tr:hover { | |
| background-color: #f9f9f9; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <a href="/docs.html" class="back-link">← Back to Documentation</a> | |
| <div class="markdown-body"> | |
| ${content} | |
| </div> | |
| </body> | |
| </html> | |
| `; | |
| fs.writeFileSync(outputFile, html, 'utf8'); | |
| console.log(`Generated ${outputFile}`); | |
| } | |
| convertToHTML('LICENSE.md', 'Music Sharity - License', 'build/web/license.html'); | |
| convertToHTML('PRIVACY.md', 'Music Sharity - Privacy Policy', 'build/web/privacy.html'); | |
| SCRIPT | |
| - name: Deploy to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./build/web | |
| cname: music-sharity.byteroast.fr |