fix: Normalize repository and owner names in Docker workflow #4
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: Build and Push Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main # メインブランチへのプッシュ時に実行 | |
| workflow_dispatch: # 手動でトリガー可能 | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. リポジトリコードをチェックアウト | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| # 2. Node.js 環境をセットアップ | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: "yarn" | |
| # 3. リポジトリ名と所有者名を変換 | |
| - name: Normalize Names | |
| id: normalize-names | |
| run: | | |
| # ユーザー名を小文字に変換 | |
| NORMALIZED_OWNER_NAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
| # リポジトリ名をケバブケースに変換 | |
| NORMALIZED_REPOSITORY_NAME=$(echo "${{ github.repository }}" | sed -E 's/([a-z])([A-Z])/\1-\L\2/g' | tr '[:upper:]' '[:lower:]') | |
| # 正規化した結果を出力(後続ステップで利用可能) | |
| echo "NORMALIZED_OWNER_NAME=${NORMALIZED_OWNER_NAME}" >> $GITHUB_ENV | |
| echo "NORMALIZED_REPOSITORY_NAME=${NORMALIZED_REPOSITORY_NAME}" >> $GITHUB_ENV | |
| # 4. Docker にログイン(GitHub Container Registry) | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/[email protected] | |
| with: | |
| registry: ghcr.io | |
| username: ${{ env.NORMALIZED_OWNER_NAME }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # 5. Docker イメージをビルド | |
| - name: Build Docker Image | |
| run: | | |
| docker build -f infra/docker/Dockerfile . \ | |
| -t ghcr.io/${{ env.NORMALIZED_OWNER_NAME }}/${{ env.NORMALIZED_REPOSITORY_NAME }}:latest | |
| # 6. Docker イメージをプッシュ | |
| - name: Push Docker Image | |
| run: | | |
| docker push ghcr.io/${{ env.NORMALIZED_OWNER_NAME }}/${{ env.NORMALIZED_REPOSITORY_NAME }}:latest |