Skip to content

Improve GHCR publishing and repo discoverability #6

Improve GHCR publishing and repo discoverability

Improve GHCR publishing and repo discoverability #6

Workflow file for this run

name: Build and Push Docker Image

Check failure on line 1 in .github/workflows/docker-image.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/docker-image.yml

Invalid workflow file

(Line: 32, Col: 13): Unrecognized named-value: 'secrets'. Located at position 40 within expression: github.event_name != 'pull_request' && secrets.GHCR_PAT != '', (Line: 40, Col: 13): Unrecognized named-value: 'secrets'. Located at position 40 within expression: github.event_name != 'pull_request' && secrets.GHCR_PAT == ''
permissions:
contents: read
packages: write
on:
push:
branches: [main]
tags: ["v*.*.*"]
pull_request:
branches: [main]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_OWNER: ${{ github.repository_owner }}
IMAGE_NAME: latrace-ai
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR with PAT
if: github.event_name != 'pull_request' && secrets.GHCR_PAT != ''
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Login to GHCR with GITHUB_TOKEN
if: github.event_name != 'pull_request' && secrets.GHCR_PAT == ''
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image summary
run: |
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY