Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 20 additions & 34 deletions .github/workflows/deploy-web-hosting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ name: Deploy to Web Hosting
on:
workflow_call:
inputs:
environment:
description: "GitHub Environment name for secret access"
type: string
required: true
deploy-type:
description: "Deploy method ('ftp' or 'rsync')"
type: string
Expand Down Expand Up @@ -41,25 +45,6 @@ on:
type: string
required: false
default: ''
secrets:
server-host:
required: true
server-user:
required: true
server-path:
required: true
server-password:
required: false
ssh-private-key:
required: false
slack-channel-id:
required: false
slack-bot-oauth-token:
required: false
slack-webhook-url:
required: false
slack-mention-user:
required: false

permissions: {}

Expand All @@ -68,6 +53,7 @@ jobs:
name: Deploy to Web Hosting
runs-on: ubuntu-24.04
timeout-minutes: 15
environment: ${{ inputs.environment }}
permissions:
pull-requests: write

Expand All @@ -83,9 +69,9 @@ jobs:
- name: Check Slack configuration
id: check-slack
env:
SLACK_CHANNEL_ID: ${{ secrets.slack-channel-id }}
SLACK_BOT_OAUTH_TOKEN: ${{ secrets.slack-bot-oauth-token }}
SLACK_WEBHOOK_URL: ${{ secrets.slack-webhook-url }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
SLACK_BOT_OAUTH_TOKEN: ${{ secrets.SLACK_BOT_OAUTH_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Comment on lines 70 to +74
run: |
if [ -n "$SLACK_CHANNEL_ID" ] && [ -n "$SLACK_BOT_OAUTH_TOKEN" ]; then
echo "success-enabled=true" >> "$GITHUB_OUTPUT"
Expand All @@ -107,10 +93,10 @@ jobs:
with:
base-path: ${{ steps.compute-path.outputs.deploy-path }}
output-dir: ${{ inputs.output-dir }}
ftp-server: ${{ secrets.server-host }}
ftp-username: ${{ secrets.server-user }}
ftp-password: ${{ secrets.server-password }}
ftp-path: ${{ secrets.server-path }}${{ steps.compute-path.outputs.deploy-path }}
ftp-server: ${{ secrets.SERVER_HOST }}
ftp-username: ${{ secrets.SERVER_USER }}
ftp-password: ${{ secrets.SERVER_PASSWORD }}
ftp-path: ${{ secrets.SERVER_PATH }}${{ steps.compute-path.outputs.deploy-path }}
dry-run: ${{ inputs.dry-run }}
is-production: ${{ steps.compute-path.outputs.is-production }}

Expand All @@ -121,10 +107,10 @@ jobs:
with:
base-path: ${{ steps.compute-path.outputs.deploy-path }}
output-dir: ${{ inputs.output-dir }}
ssh-host: ${{ secrets.server-host }}
ssh-user: ${{ secrets.server-user }}
ssh-private-key: ${{ secrets.ssh-private-key }}
ssh-path: ${{ secrets.server-path }}${{ steps.compute-path.outputs.deploy-path }}
ssh-host: ${{ secrets.SERVER_HOST }}
ssh-user: ${{ secrets.SERVER_USER }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-path: ${{ secrets.SERVER_PATH }}${{ steps.compute-path.outputs.deploy-path }}
dry-run: ${{ inputs.dry-run }}
is-production: ${{ steps.compute-path.outputs.is-production }}

Expand Down Expand Up @@ -162,17 +148,17 @@ jobs:
if: ${{ success() && github.event_name != 'pull_request' && steps.check-slack.outputs.success-enabled == 'true' }}
uses: kryota-dev/actions/.github/actions/slack-notify-success@568519d2e5e2722d8d2340f594f6af3e1564852e # v0.0.7
with:
channel-id: ${{ secrets.slack-channel-id }}
bot-oauth-token: ${{ secrets.slack-bot-oauth-token }}
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
bot-oauth-token: ${{ secrets.SLACK_BOT_OAUTH_TOKEN }}
title: 'Web Hosting deploy succeeded'
message: '${{ inputs.home-url }}${{ steps.compute-path.outputs.deploy-path }}/'

- name: Notify Slack (Deploy Failure)
if: ${{ failure() && github.event_name != 'pull_request' && steps.check-slack.outputs.failure-enabled == 'true' }}
uses: kryota-dev/actions/.github/actions/slack-notify-failure@568519d2e5e2722d8d2340f594f6af3e1564852e # v0.0.7
with:
webhook-url: ${{ secrets.slack-webhook-url }}
mention-user: ${{ secrets.slack-mention-user }}
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
mention-user: ${{ secrets.SLACK_MENTION_USER }}
title: 'Web Hosting deploy failed'

# --- Hide Previous Failed Comments ---
Expand Down
92 changes: 24 additions & 68 deletions .github/workflows/docs/deploy-web-hosting.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
pull-requests: write
uses: kryota-dev/actions/.github/workflows/deploy-web-hosting.yml@v0
with:
# environment - シークレットアクセス用の GitHub Environment 名
# Required
Comment thread
kryota-dev marked this conversation as resolved.
environment: 'production'

# deploy-type - デプロイ方法('ftp' または 'rsync')
# Required
deploy-type: 'ftp'
Expand Down Expand Up @@ -46,48 +50,13 @@ jobs:
# ref-name - ブランチ名の上書き(空の場合は github context から自動取得)
# Optional (default: '')
ref-name: ''
secrets:
# server-host - デプロイ先サーバーのホスト名
# Required
server-host: ${{ secrets.SERVER_HOST }}

# server-user - デプロイ先サーバーのユーザー名
# Required
server-user: ${{ secrets.SERVER_USER }}

# server-path - デプロイ先サーバーのパス
# Required
server-path: ${{ secrets.SERVER_PATH }}

# server-password - デプロイ先サーバーのパスワード(FTP 使用時に必要)
# Optional
server-password: ${{ secrets.SERVER_PASSWORD }}

# ssh-private-key - SSH 秘密鍵(rsync 使用時に必要)
# Optional
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

# slack-channel-id - Slack 通知先チャンネル ID
# Optional
slack-channel-id: ${{ secrets.SLACK_CHANNEL_ID }}

# slack-bot-oauth-token - Slack Bot の OAuth トークン
# Optional
slack-bot-oauth-token: ${{ secrets.SLACK_BOT_OAUTH_TOKEN }}

# slack-webhook-url - Slack Incoming Webhook URL
# Optional
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

# slack-mention-user - Slack で失敗時にメンションするユーザー
# Optional
slack-mention-user: ${{ secrets.SLACK_MENTION_USER }}
```

## Inputs

| Name | Description | Required | Default |
|------|-------------|----------|---------|
| `environment` | シークレットアクセス用の GitHub Environment 名 | Yes | - |
| `deploy-type` | デプロイ方法(`'ftp'` または `'rsync'`) | Yes | - |
| `artifact-name` | ダウンロードするビルドアーティファクトの名前 | Yes | - |
| `output-dir` | ビルド出力ディレクトリ名 | Yes | - |
Expand All @@ -97,19 +66,21 @@ jobs:
| `production-branch` | 本番ブランチ名 | No | `'main'` |
| `ref-name` | ブランチ名の上書き(空の場合は github context から自動取得) | No | `''` |

## Secrets
## Environment Secrets

`environment` input で指定した GitHub Environment に以下のシークレットを設定する必要があります:

| Name | Description | Required |
|------|-------------|----------|
| `server-host` | デプロイ先サーバーのホスト名 | Yes |
| `server-user` | デプロイ先サーバーのユーザー名 | Yes |
| `server-path` | デプロイ先サーバーのパス | Yes |
| `server-password` | デプロイ先サーバーのパスワード(FTP 使用時に必要) | No |
| `ssh-private-key` | SSH 秘密鍵(rsync 使用時に必要) | No |
| `slack-channel-id` | Slack 通知先チャンネル ID | No |
| `slack-bot-oauth-token` | Slack Bot の OAuth トークン | No |
| `slack-webhook-url` | Slack Incoming Webhook URL | No |
| `slack-mention-user` | Slack で失敗時にメンションするユーザー | No |
| `SERVER_HOST` | デプロイ先サーバーのホスト名 | Yes |
| `SERVER_USER` | デプロイ先サーバーのユーザー名 | Yes |
| `SERVER_PATH` | デプロイ先サーバーのパス | Yes |
| `SERVER_PASSWORD` | デプロイ先サーバーのパスワード(FTP 使用時に必要) | Conditional |
| `SSH_PRIVATE_KEY` | SSH 秘密鍵(rsync 使用時に必要) | Conditional |
| `SLACK_CHANNEL_ID` | Slack 通知先チャンネル ID | No |
| `SLACK_BOT_OAUTH_TOKEN` | Slack Bot の OAuth トークン | No |
| `SLACK_WEBHOOK_URL` | Slack Incoming Webhook URL | No |
| `SLACK_MENTION_USER` | Slack で失敗時にメンションするユーザー | No |

## Permissions

Expand All @@ -128,14 +99,10 @@ jobs:
pull-requests: write
uses: kryota-dev/actions/.github/workflows/deploy-web-hosting.yml@v0
with:
environment: 'production'
deploy-type: 'ftp'
artifact-name: 'build-output'
output-dir: 'dist'
secrets:
server-host: ${{ secrets.SERVER_HOST }}
server-user: ${{ secrets.SERVER_USER }}
server-path: ${{ secrets.SERVER_PATH }}
server-password: ${{ secrets.SERVER_PASSWORD }}
```

### rsync でデプロイする(Slack 通知付き)
Expand All @@ -147,20 +114,12 @@ jobs:
pull-requests: write
uses: kryota-dev/actions/.github/workflows/deploy-web-hosting.yml@v0
with:
environment: 'production'
deploy-type: 'rsync'
artifact-name: 'build-output'
output-dir: 'dist'
base-path-prefix: '/my-project'
home-url: 'https://example.com'
secrets:
server-host: ${{ secrets.SERVER_HOST }}
server-user: ${{ secrets.SERVER_USER }}
server-path: ${{ secrets.SERVER_PATH }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
slack-channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-bot-oauth-token: ${{ secrets.SLACK_BOT_OAUTH_TOKEN }}
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-mention-user: ${{ secrets.SLACK_MENTION_USER }}
```

### ドライランで確認する
Expand All @@ -172,23 +131,19 @@ jobs:
pull-requests: write
uses: kryota-dev/actions/.github/workflows/deploy-web-hosting.yml@v0
with:
environment: 'staging'
deploy-type: 'rsync'
artifact-name: 'build-output'
output-dir: 'dist'
dry-run: 'true'
secrets:
server-host: ${{ secrets.SERVER_HOST }}
server-user: ${{ secrets.SERVER_USER }}
server-path: ${{ secrets.SERVER_PATH }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
```

## Behavior

このワークフローは `deploy` ジョブで構成され、以下の順序で実行されます。

1. `compute-web-hosting-deploy-path` Composite Action でデプロイ先パスを計算
2. Slack 設定チェック(`slack-channel-id` + `slack-bot-oauth-token` があれば成功通知可能、`slack-webhook-url` があれば失敗通知可能)
2. Slack 設定チェック(`SLACK_CHANNEL_ID` + `SLACK_BOT_OAUTH_TOKEN` があれば成功通知可能、`SLACK_WEBHOOK_URL` があれば失敗通知可能)
3. `actions/download-artifact@v4.3.0` でビルドアーティファクトをダウンロード
4. `deploy-type` の値に応じてデプロイを実行
- `'ftp'`: `deploy-web-hosting-ftp` Composite Action を使用
Expand All @@ -199,6 +154,7 @@ jobs:

## Prerequisites

- 呼び出し元リポジトリに `environment` input に対応する GitHub Environment が存在し、必要なシークレットが Environment レベルで設定されていること
- 呼び出し元ワークフローで `actions/upload-artifact` によるビルド成果物のアップロードが完了していること
- `deploy-type` が `'ftp'` の場合: `server-password` が必要
- `deploy-type` が `'rsync'` の場合: `ssh-private-key` が必要
- `deploy-type` が `'ftp'` の場合: `SERVER_PASSWORD` が必要
- `deploy-type` が `'rsync'` の場合: `SSH_PRIVATE_KEY` が必要
Loading
Loading