name: Build and Publish Docker Images on: push: branches: [main, develop] tags: ["v*"] pull_request: branches: [main] workflow_dispatch: inputs: platforms: description: "Platforms to build (comma-separated)" required: false default: "linux/amd64,linux/arm64" type: string push_to_registry: description: "Push to registry" required: false default: true type: boolean permissions: contents: read # ソースコードのクローンに必要 packages: write # GHCR へイメージをプッシュするのに必要 env: REGISTRY: ghcr.io IMAGE_NAME_1: ${{ github.repository_owner }}/voice-rss-summary jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_1 }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=raw,value=latest,enable={{is_default_branch}} - name: Determine platforms id: platforms run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then echo "platforms=${{ github.event.inputs.platforms }}" >> $GITHUB_OUTPUT elif [ "${{ github.event_name }}" = "pull_request" ]; then echo "platforms=linux/amd64" >> $GITHUB_OUTPUT else echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT fi - name: Determine push setting id: push run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then echo "push=${{ github.event.inputs.push_to_registry }}" >> $GITHUB_OUTPUT elif [ "${{ github.event_name }}" = "pull_request" ]; then echo "push=false" >> $GITHUB_OUTPUT else echo "push=true" >> $GITHUB_OUTPUT fi - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . platforms: ${{ steps.platforms.outputs.platforms }} push: ${{ steps.push.outputs.push }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | BUILDKIT_INLINE_CACHE=1 - name: Generate summary if: always() run: | echo "## Build Summary" >> $GITHUB_STEP_SUMMARY echo "- **Event**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY echo "- **Ref**: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY echo "- **Platforms**: ${{ steps.platforms.outputs.platforms }}" >> $GITHUB_STEP_SUMMARY echo "- **Push to registry**: ${{ steps.push.outputs.push }}" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "### Images built:" >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY