Files
my-pal-mcp-server/.github/workflows/build_and_publish_docker.yml
Patryk Ciechanski 6c433e58e1 fix: Add PAT authentication to Docker workflow for README updates
- Enables Docker workflow to push README updates after image publish
- Uses PAT token instead of GITHUB_TOKEN for repository write permissions
- Completes automation flow: PR merge → version bump → Docker build → README update

🤖 Generated with Claude Code
2025-06-12 12:58:49 +02:00

191 lines
8.4 KiB
YAML

name: Build and Publish Docker Image to GHCR
on:
push:
tags: [ 'v*' ]
repository_dispatch:
types: [docker-build]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=main-,enable=${{ github.event_name == 'repository_dispatch' }}
type=raw,value=pr-${{ github.event.client_payload.pr_number }},enable=${{ github.event_name == 'repository_dispatch' && github.event.client_payload.pr_number != '' }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
- name: Generate usage instructions
run: |
echo "## 🐳 Docker Image Published Successfully!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image Registry:** GitHub Container Registry (GHCR)" >> $GITHUB_STEP_SUMMARY
echo "**Built Tags:** ${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract the first tag for the main pull command
MAIN_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
echo "### 📥 Pull the Image" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull $MAIN_TAG" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### ⚙️ Claude Desktop Configuration" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`json" >> $GITHUB_STEP_SUMMARY
echo "{" >> $GITHUB_STEP_SUMMARY
echo " \"mcpServers\": {" >> $GITHUB_STEP_SUMMARY
echo " \"gemini\": {" >> $GITHUB_STEP_SUMMARY
echo " \"command\": \"docker\"," >> $GITHUB_STEP_SUMMARY
echo " \"args\": [" >> $GITHUB_STEP_SUMMARY
echo " \"run\", \"--rm\", \"-i\"," >> $GITHUB_STEP_SUMMARY
echo " \"-e\", \"GEMINI_API_KEY\"," >> $GITHUB_STEP_SUMMARY
echo " \"$MAIN_TAG\"" >> $GITHUB_STEP_SUMMARY
echo " ]," >> $GITHUB_STEP_SUMMARY
echo " \"env\": {" >> $GITHUB_STEP_SUMMARY
echo " \"GEMINI_API_KEY\": \"your-gemini-api-key-here\"" >> $GITHUB_STEP_SUMMARY
echo " }" >> $GITHUB_STEP_SUMMARY
echo " }" >> $GITHUB_STEP_SUMMARY
echo " }" >> $GITHUB_STEP_SUMMARY
echo "}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🏷️ All Available Tags" >> $GITHUB_STEP_SUMMARY
echo "Built and pushed the following tags:" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/- `/' | sed 's/$/`/' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then
echo "**Note:** This is a development build triggered by PR #${{ github.event.client_payload.pr_number }}" >> $GITHUB_STEP_SUMMARY
echo "Use this image for testing the changes from that PR." >> $GITHUB_STEP_SUMMARY
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "**Note:** This is a release build from tag ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "This image represents a stable release version." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📦 View in GitHub Container Registry" >> $GITHUB_STEP_SUMMARY
echo "[View all versions and tags →](https://github.com/${{ github.repository }}/pkgs/container/gemini-mcp-server)" >> $GITHUB_STEP_SUMMARY
- name: Update README with latest image info
if: github.ref_type == 'tag' || (github.event_name == 'repository_dispatch' && github.event.client_payload.pr_number != '')
run: |
# Extract the primary image tag for updating README
if [[ "${{ github.ref_type }}" == "tag" ]]; then
# For tag releases, use the version tag
LATEST_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}"
UPDATE_TYPE="release"
elif [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.client_payload.pr_number }}" != "" ]]; then
# For repository_dispatch (PR builds), use the PR tag
LATEST_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.client_payload.pr_number }}"
UPDATE_TYPE="development"
else
# For manual repository_dispatch without PR number, use latest tag
LATEST_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
UPDATE_TYPE="manual"
fi
echo "Updating README.md with latest Docker image: $LATEST_TAG"
# Update README.md with the latest image tag
sed -i.bak "s|ghcr\.io/${{ github.repository_owner }}/gemini-mcp-server:[a-zA-Z0-9\._-]*|$LATEST_TAG|g" README.md
# Also update docs/user-guides/installation.md
sed -i.bak "s|ghcr\.io/${{ github.repository_owner }}/gemini-mcp-server:[a-zA-Z0-9\._-]*|$LATEST_TAG|g" docs/user-guides/installation.md
# Also update docs/user-guides/configuration.md
sed -i.bak "s|ghcr\.io/${{ github.repository_owner }}/gemini-mcp-server:[a-zA-Z0-9\._-]*|$LATEST_TAG|g" docs/user-guides/configuration.md
# Check if there are any changes
if git diff --quiet README.md docs/user-guides/installation.md docs/user-guides/configuration.md; then
echo "No changes needed in documentation"
else
echo "Documentation updated with new image tag"
# Configure git for automated commit
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add and commit changes
git add README.md docs/user-guides/installation.md docs/user-guides/configuration.md
if [[ "$UPDATE_TYPE" == "release" ]]; then
git commit -m "docs: Update Docker image references to ${{ github.ref_name }}
Automated update after Docker image publish for release ${{ github.ref_name }}.
All documentation now references the latest stable image.
🤖 Automated by GitHub Actions"
elif [[ "$UPDATE_TYPE" == "development" ]]; then
git commit -m "docs: Update Docker image references for PR #${{ github.event.client_payload.pr_number }}
Automated update after Docker image publish for development build.
Documentation updated to reference the latest development image.
🤖 Automated by GitHub Actions"
else
git commit -m "docs: Update Docker image references to latest
Automated update after manual Docker image build.
Documentation updated to reference the latest image.
🤖 Automated by GitHub Actions"
fi
# Push changes back to the repository
git push
echo "### 📝 Documentation Updated" >> $GITHUB_STEP_SUMMARY
echo "README.md and user guides have been automatically updated with the new Docker image tag: \`$LATEST_TAG\`" >> $GITHUB_STEP_SUMMARY
fi