Merge pull request #379 from commjoen/dependabot/npm_and_yarn/npm-11.… #550
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: Docker Hub Release | |
| permissions: | |
| contents: read | |
| on: | |
| release: | |
| types: [published] | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag to build and push' | |
| required: true | |
| default: 'latest' | |
| env: | |
| IMAGE_NAME_1: platformer-game | |
| IMAGE_NAME_2: platformer-game-1 | |
| jobs: | |
| build-and-push-dockerhub: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Fetch full git history for version injection | |
| run: git fetch --unshallow || true | |
| - name: Check Docker Hub credentials | |
| run: | | |
| if [[ -n "${{ secrets.DOCKERHUB_USERNAME }}" && -n "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then | |
| echo "✅ Docker Hub credentials available - will build and push" | |
| echo "DOCKER_HUB_AVAILABLE=true" >> $GITHUB_ENV | |
| else | |
| echo "⚠️ Docker Hub credentials not available - will build only (no push)" | |
| echo "DOCKER_HUB_AVAILABLE=false" >> $GITHUB_ENV | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| if: ${{ env.DOCKER_HUB_AVAILABLE == 'true' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set image names based on credential availability | |
| id: image-names | |
| run: | | |
| if [[ -n "${{ secrets.DOCKERHUB_USERNAME }}" && -n "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then | |
| echo "IMAGE_NAME_1_FULL=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }}" >> $GITHUB_OUTPUT | |
| echo "IMAGE_NAME_2_FULL=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_2 }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "IMAGE_NAME_1_FULL=temp/build-test-1" >> $GITHUB_OUTPUT | |
| echo "IMAGE_NAME_2_FULL=temp/build-test-2" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ steps.image-names.outputs.IMAGE_NAME_1_FULL }} | |
| ${{ steps.image-names.outputs.IMAGE_NAME_2_FULL }} | |
| tags: | | |
| type=ref,event=tag | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag != '' }} | |
| labels: | | |
| org.opencontainers.image.title=Multiplayer Platformer Game | |
| org.opencontainers.image.description=A 2D platformer game with optional multiplayer support | |
| org.opencontainers.image.url=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ github.ref_name }} | |
| org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| - name: Build and push to Docker Hub | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ env.DOCKER_HUB_AVAILABLE == 'true' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Update Docker Hub description for platformer-game | |
| uses: peter-evans/dockerhub-description@v5 | |
| if: github.event_name == 'release' && env.DOCKER_HUB_AVAILABLE == 'true' | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }} | |
| short-description: '🎮 Multiplayer 2D platformer game with optional WebSocket multiplayer support' | |
| readme-filepath: ./README.md | |
| - name: Update Docker Hub description for platformer-game-1 | |
| uses: peter-evans/dockerhub-description@v5 | |
| if: github.event_name == 'release' && env.DOCKER_HUB_AVAILABLE == 'true' | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_2 }} | |
| short-description: '🎮 Multiplayer 2D platformer game with optional WebSocket multiplayer support' | |
| readme-filepath: ./README.md | |
| - name: Generate summary | |
| run: | | |
| echo "## 🐳 Docker Hub Release Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Show trigger information | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "**Trigger:** Manual dispatch with custom tag \`${{ github.event.inputs.tag }}\`" >> $GITHUB_STEP_SUMMARY | |
| elif [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo "**Trigger:** Release \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| elif [[ "${{ github.event_name }}" == "push" ]]; then | |
| echo "**Trigger:** Push to main branch" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ env.DOCKER_HUB_AVAILABLE }}" == "true" ]]; then | |
| echo "**Status:** ✅ Built and pushed to Docker Hub" >> $GITHUB_STEP_SUMMARY | |
| echo "**Repositories:** " >> $GITHUB_STEP_SUMMARY | |
| echo "- \`${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_2 }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 📦 Published Tags" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 🚀 Usage" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "# Pull from either repository (same image)" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then | |
| echo "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }}:${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }}:latest" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "# OR" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then | |
| echo "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_2 }}:${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_2 }}:latest" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "# Run the container" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then | |
| echo "docker run -p 8080:80 -p 3001:3001 ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }}:${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "docker run -p 8080:80 -p 3001:3001 ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME_1 }}:latest" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "**Status:** ⚠️ Build completed, but not pushed to Docker Hub" >> $GITHUB_STEP_SUMMARY | |
| echo "**Reason:** Docker Hub credentials (DOCKERHUB_USERNAME and DOCKERHUB_TOKEN) not available" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 🔧 To Enable Docker Hub Push" >> $GITHUB_STEP_SUMMARY | |
| echo "1. Set \`DOCKERHUB_USERNAME\` secret to your Docker Hub username" >> $GITHUB_STEP_SUMMARY | |
| echo "2. Set \`DOCKERHUB_TOKEN\` secret to your Docker Hub access token" >> $GITHUB_STEP_SUMMARY | |
| echo "3. Re-run this workflow or create a new release" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 🏗️ Build Verification" >> $GITHUB_STEP_SUMMARY | |
| echo "Docker image was successfully built and validated with the following configuration:" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Build Context:** \`.\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Dockerfile:** \`./Dockerfile\`" >> $GITHUB_STEP_SUMMARY | |
| fi |