-
Notifications
You must be signed in to change notification settings - Fork 9
[397] GitHub Pagesへのdeploy pipeline 作成 #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
339f29c
b4297bf
f8c4d0e
db26909
6b8bedf
82249f2
300c6ba
77d5438
4313260
7a0e487
0e49b15
11b6654
8ab5794
8d453a6
9354f06
7dd9f22
b4f3145
166d615
e9c4c1e
01d8a72
235cc01
d807cb1
45b93fd
12b0237
1d492bd
3cf876f
4831844
d67ea00
65ffb4e
94be195
e7915d2
2fc10db
fb201ff
62df05d
40d8714
c3dc2ed
623ed15
16edd2b
e1e2866
d7a95a7
9baf758
8a18644
76b76e1
f95d7ee
e20fb68
e6421fb
b15ae43
963c5f5
4a019c7
4d4276d
f3c932d
cf9b34e
52a0232
07bdcbb
58578cf
93db198
bbeb9bc
3ea8b80
f0b5e33
26acab6
8b647b4
bee9da9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ srvaroa | |
| startswith | ||
| webframeworks | ||
| elif | ||
| tonumber | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| title: "[初期セットアップ(任意)] Pull Request内でデプロイのワークフローを設定する" | ||
| labels: | ||
| - initialization | ||
| - optional | ||
| --- | ||
|
|
||
| # GitHub Pages プレビュー | ||
|
|
||
| この 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. リポジトリ名条件の削除 | ||
|
|
||
| このテンプレートプロジェクトを元に新規プロジェクトを作成した際に、誤ってワークフローが実行されないように、リポジトリ名による有効化条件を記述しています。この記述はセットアップ後は不要になりますので、削除してください。 | ||
|
|
||
|  | ||
|
|
||
| <!-- 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 | ||
| 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: | ||||||
|
blendthink marked this conversation as resolved.
|
||||||
| permissions: | ||||||
| actions: read | ||||||
| timeout-minutes: 5 | ||||||
| runs-on: ubuntu-22.04 | ||||||
|
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 }} | ||||||
|
||||||
| url: ${{ steps.deployment.outputs.page_url }}${{ env.CURRENT_BRANCH }} | |
| url: ${{ steps.deployment.outputs.page_url }}/${{ env.CURRENT_BRANCH }} |
There was a problem hiding this comment.
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>となるため、本内容は対応してはいけない。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.