Open1

GitHub PagesでFlutterのWebアプリを公開するWorkflow

Koki MizumotoKoki Mizumoto

発火条件や使用するツールのバージョンは適時変える
サンプルプロジェクトリポジトリ:https://github.com/21km43/flutter-web-sample/tree/main

name: github pages

on:
  push:
    branches: ["main"]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Build
        uses: subosito/flutter-action@v2
        with:
          channel: 'stable'
          cache: true
      - run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" >> $GITHUB_ENV
      - run: flutter pub get
      - run: flutter build web --web-renderer html --base-href /${{ env.REPOSITORY_NAME }}/

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v2
        with:
          path: ./build/web

  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v3