Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
339f29c
add: GitHub Pagesへのdeploy pipeline叩き台作成
r0227n May 13, 2025
b4297bf
chore: typo修正
r0227n May 13, 2025
f8c4d0e
add: 間違って実行時にデプロイされないように制限を追加
r0227n May 13, 2025
db26909
add: GitHub Pagesの設定に関するドキュメントを作成
r0227n May 13, 2025
6b8bedf
chore: 書き換え忘れを修正
r0227n May 13, 2025
82249f2
delete: firebase hosting関連のファイルを削除
r0227n May 13, 2025
300c6ba
permission&timeout-minutesを追加
r0227n May 13, 2025
77d5438
chore: 意図しない形で実行されないようにする為、onをコメントアウト
r0227n May 13, 2025
4313260
Merge remote-tracking branch 'origin' into feature/GH-397
r0227n May 15, 2025
7a0e487
Merge branch 'main' into feature/GH-397
r0227n May 16, 2025
0e49b15
chore: ドキュメントにPagesへの注意事項を追記
r0227n May 19, 2025
11b6654
chore: repository owner を条件に追加
r0227n May 19, 2025
8ab5794
Update GITHUB_PAGES_PREVIEW.md image
r0227n May 19, 2025
8d453a6
Merge branch 'main' into feature/GH-397
r0227n May 19, 2025
9354f06
Merge branch 'main' into feature/GH-397
r0227n May 20, 2025
7dd9f22
chore: コメントアウトを解除し、デプロイの動作確認可能にした
r0227n May 20, 2025
b4f3145
fix: fomat修正
r0227n May 20, 2025
166d615
add: Deployment branches and tags の設定項目を追記
r0227n May 20, 2025
e9c4c1e
Merge remote-tracking branch 'origin' into feature/GH-397
r0227n May 28, 2025
01d8a72
add: concurrencyを追加
r0227n May 28, 2025
235cc01
chore: domain/<PR_Number>/<hash>形式でデプロイ可能にした
r0227n May 28, 2025
d807cb1
chore: branchを分けず、直接deployするように変更
r0227n May 28, 2025
45b93fd
chore: checkout を追加
r0227n May 28, 2025
12b0237
chore: urlの末尾の/を削除
r0227n May 28, 2025
1d492bd
chore: base-href にDEPLOY_DIR を追加
r0227n May 28, 2025
3cf876f
fix: base-href の末尾に/を追加
r0227n May 28, 2025
4831844
add: 404をコピー作成するstepを追加
r0227n May 28, 2025
d67ea00
chore: shaを削除
r0227n May 29, 2025
65ffb4e
chore: wasmオプションを削除
r0227n May 29, 2025
94be195
chore: deploy 専用のディレクトリを作成し、それを指定するようにした
r0227n May 29, 2025
e7915d2
chore: deloy先をPR Numberに変更
r0227n May 29, 2025
2fc10db
chore: outputディレクトリを修正し、PR Numberに出力するように修正
r0227n May 29, 2025
fb201ff
chore: base-href を変更する
r0227n May 29, 2025
62df05d
add ; configure-pagesを追加
r0227n May 29, 2025
40d8714
chore: subdirectory指定でデプロイ可能になるように試した
r0227n May 29, 2025
c3dc2ed
fix: 重複処理を削除
r0227n May 29, 2025
623ed15
chore: リファクタリングし、不要なjobを削除
r0227n May 29, 2025
16edd2b
chore: 不要な改行を削除
r0227n May 29, 2025
e1e2866
Merge branch 'main' into feature/GH-397
r0227n May 29, 2025
d7a95a7
chore: artifactの保持期間を3日に変更
r0227n May 30, 2025
9baf758
Merge branch 'feature/GH-397' of https://github.com/yumemi-inc/flutte…
r0227n May 30, 2025
8a18644
chore: artifactを複数件取得し、デプロイできるようにした
r0227n Jun 1, 2025
76b76e1
Merge remote-tracking branch 'origin' into feature/GH-397
r0227n Jun 2, 2025
f95d7ee
chore: artifact upload処理を一箇所に集約
r0227n Jun 2, 2025
e20fb68
Merge remote-tracking branch 'origin' into feature/GH-397
r0227n Jun 2, 2025
e6421fb
chore: branch指定でビルドするよに修正
r0227n Jun 2, 2025
b15ae43
Merge remote-tracking branch 'origin' into feature/GH-397
r0227n Jun 2, 2025
963c5f5
chore: 解凍先を終始絵するようにした
r0227n Jun 2, 2025
4a019c7
chore: 検証用に期間を1日までに変更
r0227n Jun 2, 2025
4d4276d
refactor: 出力されるURLを修正
r0227n Jun 2, 2025
f3c932d
chore: 不適切なコメントを削除
r0227n Jun 2, 2025
cf9b34e
Merge branch 'main' into feature/GH-397
r0227n Jun 2, 2025
52a0232
refactor: current_run_idを未使用のため、削除
r0227n Jun 2, 2025
07bdcbb
chore: 出力されるurlのフォーマットをコメントに記載
r0227n Jun 3, 2025
58578cf
chore: masonは使用しなくなったため、削除
r0227n Jun 3, 2025
93db198
chore: permissions: actions: readを明示的に宣言
r0227n Jun 3, 2025
bbeb9bc
chore: checkout actions をv4.1.7に更新
r0227n Jun 3, 2025
3ea8b80
Merge branch 'main' into feature/GH-397
r0227n Jun 3, 2025
f0b5e33
Merge remote-tracking branch 'origin' into feature/GH-397
r0227n Jun 4, 2025
26acab6
chore: fileの先頭にメタ情報を追加
r0227n Jun 4, 2025
8b647b4
fix: リスト表記のフォーマット修正
r0227n Jun 4, 2025
bee9da9
chore: artifactの保持期間を3日に変更
r0227n Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell/github-action-term.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ srvaroa
startswith
webframeworks
elif
tonumber
58 changes: 58 additions & 0 deletions .github/initialization/GITHUB_PAGES_PREVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "[初期セットアップ(任意)] Pull Request内でデプロイのワークフローを設定する"
labels:
- initialization
- optional
---

# GitHub Pages プレビュー
Comment thread
den0206 marked this conversation as resolved.

この Issue の対応は任意です。

このプロジェクトでは `apps/catalog` の Widgetbook を PullRequest 時にプレビューできるようにするワークフローが用意されています。
プレビューは GitHub Pages 上にデプロイされます。

ワークフローを有効化するためには、以下の手順に従って設定してください。

## 1. カスタム GitHub Actions ワークフローによる公開設定

[カスタム GitHub Actions ワークフローによる公開][1] に従ってGitHub Actions ワークフローでGitHub Pageにデプロイ可能にする。

## 2. Visibilityの有効化

[GitHub Pages サイトの可視性を変更する][2] に従って`Visibility`を有効化することにより、アクセス制限を設定する。
ただし、この機能は`GitHub Enterprise Cloud`を契約している`Organization`でしか利用できません。
`GitHub Enterprise Cloud`以外で非公開のデプロイを行いたい場合、

- `AWS CloudFront`
- `Cloudflare Pages` + `Zero Trust`

等を検討してください。

## 3. デプロイ環境の設定確認

`GitHub Pages`へデプロイ可能なブランチを制限します。
`Settings` ⇨ `Environments`から`github-pages`環境を選択し、デプロイ可能なブランチを指定してください。

`Deployment branches and tags`では、以下の3つのオプションからプロジェクトに適した設定を選択できます:

- `No restriction`: すべてのブランチからデプロイ可能
- `Protected branches only`: 保護されたブランチからのみデプロイ可能
- `Selected branches and tags`: 指定したブランチやタグパターンに一致するもののみデプロイ可能

セキュリティ要件や運用方針に応じて、適切な制限を設定することをお勧めします。

## 4. ワークフローの内容を変更する

`.github/workflows/github-pages-pull-request.yml` を修正する。

### 4-1. リポジトリ名条件の削除

このテンプレートプロジェクトを元に新規プロジェクトを作成した際に、誤ってワークフローが実行されないように、リポジトリ名による有効化条件を記述しています。この記述はセットアップ後は不要になりますので、削除してください。

![github-pages-pull-request.png](https://github.com/user-attachments/assets/324da9ca-078d-4b8f-a7bc-b6441c2c8564)

<!-- Links -->

[1]: https://docs.github.com/ja/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0-github-actions-%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC%E3%81%AB%E3%82%88%E3%82%8B%E5%85%AC%E9%96%8B
[2]: https://docs.github.com/ja/enterprise-cloud@latest/pages/getting-started-with-github-pages/changing-the-visibility-of-your-github-pages-site
145 changes: 145 additions & 0 deletions .github/workflows/github-pages-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Deploy to GitHub Pages on PR

on:
workflow_dispatch:
pull_request:
paths-ignore:
- ".idea/**"
- ".vscode/**"
- "apps/app/**"
- "docs/**"
- "scripts/**"
- "tools/**"
- "**/docs/**"
- "**/test/**"
- "**.md"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PROJECT_DIR: apps/catalog
DEPLOY_DIR: deploy
CURRENT_BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
build:
Comment thread
blendthink marked this conversation as resolved.
permissions:
actions: read
timeout-minutes: 5
runs-on: ubuntu-22.04
Comment thread
den0206 marked this conversation as resolved.
# NOTE: See https://github.com/yumemi-inc/flutter-mobile-project-template/blob/main/docs/GITHUB_PAGES_PREVIEW.md
if: ${{ github.repository_owner == 'yumemi-inc' && github.event.repository.name == 'flutter-mobile-project-template' }}
steps:
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup Application Runtime
uses: ./.github/actions/setup-application-runtime

- name: Build web
run: flutter build web --release --base-href /${{ github.event.repository.name }}/${{ env.CURRENT_BRANCH }}/
working-directory: ${{ env.PROJECT_DIR }}

- name: Create & Copy combined deployment directory
run: |
mkdir -p ${{ env.DEPLOY_DIR }}/${{ env.CURRENT_BRANCH }}/
cp -R ${{ env.PROJECT_DIR }}/build/web/. ${{ env.DEPLOY_DIR }}/${{ env.CURRENT_BRANCH }}/

- name: Calculate 3 days ago date (UTC)
id: date_calc
run: echo "start_date=$(date -u -d '3 days ago' '+%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"

- name: Get run IDs from the last 3 days for the triggering workflow
id: get_run_ids
run: |
START_DATE="${{ steps.date_calc.outputs.start_date }}"
echo "Fetching runs for workflow: '${{ github.workflow }}' created since $START_DATE"

# gh run list で対象ワークフローの過去3日間の成功した実行IDを取得
# 現在のデプロイワークフロー自身のrun_idは除外
RUN_IDS=$(gh run list \
--workflow "${{ github.workflow }}" \
--status success \
--created ">=$START_DATE" \
--json databaseId,headBranch,createdAt \
| jq -r --arg current_branch "${{ env.CURRENT_BRANCH }}" '
group_by(.headBranch) |
map(max_by(.createdAt)) |
map(select(.headBranch != $current_branch)) |
map({branch: .headBranch, run_id: .databaseId})
')

if [ -z "$RUN_IDS" ]; then
echo "No successful runs found in the last 3 days for workflow: '${{ github.workflow }}'."
exit 0 # 実行IDが見つからなければ、ジョブを成功として終了
fi
echo "Found run IDs and their branches:"
echo "$RUN_IDS"
{
echo "run_data<<EOF"
echo "$RUN_IDS"
echo "EOF"
} >> "$GITHUB_OUTPUT"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # gh CLI認証用

- name: Download artifacts for each run ID
run: |
mkdir -p _site # GitHub Pagesのルートディレクトリ

# 出力された各行 (run_id branch_name) をループ処理
echo '${{ steps.get_run_ids.outputs.run_data }}' | jq -r '.[] | "\(.run_id) \(.branch)"' | while read -r run_id branch; do
if [ -n "$run_id" ] && [ -n "$branch" ]; then
echo "Downloading artifact for run ID: $run_id from branch: $branch"
DOWNLOAD_PATH="dl_artifact/$branch"
mkdir -p "$DOWNLOAD_PATH"

# gh run download でartifactをダウンロード
gh run download "$run_id" \
--dir "$DOWNLOAD_PATH" \
--repo "$GITHUB_REPOSITORY"
echo "Downloaded artifact to $DOWNLOAD_PATH"

# アーティファクトを解凍して展開
if [ -f "$DOWNLOAD_PATH/github-pages/artifact.tar" ]; then
echo "Extracting artifact.tar to $DOWNLOAD_PATH"
tar -xf "$DOWNLOAD_PATH/github-pages/artifact.tar" -C "${{ env.DEPLOY_DIR }}"
rm -rf "$DOWNLOAD_PATH/github-pages" # 解凍後のtarファイルとディレクトリを削除
else
echo "Warning: artifact.tar not found in $DOWNLOAD_PATH/github-pages/"
fi
else
echo "Warning: run_id or branch is empty"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # gh CLI認証用

# https://github.com/actions/upload-pages-artifact
- name: Upload static files as artifact
id: deployment
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
with:
path: ./${{ env.DEPLOY_DIR }}
retention-days: 3

deploy:
environment:
name: github-pages
# <domain>/<repository>/<branch> のフォーマットでURLを生成
url: ${{ steps.deployment.outputs.page_url }}${{ env.CURRENT_BRANCH }}
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The URL concatenation directly appends the branch name, which could lead to double slashes or missing separators in some cases. Consider ensuring consistent formatting when constructing the deployment URL.

Suggested change
url: ${{ steps.deployment.outputs.page_url }}${{ env.CURRENT_BRANCH }}
url: ${{ steps.deployment.outputs.page_url }}/${{ env.CURRENT_BRANCH }}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steps.deployment.outputs.page_urlの出力結果の末尾に/が含まれている。
そのため、suggestedの内容を変更すると<domain>/<repository>//<branch>となるため、本内容は対応してはいけない。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-badge

上記は簡易的にでもコメントに残しておいた方が良いと思います!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@den0206
レビューありがとうございます。以下でコメントを追加しましたので、再レビューいただけますと幸いです。
07bdcbb

permissions:
pages: write
id-token: write
timeout-minutes: 5
runs-on: ubuntu-22.04
needs: build
steps:
# https://github.com/actions/deploy-pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5